From harness-claude
Implements /health/live (liveness), /health/ready (readiness), and /health/startup endpoints with component checks for dependencies. For Kubernetes probes, load balancers, monitoring, and graceful shutdown.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Implement health check endpoints for service readiness, liveness, and dependency monitoring
Implements liveness, readiness, startup, and deep health check endpoints with dependency monitoring. Use for Kubernetes probes, load balancers, auto-scaling, or fixing probe failures and startup delays.
Implements /health (liveness) and /ready (readiness) endpoints for containerized microservices in Kubernetes/ECS. Express.js TypeScript example checks Prisma DB, Redis, and external services.
Implements liveness, readiness, and dependency health check endpoints for services. Use for Kubernetes probes, load balancers, and monitoring in Express, Spring Boot, Flask.
Share bugs, ideas, or general feedback.
Implement health check endpoints for service readiness, liveness, and dependency monitoring
/health/live (liveness), /health/ready (readiness), /health/startup (startup).// health/health-controller.ts
interface HealthComponent {
name: string;
status: 'up' | 'down' | 'degraded';
latency?: number;
details?: string;
}
interface HealthResponse {
status: 'healthy' | 'unhealthy' | 'degraded';
uptime: number;
timestamp: string;
components: HealthComponent[];
}
export class HealthChecker {
private ready = false;
private shuttingDown = false;
private startTime = Date.now();
private checks: Array<{ name: string; check: () => Promise<HealthComponent> }> = [];
registerCheck(name: string, check: () => Promise<HealthComponent>) {
this.checks.push({ name, check });
}
setReady(ready: boolean) {
this.ready = ready;
}
setShuttingDown() {
this.shuttingDown = true;
this.ready = false;
}
async liveness(): Promise<{ status: number; body: object }> {
return {
status: 200,
body: { status: 'alive', uptime: Date.now() - this.startTime },
};
}
async readiness(): Promise<{ status: number; body: HealthResponse }> {
if (this.shuttingDown || !this.ready) {
return {
status: 503,
body: {
status: 'unhealthy',
uptime: Date.now() - this.startTime,
timestamp: new Date().toISOString(),
components: [
{
name: 'server',
status: 'down',
details: this.shuttingDown ? 'shutting down' : 'not ready',
},
],
},
};
}
const components = await Promise.all(
this.checks.map(async ({ name, check }) => {
try {
return await check();
} catch (err) {
return { name, status: 'down' as const, details: String(err) };
}
})
);
const allUp = components.every((c) => c.status === 'up');
const anyDown = components.some((c) => c.status === 'down');
return {
status: anyDown ? 503 : 200,
body: {
status: anyDown ? 'unhealthy' : allUp ? 'healthy' : 'degraded',
uptime: Date.now() - this.startTime,
timestamp: new Date().toISOString(),
components,
},
};
}
}
// Registering checks
const health = new HealthChecker();
health.registerCheck('database', async () => {
const start = Date.now();
await pool.query('SELECT 1');
return { name: 'database', status: 'up', latency: Date.now() - start };
});
health.registerCheck('redis', async () => {
const start = Date.now();
await redis.ping();
return { name: 'redis', status: 'up', latency: Date.now() - start };
});
// Graceful shutdown
process.on('SIGTERM', () => {
health.setShuttingDown();
// Allow in-flight requests to complete
setTimeout(() => process.exit(0), 30000);
});
Kubernetes probe configuration:
livenessProbe:
httpGet: { path: /health/live, port: 3000 }
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 3 # Restart after 3 failures
readinessProbe:
httpGet: { path: /health/ready, port: 3000 }
periodSeconds: 5
failureThreshold: 2 # Remove from service after 2 failures
startupProbe:
httpGet: { path: /health/startup, port: 3000 }
periodSeconds: 5
failureThreshold: 30 # Allow up to 150s for startup
Liveness vs readiness: Liveness failure triggers a pod restart. Readiness failure removes the pod from the service endpoint (no traffic routed to it). Making liveness too strict causes unnecessary restarts. Making readiness too lenient routes traffic to broken instances.
Health check anti-patterns: