-
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
balancer/endpointsharding: Ignore empty endpoints #7674
balancer/endpointsharding: Ignore empty endpoints #7674
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7674 +/- ##
==========================================
+ Coverage 81.68% 81.85% +0.17%
==========================================
Files 374 374
Lines 38136 38140 +4
==========================================
+ Hits 31150 31219 +69
+ Misses 5710 5661 -49
+ Partials 1276 1260 -16
|
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.
Can you add a unit test for this behaviour to catch future regressions?
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.
+1 to the request for a test case.
// Check/return early if any endpoints have no addresses. | ||
|
||
addrs := resolver.NewAddressMap() | ||
// Check/return early if any endpoints have no addresses, or there is a duplicate address map. |
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.
s/map//.
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.
Added a unit test, thanks. |
es := NewBalancer(nil, balancer.BuildOptions{}) | ||
addr := resolver.Address{Addr: "addr1"} | ||
err := es.UpdateClientConnState(balancer.ClientConnState{ | ||
ResolverState: 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.
This is pretty limited in what it covers. E.g. it doesn't cover addresses across endpoints, or endpoints with multiple addresses. Please add some more test cases to cover more possibilities -- probably make it table driven where []Endpoint
is the input and the result is probably just a bool
to indicate whether there should be an error or not.
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.
Added more coverage for passing and failing tests.
Updated endpointsharding as per offline discussion:
|
if len(endpoints) == 0 { | ||
return errors.New("endpoints list is empty") | ||
} |
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 you can just delete this? It's a subset of the other validation?
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 kept this here soley for the sake of the more specific error string. I think the two are distinct, which is why I left this clause for a different error message.
// ValidateEndpoints returns an error if the endpoints list is empty, or no | ||
// addresses are present in endpoint list. |
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 should indicate how/why/when to use this, not what it does.
// The EndpointSharding balancer assumes ValidateEndpoints has been used to validate all Endpoints
// passed to UpdateCLientConnState.
?
Or is this scenario actually not a problem for the endpointsharding balancer itself? In which case maybe this function belongs in package resolver
or balancer
?
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.
Yeah I can move it to resolver or balancer, as this should trigger failure case in all petiole policies. Mark - "All petiole LB policies reject updates with no addresses."
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.
But also since it's gatekeeped in all petiole policies maybe it does make sense to keep it here? Although looks like we won't use this in petiole like ring hash so I'll move it to resolver.
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.
Updated comment as well, let me know what you think.
// UpdateClientConnState creates a child for new endpoints and deletes children | ||
// for endpoints that are no longer present. It also updates all the children, | ||
// and sends a single synchronous update of the childrens' aggregated state at | ||
// the end of the UpdateClientConnState operation. If any endpoint has no | ||
// addresses it will ignore that endpoint. Otherwise, returns first error found | ||
// from a child, but fully processes the new update. |
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.
Nobody will see this godoc comment here since it's on an unexported type.
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.
Are you ok with 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.
I'm fine with comments that aren't visible to anyone but someone reading the code. But make sure they aren't supposed to be showing up in godoc. Godoc should have enough info that the package is usable by someone who doesn't know what it does before viewing the godocs, and unexported comments should focus on how the implementation works and why it's the way it is.
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 reread this comment and I think the language here appropriate for this not public facing operation (all relate to the UpdateClientConnState() operation), and the exported comments seem good enough to me. Do you want me to take some of this information and put it in exported go doc?
resolver/resolver.go
Outdated
@@ -330,3 +331,19 @@ type AuthorityOverrider interface { | |||
// typically in line, and must keep it unchanged. | |||
OverrideAuthority(Target) string | |||
} | |||
|
|||
// ValidateEndpoints validates endpoints are valid from a petiole policies |
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.
"Valid" now appears 3 times. And spelling mistake:
ValidateEndpoints validates endpoints from a petiole _policy's_ perspective.
But now you should also explain what that actually means?
How about:
ValidateEndpoints validates that the endpoints are valid to use in a petiole policy - i.e. they must be non-empty and each must contain at least one address.
And what's a petiole policy? Is this defined somewhere? Maybe add: "See [A61] for details"?
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.
Hmmm ok. At first I thought I needed to add Outlier Detection to this, but that isn't a petiole policy (can't use it directly on top of pick first, that is invalid), and this is meant to trigger reresolution and reject the update. This happens from the petiole policy layer so the only thing important in OD is to ignore endpoints with no addresses and to have the undefined behavior in shared addresses, and leave petiole policies to trigger this error.
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.
Switched to
// ValidateEndpoints validates endpoints from a petiole policy's perspective.
// Petiole policies should call this before calling into their children. See
// [gRPC A61](https://github.com/grpc/proposal/blob/master/A61-IPv4-IPv6-dualstack-backends.md)
// for details.
// UpdateClientConnState creates a child for new endpoints and deletes children | ||
// for endpoints that are no longer present. It also updates all the children, | ||
// and sends a single synchronous update of the childrens' aggregated state at | ||
// the end of the UpdateClientConnState operation. If any endpoint has no | ||
// addresses it will ignore that endpoint. Otherwise, returns first error found | ||
// from a child, but fully processes the new update. |
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 fine with comments that aren't visible to anyone but someone reading the code. But make sure they aren't supposed to be showing up in godoc. Godoc should have enough info that the package is usable by someone who doesn't know what it does before viewing the godocs, and unexported comments should focus on how the implementation works and why it's the way it is.
e3164e3
to
849735f
Compare
849735f
to
3c568e2
Compare
This PR ignores empty endpoints in endpoint sharding, and adds a validation helper in the resolver package that all petiole policies should call.
RELEASE NOTES: