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

balancer/endpointsharding: Ignore empty endpoints #7674

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

zasweq
Copy link
Contributor

@zasweq zasweq commented Sep 26, 2024

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: N/A

@zasweq zasweq requested a review from dfawley September 26, 2024 22:21
@zasweq zasweq added this to the 1.68 Release milestone Sep 26, 2024
@zasweq zasweq added the Type: Feature New features or improvements in behavior label Sep 26, 2024
Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 81.78%. Comparing base (9affdbb) to head (472a486).
Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
balancer/endpointsharding/endpointsharding.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7674      +/-   ##
==========================================
- Coverage   82.01%   81.78%   -0.24%     
==========================================
  Files         361      361              
  Lines       27819    27830      +11     
==========================================
- Hits        22815    22760      -55     
- Misses       3823     3868      +45     
- Partials     1181     1202      +21     
Files with missing lines Coverage Δ
resolver/resolver.go 100.00% <100.00%> (ø)
balancer/endpointsharding/endpointsharding.go 67.74% <0.00%> (+0.81%) ⬆️

... and 36 files with indirect coverage changes

Copy link
Contributor

@arjan-bal arjan-bal left a 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?

balancer/endpointsharding/endpointsharding.go Outdated Show resolved Hide resolved
Copy link
Member

@dfawley dfawley left a 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.
Copy link
Member

Choose a reason for hiding this comment

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

s/map//.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@dfawley dfawley assigned zasweq and unassigned dfawley Sep 27, 2024
@zasweq
Copy link
Contributor Author

zasweq commented Sep 30, 2024

Added a unit test, thanks.

@zasweq zasweq assigned dfawley and unassigned zasweq Sep 30, 2024
es := NewBalancer(nil, balancer.BuildOptions{})
addr := resolver.Address{Addr: "addr1"}
err := es.UpdateClientConnState(balancer.ClientConnState{
ResolverState: resolver.State{
Copy link
Member

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.

Copy link
Contributor Author

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.

@dfawley dfawley assigned zasweq and unassigned dfawley Oct 1, 2024
@zasweq zasweq assigned dfawley and unassigned zasweq Oct 1, 2024
{Addresses: []resolver.Address{addr1, addr2}},
{Addresses: []resolver.Address{}},
},
wantErr: true,
},
Copy link
Member

Choose a reason for hiding this comment

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

Please add a couple more:

  • no error with addr1+2 and addr3+4 in separate endpoints -- you should generally always have a "pass" test.
  • error where endpoint1 has the same addr multiple times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline; had the first case. Added the second case.

@dfawley dfawley assigned zasweq and unassigned dfawley Oct 7, 2024
@zasweq zasweq assigned dfawley and unassigned zasweq Oct 7, 2024
@zasweq
Copy link
Contributor Author

zasweq commented Oct 8, 2024

Updated endpointsharding as per offline discussion:

  • Validate errors if empty endpoints or no addresses present in endpoints
  • UpdateClientConnState simply ignores endpoints with no addresses

Comment on lines 81 to 83
if len(endpoints) == 0 {
return errors.New("endpoints list is empty")
}
Copy link
Member

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?

Copy link
Contributor Author

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.

Comment on lines 78 to 79
// ValidateEndpoints returns an error if the endpoints list is empty, or no
// addresses are present in endpoint list.
Copy link
Member

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?

Copy link
Contributor Author

@zasweq zasweq Oct 8, 2024

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."

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Comment on lines 93 to 98
// 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.
Copy link
Member

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.

Copy link
Contributor Author

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?

@dfawley dfawley assigned zasweq and unassigned dfawley Oct 8, 2024
@zasweq zasweq assigned dfawley and unassigned zasweq Oct 8, 2024
@zasweq zasweq changed the title balancer/endpointsharding: Return error if duplicate addresses balancer/endpointsharding: Ignore empty endpoints Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants