mirror of
https://github.com/perstarkse/minne.git
synced 2026-07-08 13:55:23 +02:00
feat: observability endpoints
This commit is contained in:
+11
-3
@@ -6,7 +6,7 @@ use axum::{
|
|||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use middleware_api_auth::api_auth;
|
use middleware_api_auth::api_auth;
|
||||||
use routes::{categories::get_categories, ingress::ingest_data};
|
use routes::{categories::get_categories, ingress::ingest_data, liveness::live, readiness::ready};
|
||||||
|
|
||||||
pub mod api_state;
|
pub mod api_state;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
@@ -19,9 +19,17 @@ where
|
|||||||
S: Clone + Send + Sync + 'static,
|
S: Clone + Send + Sync + 'static,
|
||||||
ApiState: FromRef<S>,
|
ApiState: FromRef<S>,
|
||||||
{
|
{
|
||||||
Router::new()
|
// Public, unauthenticated endpoints (for k8s/systemd probes)
|
||||||
|
let public = Router::new()
|
||||||
|
.route("/ready", get(ready))
|
||||||
|
.route("/live", get(live));
|
||||||
|
|
||||||
|
// Protected API endpoints (require auth)
|
||||||
|
let protected = Router::new()
|
||||||
.route("/ingress", post(ingest_data))
|
.route("/ingress", post(ingest_data))
|
||||||
.route("/categories", get(get_categories))
|
.route("/categories", get(get_categories))
|
||||||
.layer(DefaultBodyLimit::max(1024 * 1024 * 1024))
|
.layer(DefaultBodyLimit::max(1024 * 1024 * 1024))
|
||||||
.route_layer(from_fn_with_state(app_state.clone(), api_auth))
|
.route_layer(from_fn_with_state(app_state.clone(), api_auth));
|
||||||
|
|
||||||
|
public.merge(protected)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
use axum::{http::StatusCode, response::IntoResponse, Json};
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
/// Liveness probe: always returns 200 to indicate the process is running.
|
||||||
|
pub async fn live() -> impl IntoResponse {
|
||||||
|
(StatusCode::OK, Json(json!({"status": "ok"})))
|
||||||
|
}
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
pub mod categories;
|
pub mod categories;
|
||||||
pub mod ingress;
|
pub mod ingress;
|
||||||
|
pub mod readiness;
|
||||||
|
pub mod liveness;
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
use crate::api_state::ApiState;
|
||||||
|
|
||||||
|
/// Readiness probe: returns 200 if core dependencies are ready, else 503.
|
||||||
|
pub async fn ready(State(state): State<ApiState>) -> impl IntoResponse {
|
||||||
|
match state.db.client.query("RETURN true").await {
|
||||||
|
Ok(_) => (
|
||||||
|
StatusCode::OK,
|
||||||
|
Json(json!({
|
||||||
|
"status": "ok",
|
||||||
|
"checks": { "db": "ok" }
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
Err(e) => (
|
||||||
|
StatusCode::SERVICE_UNAVAILABLE,
|
||||||
|
Json(json!({
|
||||||
|
"status": "error",
|
||||||
|
"checks": { "db": "fail" },
|
||||||
|
"reason": e.to_string()
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user