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_client/rds: weighted_cluster totalWeight default to 100 #4439

Merged
merged 3 commits into from May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions xds/internal/client/rds_test.go
Expand Up @@ -1089,8 +1089,8 @@ func (s) TestRoutesProtoToSlice(t *testing.T) {
ClusterSpecifier: &v3routepb.RouteAction_WeightedClusters{
WeightedClusters: &v3routepb.WeightedCluster{
Clusters: []*v3routepb.WeightedCluster_ClusterWeight{
{Name: "B", Weight: &wrapperspb.UInt32Value{Value: 0}},
{Name: "A", Weight: &wrapperspb.UInt32Value{Value: 0}},
{Name: "B", Weight: &wrapperspb.UInt32Value{Value: 20}},
{Name: "A", Weight: &wrapperspb.UInt32Value{Value: 30}},
},
}}}},
},
Expand Down Expand Up @@ -1142,6 +1142,31 @@ func (s) TestRoutesProtoToSlice(t *testing.T) {
}},
wantErr: false,
},
{
name: "default totalWeight is 100 in weighted clusters action",
routes: []*v3routepb.Route{
{
Match: &v3routepb.RouteMatch{
PathSpecifier: &v3routepb.RouteMatch_Prefix{Prefix: "/a/"},
},
Action: &v3routepb.Route_Route{
Route: &v3routepb.RouteAction{
ClusterSpecifier: &v3routepb.RouteAction_WeightedClusters{
WeightedClusters: &v3routepb.WeightedCluster{
Clusters: []*v3routepb.WeightedCluster_ClusterWeight{
{Name: "B", Weight: &wrapperspb.UInt32Value{Value: 30}},
{Name: "A", Weight: &wrapperspb.UInt32Value{Value: 20}},
},
TotalWeight: &wrapperspb.UInt32Value{Value: 50},
}}}},
},
},
wantRoutes: []*Route{{
Prefix: newStringP("/a/"),
WeightedClusters: map[string]WeightedCluster{"A": {Weight: 20}, "B": {Weight: 30}},
}},
wantErr: false,
},
{
name: "with custom HTTP filter config",
routes: goodRouteWithFilterConfigs(map[string]*anypb.Any{"foo": customFilterConfig}),
Expand Down
9 changes: 7 additions & 2 deletions xds/internal/client/xds.go
Expand Up @@ -522,8 +522,13 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger,
route.WeightedClusters[c.GetName()] = wc
totalWeight += w
}
if totalWeight != 100 && (wcs.GetTotalWeight() == nil || totalWeight != wcs.GetTotalWeight().GetValue()) {
return nil, fmt.Errorf("route %+v, action %+v, weights of clusters do not add up to total total weight, got: %v, want %v", r, a, wcs.GetTotalWeight().GetValue(), totalWeight)
// default TotalWeight https://github.com/grpc/grpc-go/issues/4432
alpha-baby marked this conversation as resolved.
Show resolved Hide resolved
wantTotalWeight := uint32(100)
if tw := wcs.GetTotalWeight(); tw != nil {
wantTotalWeight = tw.GetValue()
}
if totalWeight != wantTotalWeight {
return 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)
}
if totalWeight == 0 {
return nil, fmt.Errorf("route %+v, action %+v, has no valid cluster in WeightedCluster action", r, a)
Expand Down