Skip to content

feat: Add /healthz and /readyz endpoint for liveness and readiness probes - #1259

Open
lollo03 wants to merge 6 commits into
garethgeorge:mainfrom
lollo03:main
Open

feat: Add /healthz and /readyz endpoint for liveness and readiness probes #1259
lollo03 wants to merge 6 commits into
garethgeorge:mainfrom
lollo03:main

Conversation

@lollo03

@lollo03 lollo03 commented Jun 13, 2026

Copy link
Copy Markdown

This change introduces new unauthenticated GET /healthz and GET /readyz endpoints.

These are primarily intended for use as liveness and readiness probes in environments like Kubernetes.

Changes:

  • Adds handlers in internal/api/health/health.go.
  • Registers the /healthz and /readyz routes in the main application router.
  • Includes unit tests to verify the handlers' behavior.
  • Updates api.md to document the new endpoints.

The /healthz endpoint simply checks if the API server is alive, while /readyz the database is accessible.

Fixes #1235

This is a proof of concept; I am seeking input on a more robust implementation.

@CLAassistant

CLAassistant commented Jun 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@nvtkaszpir

Copy link
Copy Markdown
Contributor

with auth required endpoint you could just check if the metrics endpoint returns 401 :D

@lollo03 lollo03 changed the title feat: Add /healthz endpoint for liveness probes feat: Add /healthz and /readyz endpoint for liveness and readyness probes Jun 13, 2026
@lollo03

lollo03 commented Jun 13, 2026

Copy link
Copy Markdown
Author

@nvtkaszpir You're right, though that approach isn't quite standard. I've also added a /readyz endpoint, which should be more useful here. Any feedback is welcome!

@lollo03 lollo03 changed the title feat: Add /healthz and /readyz endpoint for liveness and readyness probes feat: Add /healthz and /readyz endpoint for liveness and readiness probes Jun 13, 2026
Comment thread internal/api/health/health.go Outdated
@lollo03
lollo03 marked this pull request as ready for review June 13, 2026 19:19
Move ReadyHandler creation from newRootMux to newServer, passing only
the http.HandlerFunc instead of raw dependencies (configMgr, db).
@lollo03

lollo03 commented Jun 18, 2026

Copy link
Copy Markdown
Author

Hello @garethgeorge can you review this PR? This could be useful

@garethgeorge

Copy link
Copy Markdown
Owner

Hey -- apologies for the late review. Thanks for the interest in contributing! Generally, adding adding a health check and readiness probe endpoint sounds good to me, but a few thoughts on the current impl

  1. sharedKvdb is the kv/peer-state DB, but isn't the the operations log (opLog/sqlitestore) which is the more important one. Probably want the healthcheck to check the oplog at a minimum, it may be worth just having the healthcheck actually query the operation log with a short limit to test that it can get well formatted results.
  2. 10s is a long timeout, set this to e.g. 1s.
  3. configMgr.Get() failing is unusual -- typically this can only happen on startup and a failure blocks the binary from becoming healthy.

lollo03 added 2 commits July 1, 2026 10:18
The readiness probe no longer checks whether the config is loaded.
This simplifies the handler and removes the config dependency.
…ness probe

- ReadyHandler now queries the oplog (LIMIT 1) instead of pinging the
  shared kvdb, which is less critical.
- Removed the Pinger interface and db parameter from newServer.
- Timeout reduced from 10s to 2s.
- Extracted writeReady helper and added doc comments.
@lollo03

lollo03 commented Jul 1, 2026

Copy link
Copy Markdown
Author

Hello, implemented your suggestions. Let me know what do you think.

@garethgeorge
garethgeorge force-pushed the main branch 3 times, most recently from 1a75a0a to aeade74 Compare July 10, 2026 09:45
@lollo03

lollo03 commented Jul 12, 2026

Copy link
Copy Markdown
Author

@garethgeorge would you please review the changes?

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.

Add an unauthenticated /health endpoint for liveness monitoring

4 participants