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

/healthz endpoint accepts JSON now #5558

Merged
merged 7 commits into from
Apr 21, 2020
Merged

/healthz endpoint accepts JSON now #5558

merged 7 commits into from
Apr 21, 2020

Conversation

farazdagi
Copy link
Contributor

@farazdagi farazdagi commented Apr 21, 2020

Resolves #5546

  • Extends /healthz to accept JSON as preferred output.
  • By default text/plain context type is used, however, when JSON is accepted as response (that's when Accept: application/json, */*;q=0.5 header is sent), output is JSON:
{
    "data": [
        {
            "error": "",
            "service": "*attestations.Service",
            "status": true
        },
        {
            "error": "",
            "service": "*powchain.Service",
            "status": true
        }
    ],
    "error": ""
}
  • Fixes the response code as well. Previously whenever some service was down HTTP 500 error was returned, this is incorrect use of the code (that code is suitable for situations when server cannot complete request due to some problem, in our case server is capable of performing request, and as such 200 OK is valid code). Each individual service has status field (both in plain and JSON output), as well as error message, so individual services can be checked.
  • To keep PR focused, only /healthz endpoint is extended (while code was written in a way that it shouldn't be to hard to extend /metrics and /goroutinez endpoints as well)

@farazdagi farazdagi marked this pull request as ready for review April 21, 2020 17:02
@farazdagi farazdagi requested a review from a team as a code owner April 21, 2020 17:02
@farazdagi farazdagi requested a review from 0xKiwi April 21, 2020 17:02
@farazdagi farazdagi added Ready For Review A pull request ready for code review and removed In Progress labels Apr 21, 2020
w.WriteHeader(http.StatusOK)
}

switch negotiateContentType(r) {
Copy link
Member

Choose a reason for hiding this comment

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

What if the header is unset, as it usually is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then negotiateContentType() defaults to text/plain (and this is covered by unit test). So, whenever nothing is specified, we basically have the previous functionality, if "Accept:" header is provided, then we parse and use it.

@prylabs-bulldozer prylabs-bulldozer bot merged commit e753cbb into master Apr 21, 2020
@delete-merged-branch delete-merged-branch bot deleted the json-healthz branch April 21, 2020 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return JSON for /healthz
2 participants