Overview
Liveness + readiness probes for the AbsoluteJS substrate. One Elysia plugin, two endpoints, a standard JSON envelope that load balancers and Kubernetes-style orchestrators understand out of the box.
@absolutejs/healthv0.3.0betaPlatform & InfraLiveness and readiness probes for Bun services — one Elysia plugin exposing /healthz and /readyz with a standard JSON envelope.
Gives any Elysia app on Bun the /healthz and /readyz endpoints that load balancers and Kubernetes-style orchestrators expect, with a standard application/health+json envelope. createHealthChecker composes named checks with per-check timeouts, and the aggregate status is the worst of any check, so a single failing dependency flips the envelope to 503. Bundled check factories cover downstream HTTP dependencies, arbitrary probes, and metrics() snapshots from other @absolutejs packages.
bun add @absolutejs/healthLiveness + readiness probes for the AbsoluteJS substrate. One Elysia plugin, two endpoints, a standard JSON envelope that load balancers and Kubernetes-style orchestrators understand out of the box.
Endpoint — Purpose — Used by
/healthz — "Is this process alive?" If fail, the orchestrator restarts the container. — Kubernetes liveness probe, systemd WatchdogSec, @absolutejs/runtime
/readyz — "Can this instance serve traffic right now?" If fail, the LB stops routing to it (but doesn't kill it). — Load balancer health checks, drain workflows
The distinction matters: a draining instance returns readyz: fail
healthz: pass. The LB stops sending new traffic while in-flight
requests finish.
Compatible with the IETF health-check JSON draft and the Kubernetes livez / readyz conventions. content-type: application/health+json.
pass → 200 OK
warn → 200 OK (don't reroute traffic; surface in your dashboard)
fail → 503 Service Unavailable
LBs route on status code; humans + dashboards read the body.
Status is the WORST of any check: fail > warn > pass. A single failing dependency fails the whole envelope — same as Kubernetes /healthz rollup behavior.
probeCheck wraps any promise (resolve = pass, throw = fail), httpCheck grades a downstream URL by status code, and metricsCheck evaluates a metrics() snapshot into pass/warn/fail with observed values for dashboards.
Each check declares a kind ('liveness', 'readiness', or 'both') so heavy downstream checks run only under /readyz and liveness stays a cheap process-responsiveness probe.
/healthz answers "is this process alive?" (fail means restart it); /readyz answers "can it serve traffic right now?" (fail means stop routing, keep it running). A draining instance fails readiness while liveness stays green.
The JSON body follows the IETF health-check draft and Kubernetes livez/readyz conventions, served as application/health+json with Cache-Control: no-store.
Status rolls up as fail > warn > pass. warn still returns 200 — the LB keeps routing while your dashboard surfaces the degradation.
Outcomes
Liveness + readiness probes for the AbsoluteJS substrate. One Elysia plugin, two endpoints, a standard JSON envelope that load balancers and Kubernetes-style orchestrators understand out of the box.
Endpoint — Purpose — Used by
Compatible with the IETF health-check JSON draft and the Kubernetes livez / readyz conventions. content-type: application/health+json.
Hardening checklist
Follow in order
# @absolutejs/health
import { Elysia } from 'elysia';
import {
createHealthChecker,
healthPlugin,
metricsCheck,
probeCheck,
httpCheck,
} from '@absolutejs/health';
const checker = createHealthChecker({
checks: [
// Synthesis from a substrate package's metrics() snapshot.
metricsCheck('queue', () => worker.metrics(), (m) => ({
status: m.failed > 100 ? 'warn' : 'pass',
observed: { runs: m.runs, failed: m.failed },
})),
// Wrap an arbitrary probe.
probeCheck('postgres', () => pg.query('SELECT 1')),
// Downstream HTTP dependency.
httpCheck('otlp-collector', 'http://collector:4318/healthz', {
kind: 'readiness', // run only under /readyz
}),
],
});
const app = new Elysia().use(await healthPlugin({ checker }));
// GET /healthz → liveness: 200 / 503 with { status, checks, at }
// GET /readyz → readiness: same shape, filtered to readiness + bothWorking example for Body shape.
{
"status": "pass",
"at": 1717161600000,
"checks": {
"queue": {
"status": "pass",
"latencyMs": 1,
"observed": { "runs": 1057, "failed": 0 }
},
"postgres": { "status": "pass", "latencyMs": 12 }
}
}Working example for Kind filtering.
{ name: 'shutting-down', kind: 'readiness', check: () => ({
status: draining ? 'fail' : 'pass'
})}Compose named checks and mount the plugin — two endpoints with a standard envelope, no per-route wiring.
import { Elysia } from 'elysia';
import {
createHealthChecker,
healthPlugin,
metricsCheck,
probeCheck,
httpCheck,
} from '@absolutejs/health';
const checker = createHealthChecker({
checks: [
// Evaluate a metrics() snapshot into pass/warn/fail.
metricsCheck('queue', () => worker.metrics(), (m) => ({
status: m.failed > 100 ? 'warn' : 'pass',
observed: { runs: m.runs, failed: m.failed },
})),
// Wrap an arbitrary probe.
probeCheck('postgres', () => pg.query('SELECT 1')),
// Downstream HTTP dependency, readiness only.
httpCheck('otlp-collector', 'http://collector:4318/healthz', {
kind: 'readiness',
}),
],
});
const app = new Elysia().use(await healthPlugin({ checker }));
// GET /healthz -> liveness: 200 / 503 with { status, checks, at }
// GET /readyz -> readiness: same shape, readiness + both checksA readiness-only check lets an instance drain gracefully: the load balancer stops sending new traffic while in-flight requests finish.
const checker = createHealthChecker({
checks: [
{
name: 'shutting-down',
kind: 'readiness',
check: () => ({ status: draining ? 'fail' : 'pass' }),
},
],
});
// While draining: /readyz -> 503 (LB stops routing),
// /healthz -> 200 (orchestrator does NOT restart the process)Search the declarations exported by the current package type files. Expand a symbol to inspect its source-backed signature.
@absolutejs/health — liveness + readiness probes for the AbsoluteJS substrate. Two endpoints behind one Elysia plugin: - GET /healthz (liveness): is this process alive at all? Used by orchestrators (Kubernetes, systemd, runtime supervisors) to decide when to restart a container. - GET /readyz (readiness): can this instance serve traffic RIGHT NOW? Used by load balancers to decide when to route requests. Returning false while liveness still passes is the "drain me but don't kill me" state. Body s
type HealthStatus = 'pass' | 'warn' | 'fail';@absolutejs/healthCurrent package surface
Import surface · click to copy