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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user