I'm submitting a ...
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:
200 if recoverable)postgraphileSome 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
}
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:
postgraphile:options to tweak appendPlugins to add a schema plugin using makeProcessSchemaPlugin that toggles a variable to say that the schema has been generated (this is the "schema": true)postgraphile:http:handler to intercept the result if it's for us (if it is, return null, otherwise return the incoming request)https://github.com/graphile/postgraphile/blob/d2374174adfb363c20fc068aea255ad45bbbe708/src/postgraphile/http/createPostGraphileHttpRequestHandler.ts#L435-L446Not 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
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?