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

Added cluster/leader endpoint #3009

Merged
merged 3 commits into from
Mar 22, 2018
Merged

Added cluster/leader endpoint #3009

merged 3 commits into from
Mar 22, 2018

Conversation

aantono
Copy link
Contributor

@aantono aantono commented Mar 13, 2018

What does this PR do?

This PR introduces a /cluster/leader endpoint, which will return 200-OK or 429-Too-Many-Requests status, depending on if the particular node is a leader or not. The corresponding json payload will also be returned with {"leader":"true"} in case the node is a leader and {"leader":"false"} if it is not.

Motivation

This will enable creating various Load Balancers on top of a Traefik cluster, which will only route API requests to the current leader, instead of randomly to any instance in the cluster. The return of 429 status code will make most load balancers (like Netscalar or ELB, etc) to keep the instances in the pool, but "temporarily" not send any requests to them.

@emilevauge
Copy link
Member

Hey @aantono, could you explain why you need to access to the API only on the leader ?

@aantono
Copy link
Contributor Author

aantono commented Mar 14, 2018

If you add all the instances to an ELB for their api port, you get fluctuations in the data, specifically the health/stats, because each request gets randomly sent to some instance. Having only 1 instance (the leader) of the cluster be there would make things more consistent. All of api requests would always be routed to the leader in that setup. If one wants to have all the instances randomly routed, they can use /ping as a check instead of /cluster/leader

@emilevauge
Copy link
Member

@aantono so you are using the cluster in fail over mode right ?

@aantono
Copy link
Contributor Author

aantono commented Mar 15, 2018

Yep. Though we only use it in that mode for access to API/Dashboard endpoint, but it can be used in that mode for traffic routing as well, depending on which ports the ELB is proxying.

server/server.go Outdated
@@ -724,6 +724,10 @@ func (s *Server) addInternalRoutes(entryPointName string, router *mux.Router) {
if s.globalConfiguration.API != nil && s.globalConfiguration.API.EntryPoint == entryPointName {
s.globalConfiguration.API.AddRoutes(router)
}

if s.leadership != nil {
Copy link
Member

Choose a reason for hiding this comment

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

You can't put this route on all entrypoints.
This route must be activated only on the entrypoint where we activate --api. So you need to put it in the API if.

Moreover, I think the endpoint should be /api/cluster/leader, WDYT?

Copy link
Member

@mmatur mmatur left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks for your contribution @aantono 👏

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants