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 6 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,18 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger, | |
} | ||
|
||
route.WeightedClusters = make(map[string]WeightedCluster) | ||
|
||
action := r.GetRoute() | ||
|
||
// Hash Policies are only applicable for a Ring Hash LB. | ||
if env.RingHashSupport { | ||
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 +572,35 @@ 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 { | ||
policy := HashPolicy{Terminal: p.Terminal} | ||
switch p.GetPolicySpecifier().(type) { | ||
case *v3routepb.RouteAction_HashPolicy_Header_: | ||
policy.HashPolicyType = HashPolicyTypeHeader | ||
policy.HeaderName = p.GetHeader().GetHeaderName() | ||
regex := p.GetHeader().GetRegexRewrite().GetPattern().GetRegex() | ||
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().GetSubstitution() | ||
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 %T is an unsupported hash policy", p.GetPolicySpecifier()) | ||
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. As you mentioned in chat, this shouldn't 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. |
||
} | ||
|
||
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.
Delete this blank line
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.
Done.