Health Module¶
forge.health — Kubernetes-compatible /health and /ready endpoints with
custom check registration.
Overview¶
The Health module provides standardized health and readiness checking that works
with Kubernetes liveness and readiness probes out of the box. Every registered
module automatically contributes its health_check() method. Custom checks can be
added with a simple decorator.
Installation¶
Quick Start¶
from forge.health import HealthModule, health_router
# Mount in your FastAPI app
app.mount("/health", health_router)
Built-in behavior:
| Endpoint | Purpose | Failure Behavior |
|---|---|---|
/health (liveness) |
Is the process alive? | Kubernetes restarts the pod |
/ready (readiness) |
Can the process serve traffic? | Kubernetes stops sending traffic |
Key Features¶
Custom Health Checks¶
from forge.health import check, HealthResult
@check("database")
async def check_database():
if await db.is_connected():
return HealthResult.ok()
return HealthResult.error("Database connection lost")
@check("cache")
async def check_cache():
if cache.latency_ms > 100:
return HealthResult.degraded("Cache latency high")
return HealthResult.ok()
Module-Level Health¶
Every ForgeModule can implement a health_check() method that is automatically
registered:
class MyModule(ForgeModule):
name = "my_module"
async def health_check(self) -> HealthResult:
if self.is_healthy():
return HealthResult.ok()
return HealthResult.error("Module unhealthy")
Check Timeout¶
Each health check runs with a configurable timeout to prevent hanging probes:
API Reference¶
Health check module — standardized /health and /ready endpoints.
Provides a health check registry, built-in checks for module dependencies, and FastAPI routers for /health (liveness) and /ready (readiness) endpoints compatible with Kubernetes probes.
Classes¶
HealthModule ¶
Manages health and readiness checks for the forge runtime.
Integrates with K8s probes and coordinates module-level checks.
Attributes¶
include_details
property
¶
Dynamically determine if check details should be included in responses.
Methods:¶
check ¶
Decorator to register a custom health check function.
check_all
async
¶
Run all registered checks and return results.
Returns dict of check_name -> {status, message, latency_ms}
is_ready ¶
Determine overall readiness.
Returns False if any critical check fails (status is error).
register ¶
Register a custom health check.
setup
async
¶
Initialize the health module and configure settings.
HealthRegistry ¶
HealthResult
dataclass
¶
Functions:¶
check ¶
Decorator to register a custom health check.