Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: NACK route configuration if sum of weights of weighted clusters exceeds uint32_max #6085

Merged
merged 3 commits into from Mar 9, 2023

Conversation

arvindbr8
Copy link
Member

@arvindbr8 arvindbr8 commented Mar 3, 2023

fixes #6053

RELEASE NOTES:

  • xds: NACK route configuration if sum of weights of weighted clusters exceeds uint32_max

@arvindbr8 arvindbr8 added Type: Bug Type: Behavior Change Behavior changes not categorized as bugs and removed Type: Bug labels Mar 3, 2023
@arvindbr8 arvindbr8 added this to the 1.54 Release milestone Mar 3, 2023
@arvindbr8 arvindbr8 requested a review from easwars March 3, 2023 22:40
@@ -326,17 +326,13 @@ func routesProtoToSlice(routes []*v3routepb.Route, csps map[string]clusterspecif
}
wc.HTTPFilterConfigOverride = cfgs
route.WeightedClusters[c.GetName()] = wc

// Sum of all weights cannot exceed MaxUint32. Checking for overflow.
if totalWeight > (totalWeight + w) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we declared totalWeight as a uint64 instead? Then we can unconditionally add w to totalWeight and simply check if totalWeight > math.MaxUint32. I feel that will be more readable. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Updating.


// Sum of all weights cannot exceed MaxUint32. Checking for overflow.
if totalWeight > (totalWeight + w) {
return nil, nil, fmt.Errorf("route %+v, action %+v, has no valid cluster in WeightedCluster action", r, a)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message needs updating.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops.. done

@easwars easwars assigned arvindbr8 and unassigned easwars Mar 8, 2023
@arvindbr8 arvindbr8 assigned easwars and unassigned arvindbr8 Mar 9, 2023
@arvindbr8 arvindbr8 requested a review from easwars March 9, 2023 19:51
}
if totalWeight != wantTotalWeight {
return nil, nil, fmt.Errorf("route %+v, action %+v, weights of clusters do not add up to total total weight, got: %v, expected total weight from response: %v", r, a, totalWeight, wantTotalWeight)
totalWeight += uint64(w)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit. If you move this line to 322, then it will look simpler I feel:

totalWeight += uint64(w)
if totalWeight > math.MaxUint32 {
	return nil, nil, fmt.Errorf("xds: total weight of clusters exceeds MaxUint32")
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. updating..

for _, c := range wcs.Clusters {
w := c.GetWeight().GetValue()
if w == 0 {
continue
}
if (totalWeight + uint64(w)) > math.MaxUint32 {
return nil, nil, fmt.Errorf("total weight of clusters exceed MaxUint32")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/exceed/exceeds/
Also, add an xds: prefix to the error string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@easwars easwars assigned arvindbr8 and unassigned easwars Mar 9, 2023
@arvindbr8 arvindbr8 merged commit 92d9e77 into grpc:master Mar 9, 2023
1 check passed
@arvindbr8 arvindbr8 deleted the NACK-routeConfiguration branch March 9, 2023 22:48
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Behavior Change Behavior changes not categorized as bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xds: NACK route configuration if sum of weights of weighted clusters exceeds uint32_max
2 participants