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

[feature] Add healthcheck endpoints /livez and /readyz #2783

Merged
merged 2 commits into from
Mar 25, 2024

Conversation

tsmethurst
Copy link
Contributor

Description

If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.

If this is a documentation change, please briefly describe what you've changed and why.

This pull request adds some simple health check endpoints, and documentation for how to configure a health check.

Closes #2707

Checklist

Please put an x inside each checkbox to indicate that you've read and followed it: [ ] -> [x]

If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).

  • I/we have read the GoToSocial contribution guidelines.
  • I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
  • I/we have not leveraged AI to create the proposed changes.
  • I/we have performed a self-review of added code.
  • I/we have written code that is legible and maintainable by others.
  • I/we have commented the added code, particularly in hard-to-understand areas.
  • I/we have made any necessary changes to documentation.
  • I/we have added tests that cover new code.
  • I/we have run tests and they pass locally with the changes.
  • I/we have run go fmt ./... and golangci-lint run.

@NyaaaWhatsUpDoc
Copy link
Member

NyaaaWhatsUpDoc commented Mar 25, 2024

@tsmethurst this otherwise looks good and ready to go, but just one question: would it be worth instead doing a database ping instead of an actual select on a table? or instead just do a select on a table with no columns (just so we don't end up doing any actual searching).

@tsmethurst
Copy link
Contributor Author

Mm, the nice thing about doing a little select instead of a ping is that I don't think pinging catches things like database locked etc. Actually selecting something is a bit more of a representative test of "is this thing on", imo.

or instead just do a select on a table with no columns (just so we don't end up doing any actual searching).

I'd be happy to change it to that yeah, like just a SELECT * [...] LIMIT 1 you mean? Is that cheaper?

@NyaaaWhatsUpDoc
Copy link
Member

NyaaaWhatsUpDoc commented Mar 25, 2024

Mm, the nice thing about doing a little select instead of a ping is that I don't think pinging catches things like database locked etc. Actually selecting something is a bit more of a representative test of "is this thing on", imo.

or instead just do a select on a table with no columns (just so we don't end up doing any actual searching).

I'd be happy to change it to that yeah, like just a SELECT * [...] LIMIT 1 you mean? Is that cheaper?

no i mean you can write a statement that basically returns just none of the columns, so for example here's:

sqlite> select null from instances limit 0;
Run Time: real 0.000 user 0.000075 sys 0.000000

and then compared to the original:

sqlite> select id from instances where domain = "k.iim.gay";
01A0XSYN1D4BG83VMGPEV17PH2
Run Time: real 0.000 user 0.000177 sys 0.000000

not a huge difference given they're both absurdly fast, but there is some

EDIT:
if you set .timer onwhen in sqlite interactive you can play around a bit and see. obviously there's some variance between each time you execute them but it's generally useful for showing ballpark figures if you run it a few times

@tsmethurst
Copy link
Contributor Author

Got it! Changed it here 4924713 and it seems to work for both sqlite and postgres :)

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc merged commit b7b42e8 into main Mar 25, 2024
3 checks passed
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc deleted the health_check branch March 25, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] Provide healthcheck endpoints for uptime monitoring
2 participants