-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: add HashPolicy fields to RDS update #4521
Changes from 5 commits
284dfde
026e9d2
d30e2c9
7301a31
e7ad0ef
0d33dde
46ef33f
b1418a6
b065a7d
aa1169a
95e48a8
a719ca7
6351a55
2d3b1f9
4554924
d03c30b
e35d50e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,7 +499,14 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger, | |
} | ||
|
||
route.WeightedClusters = make(map[string]WeightedCluster) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this blank line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
action := r.GetRoute() | ||
hp, err := hashPoliciesProtoToSlice(action.HashPolicy) | ||
if err != nil { | ||
return nil, err | ||
} | ||
route.HashPolicies = hp | ||
|
||
switch a := action.GetClusterSpecifier().(type) { | ||
case *v3routepb.RouteAction_Cluster: | ||
route.WeightedClusters[a.Cluster] = WeightedCluster{Weight: 1} | ||
|
@@ -561,6 +568,40 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger, | |
return routesRet, nil | ||
} | ||
|
||
func hashPoliciesProtoToSlice(policies []*v3routepb.RouteAction_HashPolicy) ([]*HashPolicy, error) { | ||
var hashPoliciesRet []*HashPolicy | ||
for _, p := range policies { | ||
// Hash Policies are only applicable for a Ring Hash LB. | ||
if !env.RingHashSupport { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do this check before calling And also, no need to return an error (error results in NACKs). It's safe to just ignore it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrapped the hashPoliciesProtoToSlice call inside a RingHashSupport conditional. |
||
return nil, errors.New("hash policies are only applicable for ring hash lb policy") | ||
} | ||
var policy HashPolicy | ||
policy.Terminal = p.Terminal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this can be oneline There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
switch p.GetPolicySpecifier().(type) { | ||
case *v3routepb.RouteAction_HashPolicy_Header_: | ||
policy.HashPolicyType = HashPolicyTypeHeader | ||
policy.HeaderName = p.GetHeader().HeaderName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I've actually been wondering about this for a while. |
||
regex := p.GetHeader().GetRegexRewrite().GetPattern().Regex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
re, err := regexp.Compile(regex) | ||
if err != nil { | ||
return nil, fmt.Errorf("hash policy %+v contains an invalid regex %q", p, regex) | ||
} | ||
policy.Regex = re | ||
policy.RegexSubstitution = p.GetHeader().GetRegexRewrite().Substitution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
case *v3routepb.RouteAction_HashPolicy_FilterState_: | ||
if p.GetFilterState().GetKey() != "io.grpc.channel_id" { | ||
return nil, fmt.Errorf("hash policy %+v contains an invalid key for filter state policy %q", p, p.GetFilterState().GetKey()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also not NACK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to logger. |
||
} | ||
policy.HashPolicyType = HashPolicyTypeChannelID | ||
default: | ||
return nil, fmt.Errorf("hash policy %v is an unsupported hash policy", p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Print the type (with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to p.GetPolicySpecifier(). Crossing my fingers that that's the right thing. |
||
} | ||
|
||
hashPoliciesRet = append(hashPoliciesRet, &policy) | ||
} | ||
return hashPoliciesRet, nil | ||
} | ||
|
||
// UnmarshalCluster processes resources received in an CDS response, validates | ||
// them, and transforms them into a native struct which contains only fields we | ||
// are interested in. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want the default of this to be "false". See how AggregateAndDNSSupportEnv is handled
(Note that the comment says it can be enabled by setting env var to true, and also
EqualFold(..., "true")
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, this isn't something the user should have to disable, but rather something the user should have to enable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.