@sigfox/koa-k8s-probes

1.0.0 • Public • Published

koa-k8s-probes

Koa middleware mounting customizable probes for readiness and liveness checks, especially useful in a Kubernetes runtime context.

Features

Mount GET /liveness and /readiness routes to your Koa application. By default, these routes will always return a 200 HTTP status code.

You can customize each route check by setting the livenessProbe or readinessProbe attributes when mounting middleware. These custom checks would have to return a Promise. If resolved, a 200 HTTP status code will be returned, otherwise it will be a 503.

Install

npm install @sigfox/koa-k8s-probes

Usage

const k8sProbes = require('@sigfox/koa-k8s-probes');
const Koa = require('koa');

async function readinessProbe(ctx) {
  const { mongodbClient, redisClient, otherClient } = ctx.services;
  await Promise.all([
    mongodbClient.db.command({ ping: 1 }),
    redisClient.ping(),
    otherClient.someCheck()
  ]);
}

const app = new Koa().use(k8sProbes()); // always return 200 with default configuration
const app = new Koa().use(k8sProbes({ readinessProbe })); // customize readiness route and return 503 when promise is rejected

const server = app.listen();

Test

npm test

Licence

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i @sigfox/koa-k8s-probes

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

4.92 kB

Total Files

5

Last publish

Collaborators

  • robnriks
  • cgrimal
  • damien-s
  • lbdremy