Postgraphile: Feature Request: expose health check endpoint

Created on 14 Jun 2019  Â·  5Comments  Â·  Source: graphile/postgraphile

I'm submitting a ...

  • [ ] bug report
  • [x] feature request
  • [ ] question

PostGraphile version: v4.4.0

For deployments within containerized environments, it would be convenient if the server exposed a default health check endpoint (conventionally /healthz in Kubernetes). A simple 200/500 status code with an empty response would be enough, but it might make sense to expose some basic metadata as well. At minimum, I think this endpoint should check for:

  • schema build errors (200 if recoverable)
  • connection to postgres
  • successful startup of postgraphile

Some examples:

// status: 200
{
  "schema": true,
  "postgraphile": true,
  "database": true
}
// recoverable schema errors
// status: 200
{
  "schema": false,
  "postgraphile": true,
  "database": true
}
// fail to connect to postgres
// status: 500
{
  "schema": false,
  "postgraphile": true,
  "database": false
}
✨ Possible via v4 plugin 💅 enhancement

Most helpful comment

This sounds like it should be a server plugin (namely because I don’t think it should be added by default because it risks overriding any healthz endpoint the user has added themselves). Since we don’t keep connections open to the database for more than a few idle seconds (8?), would you want this to make its own connection to DB, or to check the initial connection succeeded, or perhaps something more complex like seeing if the last connection attempt succeeded/failed?

All 5 comments

This sounds like it should be a server plugin (namely because I don’t think it should be added by default because it risks overriding any healthz endpoint the user has added themselves). Since we don’t keep connections open to the database for more than a few idle seconds (8?), would you want this to make its own connection to DB, or to check the initial connection succeeded, or perhaps something more complex like seeing if the last connection attempt succeeded/failed?

I was thinking it should probably make its own connection to the db to check for connectivity at the time the health check is being performed. The postgraphile check in the above examples would necessarily imply the initial connection succeeded.

I think this can entirely be achieved via a server plugin:

Not sure what the difference between postgraphile: true and schema: true is.

Closing this as I don't think any action is necessary

I'm guessing this is because someone wanted to run the server on a kubernetes or similar environment, where a health check will help know if each instance of the service is running correctly.

I would like to know how one would do something similar but for the worker instead of the server. But I guess this is a question for https://github.com/graphile/worker

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jayp picture jayp  Â·  3Comments

5argon picture 5argon  Â·  4Comments

jwdotjs picture jwdotjs  Â·  5Comments

k-ogawa-1988 picture k-ogawa-1988  Â·  3Comments

kilianc picture kilianc  Â·  4Comments