feat(O1): instrument ingest handler with Prometheus metrics

- Track ingest requests, errors, auth failures, rate limits, duplicates
- Track bytes ingested, records queued
- In-flight gauge for concurrent ingest jobs
- Timer for ingest duration histogram
- Metrics: I1-I12 (12 metrics instrumented)
This commit is contained in:
2026-09-13 21:36:22 +09:00
parent fd63b089f8
commit 04c28b801d
3 changed files with 76 additions and 2 deletions
+25 -2
View File
@@ -439,29 +439,52 @@ pub async fn ingest_handler(
body: web::Json<IngestRequest>,
state: web::Data<AppState>,
) -> HttpResponse {
use crate::metrics::*;
INGEST_REQUESTS_TOTAL.inc();
INGEST_IN_FLIGHT.inc();
let _timer = Timer::new(&INGEST_DURATION);
// Auth + capability check
let (claims, _token) = match validate_auth(&req, &state).await {
Ok(c) => c,
Err(e) => return e,
Err(e) => {
INGEST_AUTH_FAILURES.inc();
INGEST_ERRORS_TOTAL.inc();
INGEST_IN_FLIGHT.dec();
return e;
}
};
if !has_capability(&claims, "memory:write") {
INGEST_AUTH_FAILURES.inc();
INGEST_ERRORS_TOTAL.inc();
INGEST_IN_FLIGHT.dec();
return HttpResponse::Forbidden().json(json!({
"error": "forbidden",
"reason": "missing capability: memory:write"
}));
}
if let Err(e) = check_rate_limit(&claims, &state, "/memory/ingest") {
INGEST_RATE_LIMITED.inc();
INGEST_IN_FLIGHT.dec();
return e;
}
// Check idempotency
if let Some(cached) = state.idempotency_store.get(&body.ingest_id) {
tracing::info!("Returning cached response for ingest_id: {}", body.ingest_id);
INGEST_DUPLICATES_TOTAL.inc();
INGEST_IN_FLIGHT.dec();
return HttpResponse::Accepted().json(cached);
}
let byte_count: usize = body.records.iter().map(|r| r.text.len()).sum();
INGEST_BYTES_TOTAL.inc_by(byte_count as u64);
INGEST_RECORDS_TOTAL.inc_by(body.records.len() as u64);
// Execute ingest
execute_ingest(&state, &body).await
let resp = execute_ingest(&state, &body).await;
INGEST_IN_FLIGHT.dec();
resp
}
/// Execute ingest job creation and spawn worker