Merge pull request #2240 from murgatroid99/eds_locality_weight_limit_validation

grpc-js-xds: Validate that endpoint weights sum to no more than the 32 bit uint max value per priority
This commit is contained in:
Michael Lumish 2022-10-10 15:38:32 -07:00 committed by GitHub
commit 2f6d49d334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -50,6 +50,7 @@ export class EdsState extends BaseXdsStreamState<ClusterLoadAssignment__Output>
*/
public validateResponse(message: ClusterLoadAssignment__Output) {
const seenLocalities: {locality: Locality__Output, priority: number}[] = [];
const priorityTotalWeights: Map<number, number> = new Map();
for (const endpoint of message.endpoints) {
if (!endpoint.locality) {
return false;
@ -72,6 +73,12 @@ export class EdsState extends BaseXdsStreamState<ClusterLoadAssignment__Output>
return false;
}
}
priorityTotalWeights.set(endpoint.priority, (priorityTotalWeights.get(endpoint.priority) ?? 0) + (endpoint.load_balancing_weight?.value ?? 0));
}
for (const totalWeight of priorityTotalWeights.values()) {
if (totalWeight >= 1<<32) {
return false;
}
}
return true;
}