Health checks

ferrite-health gives you a /health endpoint that aggregates indicators — small checks your infrastructure and load balancers can probe. Indicators run in parallel, and the endpoint reports aggregate status.

Enable it

#[module(imports = [HealthModule])]
pub struct AppModule;
curl http://localhost:3000/health
{
  "status": "UP",
  "indicators": {
    "app": { "status": "UP" }
  }
}

The default LivenessIndicator reports the app as up.

Custom indicators

Implement HealthIndicator:

use ferrite_health::{HealthIndicator, Health, HealthResult, submit_indicator};
use ferrite_framework::async_trait;

pub struct CacheHealthIndicator {
    pub key: String,
}

#[async_trait]
impl HealthIndicator for CacheHealthIndicator {
    fn name(&self) -> &'static str {
        "cache"
    }

    async fn check(&self) -> HealthResult {
        match self.client.ping().await {
            Ok(_) => Health::up().finish(),
            Err(err) => Health::down()
                .with_details(serde_json::json!({ "error": err.to_string() }))
                .finish(),
        }
    }
}

Register it with submit_indicator! (the type must be Default):

submit_indicator!(CacheHealthIndicator);

The aggregate body nests each indicator under its name:

{
  "status": "DOWN",
  "indicators": {
    "app": { "status": "UP" },
    "cache": { "status": "DOWN", "details": { "error": "connection refused" } }
  }
}

The Health builder

Health::up().finish();            // HealthResult { UP, details: null }
Health::down().with_details(json).finish();
Health::out_of_service().finish();
Health::unknown().finish();

Statuses serialize as "UP", "DOWN", "OUT_OF_SERVICE", "UNKNOWN".

Behavior

  • Indicators run in parallel (join_all), so slow checks don't serialize.
  • The aggregate is DOWN if any indicator is down.
  • HealthService is an #[injectable]; inject it if you need to report health from tests or dashboards.

Next steps