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 2 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 |
---|---|---|
|
@@ -500,6 +500,7 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger, | |
|
||
route.WeightedClusters = make(map[string]WeightedCluster) | ||
action := r.GetRoute() | ||
route.HashPolicies = hashPoliciesProtoToSlice(action.HashPolicy) | ||
switch a := action.GetClusterSpecifier().(type) { | ||
case *v3routepb.RouteAction_Cluster: | ||
route.WeightedClusters[a.Cluster] = WeightedCluster{Weight: 1} | ||
|
@@ -561,6 +562,33 @@ func routesProtoToSlice(routes []*v3routepb.Route, logger *grpclog.PrefixLogger, | |
return routesRet, nil | ||
} | ||
|
||
func hashPoliciesProtoToSlice(policies []*v3routepb.RouteAction_HashPolicy) []*HashPolicy { | ||
var hashPoliciesRet []*HashPolicy | ||
for _, p := range policies { | ||
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. |
||
policy.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. Make these two type Like https://github.com/grpc/grpc-go/blob/master/xds/internal/xdsclient/xds.go#L461 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. Ah, I treated these errors as no-ops in config selector. Your idea is much better, fail at parsing. 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 only changed .Regex though, because the others aren't Regexes but strings. 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. I also changed all the no op logic due to our discussion yesterday. Rather than make the no-op decision for the user, just fail at parsing step. |
||
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. |
||
// ConnectionProperties in Envoy specifies to hash the source ip | ||
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. Move this under Or, move this to the next config selector PR. This comment doesn't make much sense here. 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. How does this not make sense? How would you describe the scope of comments in this file? 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 comment would make more sense in config selector, where you hash the pointer. You don't need to explain here how it will be handled. 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. Hmmmm ok deleted. |
||
// address. In grpc, this is logically equivalent to hashing the | ||
// channel pointer. | ||
case *v3routepb.RouteAction_HashPolicy_ConnectionProperties_: | ||
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. We don't support connection properties I think. The way to specify channel_id is the filter_state field set to contain the key "io.grpc.channel_id". 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. |
||
policy.HashPolicyType = HashPolicyTypeChannelID | ||
default: | ||
// In the case where the hash policy action isn't to hash the header | ||
// or the unique identifier of the channel, ignore the field in the | ||
// update and treat as a no-op. | ||
} | ||
|
||
hashPoliciesRet = append(hashPoliciesRet, &policy) | ||
} | ||
return hashPoliciesRet | ||
} | ||
|
||
// 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.
Add an env var
GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH
See also #4440
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.