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/xdsclient: add sum of EDS locality weights check #5703

Merged
merged 2 commits into from Oct 10, 2022
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
16 changes: 11 additions & 5 deletions xds/internal/xdsclient/xdsresource/unmarshal_eds.go
Expand Up @@ -19,6 +19,7 @@ package xdsresource

import (
"fmt"
"math"
"net"
"strconv"

Expand Down Expand Up @@ -118,6 +119,7 @@ func parseEDSRespProto(m *v3endpointpb.ClusterLoadAssignment, logger *grpclog.Pr
ret.Drops = append(ret.Drops, parseDropPolicy(dropPolicy))
}
priorities := make(map[uint32]map[string]bool)
sumOfWeights := make(map[uint32]uint64)
for _, locality := range m.Endpoints {
l := locality.GetLocality()
if l == nil {
Expand All @@ -128,17 +130,21 @@ func parseEDSRespProto(m *v3endpointpb.ClusterLoadAssignment, logger *grpclog.Pr
logger.Warningf("Ignoring locality %s with weight 0", pretty.ToJSON(l))
continue
}
lid := internal.LocalityID{
Region: l.Region,
Zone: l.Zone,
SubZone: l.SubZone,
}
priority := locality.GetPriority()
sumOfWeights[priority] += uint64(weight)
if sumOfWeights[priority] > math.MaxUint32 {
return EndpointsUpdate{}, fmt.Errorf("sum of weights of localities at the same priority %d exceeded maximal value", priority)
}
localitiesWithPriority := priorities[priority]
if localitiesWithPriority == nil {
localitiesWithPriority = make(map[string]bool)
priorities[priority] = localitiesWithPriority
}
lid := internal.LocalityID{
Region: l.Region,
Zone: l.Zone,
SubZone: l.SubZone,
}
lidStr, _ := lid.ToString()
if localitiesWithPriority[lidStr] {
return EndpointsUpdate{}, fmt.Errorf("duplicate locality %s with the same priority %v", lidStr, priority)
Expand Down
25 changes: 25 additions & 0 deletions xds/internal/xdsclient/xdsresource/unmarshal_eds_test.go
Expand Up @@ -99,6 +99,31 @@ func (s) TestEDSParseRespProto(t *testing.T) {
}(),
want: EndpointsUpdate{},
},
{
name: "max sum of weights at the same priority exceeded",
m: func() *v3endpointpb.ClusterLoadAssignment {
clab0 := newClaBuilder("test", nil)
clab0.addLocality("locality-1", 1, 0, []string{"addr1:314"}, &addLocalityOptions{
Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_UNHEALTHY},
erni27 marked this conversation as resolved.
Show resolved Hide resolved
Weight: []uint32{271},
})
clab0.addLocality("locality-2", 1431655765, 1, []string{"addr2:159"}, &addLocalityOptions{
Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_DRAINING},
Weight: []uint32{828},
})
clab0.addLocality("locality-3", 1431655765, 1, []string{"addr2:73"}, &addLocalityOptions{
Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_HEALTHY},
Weight: []uint32{997},
})
clab0.addLocality("locality-4", 1431655766, 1, []string{"addr2:44"}, &addLocalityOptions{
Health: []v3corepb.HealthStatus{v3corepb.HealthStatus_UNHEALTHY},
Weight: []uint32{1143},
})
return clab0.Build()
}(),
want: EndpointsUpdate{},
wantErr: true,
},
{
name: "good",
m: func() *v3endpointpb.ClusterLoadAssignment {
Expand Down