feat: observability endpoints

This commit is contained in:
Per Stark
2025-09-06 11:14:24 +02:00
parent 2e076c8236
commit e150b476c3
4 changed files with 45 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
use axum::{http::StatusCode, response::IntoResponse, Json};
use serde_json::json;
/// Liveness probe: always returns 200 to indicate the process is running.
pub async fn live() -> impl IntoResponse {
(StatusCode::OK, Json(json!({"status": "ok"})))
}

View File

@@ -1,2 +1,4 @@
pub mod categories;
pub mod ingress;
pub mod readiness;
pub mod liveness;

View File

@@ -0,0 +1,25 @@
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use serde_json::json;
use crate::api_state::ApiState;
/// Readiness probe: returns 200 if core dependencies are ready, else 503.
pub async fn ready(State(state): State<ApiState>) -> impl IntoResponse {
match state.db.client.query("RETURN true").await {
Ok(_) => (
StatusCode::OK,
Json(json!({
"status": "ok",
"checks": { "db": "ok" }
})),
),
Err(e) => (
StatusCode::SERVICE_UNAVAILABLE,
Json(json!({
"status": "error",
"checks": { "db": "fail" },
"reason": e.to_string()
})),
),
}
}