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

ringhash: implement gRFC A76 #8159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

ringhash: implement gRFC A76 #8159

wants to merge 1 commit into from

Conversation

atollena
Copy link
Collaborator

@atollena atollena commented Mar 11, 2025

Fixes #8147.

  • Add the ability to set the request hash key, to extract the hash from a header. This allows using ring hash without xDS.

  • Add the ability to specify the location of endpoints on the ring, and a default implementation based on EDS metadata that matches Envoy behavior.

See https://github.com/grpc/proposal/blob/master/A76-ring-hash-improvements.md for details.

RELEASE NOTES:

  • ringhash: implement gRFC A76.

@atollena atollena requested a review from arjan-bal March 11, 2025 09:27
@atollena atollena added P1 Type: Feature New features or improvements in behavior Area: xDS Includes everything xDS related, including LB policies used with xDS. Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. labels Mar 11, 2025
@atollena atollena added this to the 1.72 Release milestone Mar 11, 2025
Copy link

codecov bot commented Mar 11, 2025

Codecov Report

Attention: Patch coverage is 97.35099% with 4 lines in your changes missing coverage. Please review.

Project coverage is 82.44%. Comparing base (a0a739f) to head (5f56c4c).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
internal/testutils/xds/e2e/clientresources.go 75.00% 1 Missing and 1 partial ⚠️
xds/internal/balancer/ringhash/picker.go 96.29% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8159      +/-   ##
==========================================
+ Coverage   82.42%   82.44%   +0.01%     
==========================================
  Files         392      393       +1     
  Lines       39106    39212     +106     
==========================================
+ Hits        32232    32327      +95     
- Misses       5564     5571       +7     
- Partials     1310     1314       +4     
Files with missing lines Coverage Δ
internal/envconfig/envconfig.go 100.00% <ø> (ø)
internal/metadata/metadata.go 82.08% <100.00%> (+1.44%) ⬆️
resolver/ringhash/attr.go 100.00% <100.00%> (ø)
...internal/balancer/clusterresolver/configbuilder.go 91.12% <100.00%> (+0.05%) ⬆️
xds/internal/balancer/ringhash/config.go 92.10% <100.00%> (+3.21%) ⬆️
xds/internal/balancer/ringhash/ring.go 100.00% <100.00%> (+7.04%) ⬆️
xds/internal/balancer/ringhash/ringhash.go 94.37% <100.00%> (+0.44%) ⬆️
xds/internal/balancer/ringhash/util.go 100.00% <100.00%> (ø)
xds/internal/resolver/serviceconfig.go 85.71% <100.00%> (ø)
...ds/internal/xdsclient/xdsresource/unmarshal_eds.go 95.13% <100.00%> (+0.56%) ⬆️
... and 2 more

... and 20 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Add the ability to set the request hash header. This allows using ring hash
  without xDS.

- Add the ability to specify the location of endpoints on the ring, and a
  default implementation based on EDS metadata that matches Envoy behavior.

See https://github.com/grpc/proposal/blob/master/A76-ring-hash-improvements.md
for details.

Release Notes:

- ringhash: implement gRFC A76.
Copy link
Contributor

@danielzhaotongliu danielzhaotongliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps @easwars or @dfawley should also take a pass at the review if they have time.

Comment on lines +59 to +62
// XDSEndpointHashKeyBackwardCompat disables parsing of the endpoint hash
// key from EDS LbEndpoint metadata. We can disable this behavior by setting
// the environment variable "GRPC_XDS_ENDPOINT_HASH_KEY_BACKWARD_COMPAT" to
// "true".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since the default value of this GRPC_XDS_ENDPOINT_HASH_KEY_BACKWARD_COMPAT is true and the plan is to flip the default to false once it is stable (which is the opposite of most other env var protection). I think this comment should mention the migration strategy, e.g. the current default if unset is true and once this feature proves stable, we would flip the default to false

@@ -708,6 +713,10 @@ func EndpointResourceWithOptions(opts EndpointOptions) *v3endpointpb.ClusterLoad
},
}
}
metadata, err := structpb.NewStruct(b.Metadata)
if err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education, would it be the right behaviour to panic here? Or should we return an empty metadata?

cfg.RequestHashHeader = ""
}
if cfg.RequestHashHeader != "" {
// See rules in https://github.com/grpc/proposal/blob/b64e6d3953816ed3b16b88bde0b7c16d3b62654f/A76-ring-hash-improvements.md#explicitly-setting-the-request-hash-key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -94,6 +98,27 @@ func (s) TestParseConfig(t *testing.T) {
want: nil,
wantErr: true,
},
{
name: "request metadata key set",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a test case for when there are multiple header values from the gRFC A76

If the header contains multiple values, then values are joined with a comma , character before hashing.

Comment on lines +77 to +79
if err := metadata.ValidateKey(cfg.RequestHashHeader); err != nil {
return nil, fmt.Errorf("invalid request_metadata_key %q: %s", cfg.RequestHashHeader, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would metadata.ValidateKey cover the case with multiple header values from the gRFC A76?

If the header contains multiple values, then values are joined with a comma , character before hashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Resolvers/Balancers Includes LB policy & NR APIs, resolver/balancer/picker wrappers, LB policy impls and utilities. Area: xDS Includes everything xDS related, including LB policies used with xDS. P1 Status: Requires Reporter Clarification Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement A76: Improvements to the Ring Hash LB Policy
4 participants