wsprism_gateway/ops/
mod.rs

1//! Operational HTTP endpoints.
2//!
3//! - `/healthz` : liveness
4//! - `/readyz`  : readiness (503 when draining)
5//! - `/metrics` : Prometheus text format
6
7use axum::{http::StatusCode, response::{IntoResponse, Response}};
8
9use crate::app_state::AppState;
10
11pub async fn healthz() -> impl IntoResponse {
12    (StatusCode::OK, "ok")
13}
14
15pub async fn readyz(axum::extract::State(state): axum::extract::State<AppState>) -> impl IntoResponse {
16    if state.is_draining() {
17        (StatusCode::SERVICE_UNAVAILABLE, "draining")
18    } else {
19        (StatusCode::OK, "ready")
20    }
21}
22
23pub async fn metrics(axum::extract::State(state): axum::extract::State<AppState>) -> Response {
24    let extra = state.metrics_extra();
25    let body = state.metrics().render(&extra);
26
27    (
28        StatusCode::OK,
29        [(axum::http::header::CONTENT_TYPE, "text/plain; version=0.0.4; charset=utf-8")],
30        body,
31    )
32        .into_response()
33}