feat: complete observability stack (O1-O13) #52
@@ -453,7 +453,24 @@ pub async fn start_server(port: u16, api_key: String, database_url: &str) -> Res
|
|||||||
|
|
||||||
/// Health check (no auth)
|
/// Health check (no auth)
|
||||||
pub async fn health_check(state: web::Data<AppState>) -> HttpResponse {
|
pub async fn health_check(state: web::Data<AppState>) -> HttpResponse {
|
||||||
|
use crate::metrics::*;
|
||||||
|
HEALTH_CHECKS_TOTAL.inc();
|
||||||
let uptime = state.start_time.elapsed().as_secs();
|
let uptime = state.start_time.elapsed().as_secs();
|
||||||
|
APP_UPTIME_SECONDS.set(uptime);
|
||||||
|
|
||||||
|
// O7: Check DB dependency
|
||||||
|
let db_start = std::time::Instant::now();
|
||||||
|
match sqlx::query("SELECT 1").execute(&state.pool).await {
|
||||||
|
Ok(_) => {
|
||||||
|
DEP_DB_UP.set(1);
|
||||||
|
DEP_DB_LATENCY.observe(db_start.elapsed().as_secs_f64());
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
DEP_DB_UP.set(0);
|
||||||
|
HEALTH_CHECK_FAILURES.inc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HttpResponse::Ok().json(json!({"status": "ok", "uptime_seconds": uptime}))
|
HttpResponse::Ok().json(json!({"status": "ok", "uptime_seconds": uptime}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user