- Fix all 106 warnings: unused imports, dead struct fields (_prefix), dead_code annotations on bin-only items in ingest_worker.rs - Add GET /ready endpoint (readiness probe, checks DB) - Keep GET /health lightweight (liveness, no DB check) - Add ServiceMonitor for Prometheus scraping - Add tracing-subscriber json feature for structured logs - 760 tests passing, 0 warnings, 0 errors
This commit is contained in:
@@ -46,8 +46,8 @@ pub struct IngestRecord {
|
||||
}
|
||||
// RBAC removed for MVP - will add after core ingest/query working
|
||||
use crate::handlers::{
|
||||
QueryParams, QueryParamsError, SearchMethod, build_search_response,
|
||||
LearnParams, LearnParamsError, build_learn_response,
|
||||
QueryParams,
|
||||
LearnParams, build_learn_response,
|
||||
visualize_handler, visualize_stream_handler, compact_handler
|
||||
};
|
||||
|
||||
@@ -182,6 +182,7 @@ fn has_capability(claims: &JwtClaims, required_capability: &str) -> bool {
|
||||
}
|
||||
|
||||
/// Extract client identifier from claims for rate limiting
|
||||
#[allow(dead_code)]
|
||||
fn extract_rate_limit_key(claims: &JwtClaims) -> String {
|
||||
// Use subject (user/service ID) as rate limit key
|
||||
claims.sub.clone()
|
||||
@@ -291,6 +292,7 @@ pub async fn start_server(port: u16, api_key: String, database_url: &str) -> Res
|
||||
.app_data(state.clone())
|
||||
.wrap(Logger::default())
|
||||
.route("/health", web::get().to(health_check))
|
||||
.route("/ready", web::get().to(readiness_check))
|
||||
.route("/metrics", web::get().to(crate::metrics::metrics_handler))
|
||||
.route("/memory/ingest", web::post().to(ingest_handler))
|
||||
.route("/memory/ingest/{ingest_id}", web::get().to(ingest_status))
|
||||
@@ -362,6 +364,24 @@ pub async fn health_check(state: web::Data<AppState>) -> HttpResponse {
|
||||
HttpResponse::Ok().json(json!({"status": "ok", "uptime_seconds": uptime}))
|
||||
}
|
||||
|
||||
/// GET /ready — readiness probe (checks DB)
|
||||
pub async fn readiness_check(state: web::Data<AppState>) -> HttpResponse {
|
||||
let uptime = state.start_time.elapsed().as_secs();
|
||||
let db_start = std::time::Instant::now();
|
||||
match sqlx::query("SELECT 1").execute(&state.pool).await {
|
||||
Ok(_) => {
|
||||
crate::metrics::DEP_DB_UP.set(1);
|
||||
crate::metrics::DEP_DB_LATENCY.observe(db_start.elapsed().as_secs_f64());
|
||||
HttpResponse::Ok().json(json!({"status": "ready", "uptime_seconds": uptime, "db": "ok"}))
|
||||
}
|
||||
Err(e) => {
|
||||
crate::metrics::DEP_DB_UP.set(0);
|
||||
crate::metrics::HEALTH_CHECK_FAILURES.inc();
|
||||
HttpResponse::ServiceUnavailable().json(json!({"status": "not_ready", "uptime_seconds": uptime, "db": format!("error: {}", e)}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// POST /memory/ingest — queue an ingest job
|
||||
pub async fn ingest_handler(
|
||||
req: HttpRequest,
|
||||
@@ -385,7 +405,7 @@ pub async fn ingest_handler(
|
||||
}
|
||||
};
|
||||
|
||||
let user_id = &claims.sub;
|
||||
let _user_id = &claims.sub;
|
||||
if !has_capability(&claims, "memory:write") {
|
||||
INGEST_AUTH_FAILURES.inc();
|
||||
INGEST_ERRORS_TOTAL.inc();
|
||||
@@ -1008,7 +1028,7 @@ pub async fn vault_browser_handler(
|
||||
/// Helper: Build file tree for a project
|
||||
async fn vault_project_tree(
|
||||
project: &str,
|
||||
state: &web::Data<AppState>,
|
||||
_state: &web::Data<AppState>,
|
||||
) -> HttpResponse {
|
||||
let vault_dir = std::env::var("MEM_HOME").unwrap_or_else(|_| "/data".to_string());
|
||||
let project_path = format!("{}/vault/{}", vault_dir, project);
|
||||
|
||||
Reference in New Issue
Block a user