gajus / lightship

Abstracts readiness, liveness and startup checks and graceful shutdown of Node.js services running in Kubernetes.
Other
515 stars 33 forks source link

Feature request: custom health check method #40

Closed fmoessle closed 2 years ago

fmoessle commented 2 years ago

Currently /live provides information about the current shutdown state of the server: "SERVER_IS_NOT_SHUTTING_DOWN" or "SERVER_IS_SHUTTING_DOWN".

While this is ok for simple use-cases, it does not truly reflect the liveness state of every application. Imagine your application loses the connection to its database (or something similar). In this case, you don't want /live to respond with 200 and "SERVER_IS_NOT_SHUTTING_DOWN". Instead, you want the liveness probe to fail and the application to be restarted.

godaddy/terminus let's define you a custom health check method

function healthCheck ({ state }) {
  // `state.isShuttingDown` (boolean) shows whether the server is shutting down or not
  return Promise.resolve(
    // optionally include a resolve value to be included as
    // info in the health check response
  )
}

and defaults to returning the state if no custom method was defined.

@gajus Is this a feature that could be implemented or would it be out-of-scope for this project?

gajus commented 2 years ago

Imagine your application loses the connection to its database (or something similar). In this case, you don't want /live to respond with 200 and "SERVER_IS_NOT_SHUTTING_DOWN"

Then you should either signal "not ready" or "not live" (depending on whether you expect application to automatically recover). Kubernetes will handle restarting of the application.

I don't comprehend the use case for what is being asked. What is going to be reading the custom response?