kubernetes-health
Version:
Helper library for implementing Kubernetes heath checks and graceful HTTP shutdown in Node applications
77 lines (76 loc) • 2.31 kB
TypeScript
/// <reference types="node" />
import http from 'http';
import { Health } from './Health';
/**
* A probe listener for the liveness or readiness status of the application. Supports Express, Connect,
* Fastify, Koa, and `http.Server`.
*/
export interface ProbeListener {
(ctx: {
res: http.ServerResponse;
}): void;
(req: any, res: http.ServerResponse): void;
(req: any, res: {
raw: http.ServerResponse;
}): void;
}
/**
* Creates a new `ProbeListener` that returns 200 if the specified `Health` instance is live, and 500 otherwise.
*
* @param health the `Health` instance
* @returns an `ProbeListener`
*/
export declare function createLivenessProbeListener(health: Health): ProbeListener;
/**
* Creates a new `ProbeListener` that returns 200 if the specified `Health` instance is ready, and 500 otherwise.
*
* @param health the `Health` instance
* @returns an `ProbeListener`
*/
export declare function createReadinessProbeListener(health: Health): ProbeListener;
/**
* Options for the health probe server
*/
export interface ProbeServerOptions {
/**
* Pathname of the liveness endpoint
*
* @default '/healthz'
*/
livenessEndpoint?: string;
/**
* Pathname of the readiness endpoint
*
* @default '/readyz'
*/
readinessEndpoint?: string;
}
/**
* Creates a new `http.Server` configured to serve the liveness and readiness endpoints for a given Health instance.
*
* @param health the `Health` instance to serve
* @param options options for the health probe server
* @returns an `http.Server` ready to serve the health probes
*/
export declare function createProbeServer(health: Health, options?: ProbeServerOptions): http.Server;
export interface ProbeServerListenOptions {
/**
* The port to listen on
*
* @default 4000
*/
port?: number;
/**
* The hostname to bind to
*
* @default all hostnames
*/
hostname?: string;
}
/**
* Create and start a health probe server, listening on on the specified port / hostname.
*
* @param health the `Health` instance to serve
* @param options options for the health probe server
*/
export declare function startProbeServer(health: Health, options?: ProbeServerOptions & ProbeServerListenOptions): http.Server;