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

Modify Status Leader API to return Status 500 when there is no leader #8408

Closed
wants to merge 1 commit into from

Conversation

nicholasjackson
Copy link
Contributor

@nicholasjackson nicholasjackson commented Jul 30, 2020

The API endpoint /v1/status/leader can return a HTTP status 200 and no leader in the response in certain instances. This mainly occurs in a race condition when you need to check if an agent has successfully joined a cluster before making a request to register a service or submit L7 config.

This PR implements a better RESTFull behaviour in the instance that the API is called and no leader is available. When there is no leader the API will return a HTTP status InternalServerError. I am not 100% convinced this is the correct status code as in fact the API is not returning an error but this mimics other No Leader error messages which can be returned from this API.

@mikemorris
Copy link
Contributor

Refs #8395, some of the tests in consul/api should likely be made more explicit as part of this change, even though they aren't currently failing because they only check response content and not HTTP status code.

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM, this change is correct and should fix the race. Being consistent with the status code seems good for now. We can fix the status code across the board for this error at some later time.

We should rebase this PR to run the latest tests, but otherwise I think this is good to merge.

agent/status_endpoint.go Outdated Show resolved Hide resolved
@vercel
Copy link

vercel bot commented Aug 3, 2021

@dnephin is attempting to deploy a commit to the HashiCorp Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Aug 3, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

consul-ui-staging – ./ui

🔍 Inspect: https://vercel.com/hashicorp/consul-ui-staging/En54zwsMkKLwKVwz7nXKf4EBqUZW
✅ Preview: Failed

@vercel vercel bot temporarily deployed to Preview – consul August 3, 2021 19:10 Inactive
@dnephin dnephin added theme/api Relating to the HTTP API interface type/bug Feature does not function as expected labels Aug 3, 2021
@vercel vercel bot temporarily deployed to Preview – consul August 3, 2021 19:14 Inactive
Copy link
Contributor

@markan markan left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! We were just about to merge this, thinking it would solve #10733, but after looking at the integration mentioned there (prometheus/consul_exporter source) I think unfortunate this is a breaking change. It would be more consistent with other API endpoints but would break existing users of this API endpoint.

The API endpoint /v1/status/leader can return a HTTP status 200 and no leader in the response in certain instances

Surprisingly this is actually always the case when there is no leader. There is no way for this endpoint to return a non-200 code if the query is being made to the local DC. It always returned an empty response if the leader is unknown. Maybe we should update the API docs and/or add a new API with the behaviour we expect (a non-200 code when there is no leader).

@dnephin dnephin self-assigned this Aug 10, 2021
@dnephin
Copy link
Contributor

dnephin commented Aug 10, 2021

Thanks again for the PR! Since this is a breaking change we won't be able to merge it, so I'm going to close this PR. I think it would be worthwhile to talk about expected behaviour for a v2 version of this endpoint in a github issue.

@dnephin dnephin closed this Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface type/bug Feature does not function as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants