Vue Storefront is now Alokai! Learn More
Readiness Probes

Readiness probes

Users of Alokai Cloud have their middleware deployed in Kubernetes. Readiness probes allow an application to temporarily mark itself as unable to serve requests in a Kubernetes cluster.

As of version 5.0.0 of the @vue-storefront/middleware package, you can launch the middleware and send a GET request to the http://localhost:4000/readyz endpoint. The response will contain either a success message or a list of errors describing why the readiness probe failed.

The same endpoint is queried automatically by Alokai Cloud every few seconds to check whether requests should be routed to a particular middleware replica. One such case is if a middleware instance is being killed (if it receives a SIGTERM signal), it should stop accepting traffic, but wait a few seconds before shutting down to handle any requests that are still being handledby that instance.

You can read more about Kubernetes readiness probes in the official documentation.

Adding custom readiness probes

To add custom readiness probes, pass them to the readinessProbes property when calling createServer.

const customReadinessProbe = async () => { 
  const dependentServiceRunning = await axios.get('http://someservice:3000/healthz');
  if(dependentServiceRunning.status !== 200) {
    throw new Error('Service that the middleware depends on is offline. The middleware is temporarily not ready to accept connections.')
  }
}
const app = await createServer(config, { readinessProbes: [customReadinessProbe]});

In order for custom readiness probes to be implemented correctly, they need to do two things:

  1. they must all be async or return a promise (the return value is not checked, it's expected to be void/undefined)
  2. they must all throw an exception when you want a readiness probe to fail