-
Notifications
You must be signed in to change notification settings - Fork 487
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
Improvements to Consul nameresolver #2594
Conversation
Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: ItalyPaleAle <[email protected]>
Moving this back to draft as I realized there's a better way to do this: https://developer.hashicorp.com/consul/api-docs/agent/check#deregistercriticalserviceafter The risk is that if we delete a service, we may delete multiple instances when we just need to delete one. I'll also test in a Load balanced scenario |
Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: ItalyPaleAle <[email protected]>
After further investigation, looks like the initial approach of unregistering the service won't work and can't be made to work. I'm leaving this PR with only the "ancillary" improvements to the component. |
if err := r.client.Agent().ServiceRegister(r.config.Registration); err != nil { | ||
agent := r.client.Agent() | ||
|
||
err = agent.ServiceRegister(r.config.Registration) |
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 saw your comment about using deregistercriticalserviceafter
- but that fix not working.
Should we rather deregister before registering?
Documentation for ServiceDeregister(serviceID string) error
(https://developer.hashicorp.com/consul/commands/services/deregister) also recommends that it is meant to be paired with services register
.
It may not completely solve the issue but would certainly be a good practice most probably and may also help in solving issues like #2489
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.
That was actually what I first tried doing, and it didn't work because a service can have multiple instances if the app is scaled horizontally. Calling "ServiceDeregister" removed the entire service and so un-registered other instances of the app too.
I spent 2 hours on this yesterday and doesn't really look like Consul has any way to remove only one instance :(
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.
Ohh ok, got it.
Signed-off-by: ItalyPaleAle <[email protected]>
Description
This PR contains improvements to the Consul nameresolver, especially the
ResolveID
method which was more complex than it needed to be. In particular, the algorithm for picking a random entry from the list of results could be replaced with a much simpler one (complexity: O(n) to O(1), and removes N allocations on the heap), plus other small tweaks.Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: