113 lines
2.6 KiB
Rust
113 lines
2.6 KiB
Rust
pub mod access;
|
|
pub mod agents;
|
|
pub mod auth;
|
|
pub mod auth_profiles;
|
|
pub mod capabilities;
|
|
pub mod imports;
|
|
pub mod observability;
|
|
pub mod onboarding;
|
|
pub mod operations;
|
|
pub mod secrets;
|
|
pub mod upstreams;
|
|
pub mod workspaces;
|
|
|
|
use axum::{Json, extract::State, http::StatusCode, response::IntoResponse};
|
|
use serde_json::json;
|
|
|
|
use crate::state::AppState;
|
|
|
|
pub async fn health() -> Json<serde_json::Value> {
|
|
Json(json!({
|
|
"service": "admin-api",
|
|
"status": "ok"
|
|
}))
|
|
}
|
|
|
|
pub async fn readiness(State(state): State<AppState>) -> impl IntoResponse {
|
|
let checks = state.service.readiness().await;
|
|
let postgres = if checks.postgres {
|
|
"ready"
|
|
} else {
|
|
"not_ready"
|
|
};
|
|
let artifact_storage = if checks.artifact_storage {
|
|
"ready"
|
|
} else {
|
|
"not_ready"
|
|
};
|
|
if checks.is_ready() {
|
|
(
|
|
StatusCode::OK,
|
|
Json(json!({
|
|
"service": "admin-api",
|
|
"status": "ready",
|
|
"checks": { "postgres": postgres, "artifact_storage": artifact_storage }
|
|
})),
|
|
)
|
|
} else {
|
|
(
|
|
StatusCode::SERVICE_UNAVAILABLE,
|
|
Json(json!({
|
|
"service": "admin-api",
|
|
"status": "not_ready",
|
|
"checks": { "postgres": postgres, "artifact_storage": artifact_storage }
|
|
})),
|
|
)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use crate::service::ReadinessChecks;
|
|
|
|
#[test]
|
|
fn readiness_checks_identify_a_postgres_failure() {
|
|
let checks = ReadinessChecks {
|
|
postgres: false,
|
|
artifact_storage: true,
|
|
};
|
|
assert!(!checks.is_ready());
|
|
assert_eq!(
|
|
if checks.postgres {
|
|
"ready"
|
|
} else {
|
|
"not_ready"
|
|
},
|
|
"not_ready"
|
|
);
|
|
assert_eq!(
|
|
if checks.artifact_storage {
|
|
"ready"
|
|
} else {
|
|
"not_ready"
|
|
},
|
|
"ready"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn readiness_checks_identify_an_artifact_storage_failure() {
|
|
let checks = ReadinessChecks {
|
|
postgres: true,
|
|
artifact_storage: false,
|
|
};
|
|
assert!(!checks.is_ready());
|
|
assert_eq!(
|
|
if checks.postgres {
|
|
"ready"
|
|
} else {
|
|
"not_ready"
|
|
},
|
|
"ready"
|
|
);
|
|
assert_eq!(
|
|
if checks.artifact_storage {
|
|
"ready"
|
|
} else {
|
|
"not_ready"
|
|
},
|
|
"not_ready"
|
|
);
|
|
}
|
|
}
|