Add more elaborate health check endpoint that optionally hits the database#72
Merged
Add more elaborate health check endpoint that optionally hits the database#72
Conversation
brandur
commented
Jun 28, 2024
| SetBundle(bundle *apiBundle) | ||
| } | ||
|
|
||
| type statusResponse struct { |
Collaborator
Author
There was a problem hiding this comment.
A lot of endpoints return {status: "ok"}, so I made a common struct that they can share so we don't have to write a new response struct for each. statusResponseOK below is also a shortcut for making an OK response.
brandur
commented
Jun 28, 2024
| // InternalError is an additional error that might be associated with the | ||
| // API error. It's not returned in the API error response, but is logged in | ||
| // API endpoint execution to provide extra information for operators. | ||
| InternalError error `json:"-"` |
Collaborator
Author
There was a problem hiding this comment.
Added a possible internal error that an API error can be tagged with and which will be added to the logs by api_endpoint.go above. This is nice because it lets some additional context be added for operators without the possibility of leaking anything sensitive from an internal error via HTTP.
…abase An alternative to #68 that adds a pair of health check endpoints: * `GET /api/health-checks/complete` * `GET /api/health-checks/minimal` The minimal endpoint just returns an OK response regardless of anything else so it'll return 200 as long as the Go process is up. The complete endpoint runs the additional check of pinging the database, verifying its liveliness as well. This is useful because if the database is totally down then River UI will be totally non-functional, but the minimal endpoint would still return OK, and it's nice to have an alternative that'll return an unhealthy status. Based on something I wrote about last year here [1]. Fixes #67. [1] https://brandur.org/fragments/database-health-check
6792d5f to
29a4eed
Compare
Closed
bgentry
approved these changes
Jun 28, 2024
| // InternalError is an additional error that might be associated with the | ||
| // API error. It's not returned in the API error response, but is logged in | ||
| // API endpoint execution to provide extra information for operators. | ||
| InternalError error `json:"-"` |
Contributor
|
I had the same thoughts when seeing the health check PR so I love that you just went for it, thank you! |
Collaborator
Author
|
Wicked. Thanks! |
brandur
added a commit
that referenced
this pull request
Jun 28, 2024
Oops, I forgot to add a changelog entry for #72, but given it's a feature somewhat meant to be used by users, it should probably get one.
brandur
added a commit
that referenced
this pull request
Jun 28, 2024
Oops, I forgot to add a changelog entry for #72, but given it's a feature somewhat meant to be used by users, it should probably get one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An alternative to #68 that adds a pair of health check endpoints:
GET /api/health-checks/completeGET /api/health-checks/minimalThe minimal endpoint just returns an OK response regardless of anything
else so it'll return 200 as long as the Go process is up. The complete
endpoint runs the additional check of pinging the database, verifying its
liveliness as well. This is useful because if the database is totally down
then River UI will be totally non-functional, but the minimal endpoint
would still return OK, and it's nice to have an alternative that'll return
an unhealthy status. Based on something I wrote about last year here [1].
Fixes #67.
[1] https://brandur.org/fragments/database-health-check