use crate::serve::state::ServerState;
use axum::extract::State;
use axum::http::{StatusCode, header};
use axum::response::{IntoResponse, Response};
pub async fn healthz() -> impl IntoResponse {
StatusCode::OK
}
pub async fn readyz(State(state): State<ServerState>) -> impl IntoResponse {
let history_ok = !state.history().degraded();
let queue_ok = !state.registry().is_full();
if history_ok && queue_ok {
StatusCode::OK
} else {
StatusCode::SERVICE_UNAVAILABLE
}
}
pub async fn metrics(State(state): State<ServerState>) -> Response {
match state.render_metrics() {
Some(body) => ([(header::CONTENT_TYPE, "text/plain; version=0.0.4")], body).into_response(),
None => (
StatusCode::SERVICE_UNAVAILABLE,
[(header::CONTENT_TYPE, "text/plain; version=0.0.4")],
"# metrics recorder not installed in this process\n",
)
.into_response(),
}
}