-
Notifications
You must be signed in to change notification settings - Fork 4.6k
balancer/randomsubsetting: Implementation of the random_subsetting LB policy #8650
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: marek-szews <[email protected]>
|
@marek-szews : Could you please get the tests to pass. Thanks. |
|
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
|
Hi @marek-szews - I think we're waiting on you to make some updates so we can continue the review. We can discuss Friday but I wanted to ping this in part to prevent the stale bot from closing it. |
marek-szews
left a comment
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.
Rework done, tests passed
Tests are still failing. Please read this document for guidelines: https://github.com/grpc/grpc-go/blob/master/CONTRIBUTING.md TL;dr |
| } | ||
|
|
||
| if b.cfg == nil || b.cfg.ChildPolicy.Name != lbCfg.ChildPolicy.Name { | ||
|
|
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.
Please remove this newline.
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
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.
I'm talking about the newline after the if and before the call to SwitchTo.
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
| maxDiff int | ||
| }{ | ||
| { | ||
| name: "backends could be evenly distributed between small number of clients", |
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.
Please see here for guidelines on how best to name subtests: https://google.github.io/styleguide/go/decisions#subtest-names
TL;dr
Think of subtest names more like a function identifier than a prose description.
The test runner replaces spaces with underscores, and escapes non-printing characters. To ensure accurate correlation between test logs and source code, it is recommended to avoid using these characters in subtest names.
|
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8650 +/- ##
==========================================
+ Coverage 79.45% 83.19% +3.74%
==========================================
Files 415 419 +4
Lines 41339 32429 -8910
==========================================
- Hits 32844 26978 -5866
+ Misses 6621 4062 -2559
+ Partials 1874 1389 -485
🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| if b.cfg == nil || b.cfg.ChildPolicy.Name != lbCfg.ChildPolicy.Name { | ||
|
|
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.
I'm talking about the newline after the if and before the call to SwitchTo.
| func (b *subsettingBalancer) UpdateClientConnState(s balancer.ClientConnState) error { | ||
| lbCfg, ok := s.BalancerConfig.(*lbConfig) | ||
| if !ok { | ||
| b.logger.Errorf("Received config with unexpected type %T: %v", s.BalancerConfig, s.BalancerConfig) |
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.
This should probably be logged at WARNING level instead of error. Please see https://github.com/grpc/grpc-go/blob/master/Documentation/log_levels.md for guidance on what logging levels to use.
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
| func (b *subsettingBalancer) prepareChildResolverState(s balancer.ClientConnState) resolver.State { | ||
| subsetSize := b.cfg.SubsetSize | ||
| endpoints := s.ResolverState.Endpoints | ||
| if len(endpoints) <= int(subsetSize) || subsetSize < 2 { |
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.
The subsetting algorithm described in the gRFC does not specify any special considerations for subset sizes less than two. Please see: https://github.com/grpc/proposal/blob/master/A68-random-subsetting.md#subsetting-algorithm
So, please remove this condition subsetSize < 2. If the user wants a subset size of 1, they should get just that.
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
|
|
||
| // implements the subsetting algorithm, | ||
| // as described in A68: https://github.com/grpc/proposal/blob/master/A68-random-subsetting.md | ||
| func (b *subsettingBalancer) prepareChildResolverState(s balancer.ClientConnState) resolver.State { |
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.
Is there any reason for this method to accept a balancer.ClientConnState and return a resolver.State. Why not accept a []resolver.Endpoint and return a []resolver.Endpoint? and let the caller deal with creating the resolver.State to be passed to the child.
Also, when we do that, we should rename this method appropriately.
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.
Yes, it's a good idea to do this, especially since the interface of this function has changed completely (in/out).
Done
| } | ||
|
|
||
| // implements the subsetting algorithm, | ||
| // as described in A68: https://github.com/grpc/proposal/blob/master/A68-random-subsetting.md |
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.
If adding a link, please add it to the specific sub-section in the gRFC that talks about the subsetting algorithm or just don't add one.
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
| * | ||
| */ | ||
|
|
||
| // Package e2e_test contains e2e test cases for the Subsetting LB Policy. |
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.
This comment is not valid anymore.
| wantErr string | ||
| }{ | ||
| { | ||
| name: "invalid-json", |
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.
Nit: s/invalid-json/invalid_json/
See: https://google.github.io/styleguide/go/decisions#subtest-names
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
| { | ||
| name: "invalid-json", | ||
| input: "{{invalidjson{{", | ||
| wantErr: "invalid character", |
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.
This has now become a change detector test for the json package. Please change the error string returned when unmarshal fails so that you can look for that here instead. So, maybe something like:
if err := json.Unmarshal(s, lbCfg); err != nil {
return nil, fmt.Errorf("randomsubsetting: json.Unmarshal failed for configuration: %s with error: %v", string(s), err)
}Then, your wantErr here could be "json.Unmarshal failed for configuration"
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
| if diff := cmp.Diff(gotCfg, test.wantCfg); diff != "" { | ||
| t.Fatalf("ParseConfig(%v) got unexpected output, diff (-got +want): %v", test.input, diff) | ||
| } |
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.
I think the order of arguments passed to cmp.Diff and in the error message is inverted. See here for examples: https://google.github.io/styleguide/go/decisions#equality-comparison-and-diffs
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
| } | ||
| } | ||
|
|
||
| func (s) TestSubsettingE2E(t *testing.T) { |
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.
The only real piece of functionality provided by this LB policy is the subsetting algorithm. If we refactor it the way I recommended in another comment, then we could simply have unit tests for that method to ensure that subsetting behavior is as expected.
And then we could have a functional test where we:
- create an instance of the LB policy,
- call its
UpdateClientConnStatemethod to pass it some configuration with a child policy that is controlled by the test. See here for how to define a balancer that is completely under the control of the test: https://github.com/grpc/grpc-go/blob/master/internal/balancer/stub/stub.go - Verify that the child policy gets the expected
resolver.State
There is very little value is having an E2E style for this LB policy.
Implements [gRFC A68]https://github.com/grpc/proposal/blob/master/A68-random-subsetting.md.
Note that this PR only implements the LB policy and does not implement the xDS integration specified here: https://github.com/grpc/proposal/blob/master/A68-random-subsetting.md#xds-integration
RELEASE NOTES:
random_subsettingLB policy