feat: add /api/v1/health public endpoint
- Add public health routes at /api/v1/health, /api/v1/health/detailed, /api/v1/health/consistency - Make health functions and response types public - Public routes bypass auth middleware (unlike protected /api/v1/* routes)
This commit is contained in:
@@ -52,7 +52,7 @@ pub fn get_uptime_ms() -> u64 {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct HealthResponse {
|
||||
pub struct HealthResponse {
|
||||
ip: String,
|
||||
port: u16,
|
||||
status: String,
|
||||
@@ -68,7 +68,7 @@ struct HealthResponse {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct DetailedHealthResponse {
|
||||
pub struct DetailedHealthResponse {
|
||||
ip: String,
|
||||
port: u16,
|
||||
status: String,
|
||||
@@ -189,7 +189,7 @@ struct ServiceStatus {
|
||||
error: Option<String>,
|
||||
}
|
||||
|
||||
async fn health(State(state): State<AppState>) -> Json<HealthResponse> {
|
||||
pub async fn health(State(state): State<AppState>) -> Json<HealthResponse> {
|
||||
let postgres = check_postgres().await;
|
||||
let redis = check_redis().await;
|
||||
let qdrant = check_qdrant().await;
|
||||
@@ -222,7 +222,7 @@ async fn health(State(state): State<AppState>) -> Json<HealthResponse> {
|
||||
})
|
||||
}
|
||||
|
||||
async fn health_detailed(State(state): State<AppState>) -> Json<DetailedHealthResponse> {
|
||||
pub async fn health_detailed(State(state): State<AppState>) -> Json<DetailedHealthResponse> {
|
||||
let postgres = check_postgres().await;
|
||||
let redis = check_redis().await;
|
||||
let qdrant = check_qdrant().await;
|
||||
@@ -420,7 +420,7 @@ async fn health_detailed(State(state): State<AppState>) -> Json<DetailedHealthRe
|
||||
})
|
||||
}
|
||||
|
||||
async fn health_consistency(
|
||||
pub async fn health_consistency(
|
||||
State(state): State<AppState>,
|
||||
) -> Result<Json<crate::core::health_agent::ConsistencyReport>, (StatusCode, String)> {
|
||||
let report = crate::core::health_agent::run_consistency_checks(&state.db).await;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use axum::Router;
|
||||
use axum::{Json, Router};
|
||||
use serde_json::json;
|
||||
use tokio::time::timeout;
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
|
||||
@@ -15,6 +16,7 @@ use super::checkin_api;
|
||||
use super::docs;
|
||||
use super::files;
|
||||
use super::health;
|
||||
use super::health::{health, health_detailed, health_consistency};
|
||||
use super::identities;
|
||||
use super::identity_agent_api;
|
||||
use super::identity_api;
|
||||
@@ -134,8 +136,14 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
.allow_methods(Any)
|
||||
.allow_headers(Any);
|
||||
|
||||
let public_health_routes = Router::new()
|
||||
.route("/api/v1/health", axum::routing::get(health))
|
||||
.route("/api/v1/health/detailed", axum::routing::get(health_detailed))
|
||||
.route("/api/v1/health/consistency", axum::routing::get(health_consistency));
|
||||
|
||||
let app = Router::new()
|
||||
.merge(auth::auth_routes())
|
||||
.merge(public_health_routes)
|
||||
.merge(health::health_routes())
|
||||
.merge(docs::doc_routes())
|
||||
.merge(protected_routes)
|
||||
|
||||
Reference in New Issue
Block a user