2026-07-25 15:07:19 +07:00
|
|
|
//! Health check endpoint.
|
|
|
|
|
|
2026-08-03 11:44:21 +07:00
|
|
|
use std::sync::atomic::AtomicU64;
|
|
|
|
|
use std::sync::LazyLock;
|
|
|
|
|
use std::time::Instant;
|
|
|
|
|
|
2026-07-25 15:07:19 +07:00
|
|
|
use axum::Json;
|
|
|
|
|
|
2026-08-03 11:44:21 +07:00
|
|
|
use crate::config::{CONFIG, MODEL_ID};
|
2026-07-25 15:07:19 +07:00
|
|
|
use crate::domain::entity::HealthResponse;
|
|
|
|
|
|
2026-08-03 11:44:21 +07:00
|
|
|
/// Process start instant — used to compute uptime for /health and /metrics.
|
|
|
|
|
pub static START_INSTANT: LazyLock<Instant> = LazyLock::new(Instant::now);
|
|
|
|
|
|
|
|
|
|
/// Process start timestamp (unix seconds) — exported as a Prometheus gauge.
|
|
|
|
|
pub static START_TIMESTAMP: LazyLock<AtomicU64> = LazyLock::new(|| {
|
|
|
|
|
AtomicU64::new(
|
|
|
|
|
std::time::SystemTime::now()
|
|
|
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
|
|
|
.map(|d| d.as_secs())
|
|
|
|
|
.unwrap_or(0),
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/// Seconds since process start.
|
|
|
|
|
pub fn uptime_secs() -> u64 {
|
|
|
|
|
START_INSTANT.elapsed().as_secs()
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-25 15:07:19 +07:00
|
|
|
pub async fn health_check() -> Json<HealthResponse> {
|
|
|
|
|
Json(HealthResponse {
|
|
|
|
|
status: "ok".into(),
|
2026-08-03 08:58:13 +07:00
|
|
|
// Report the exact model id served by /v1/models (no extra suffix).
|
|
|
|
|
model: MODEL_ID.into(),
|
2026-08-03 11:44:21 +07:00
|
|
|
uptime_s: Some(uptime_secs()),
|
|
|
|
|
n_ctx: Some(CONFIG.n_ctx),
|
|
|
|
|
version: Some(env!("CARGO_PKG_VERSION").into()),
|
2026-07-25 15:07:19 +07:00
|
|
|
})
|
|
|
|
|
}
|