mirror of https://github.com/grpc/grpc-node.git
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:
commit
2f6d49d334
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue