diff --git a/sgl-model-gateway/src/middleware.rs b/sgl-model-gateway/src/middleware.rs index 75ea2bb703ec..bae4c790e278 100644 --- a/sgl-model-gateway/src/middleware.rs +++ b/sgl-model-gateway/src/middleware.rs @@ -308,6 +308,10 @@ impl OnRequest for RequestLogger { span.record("request_id", request_id.0.as_str()); } + let method = method_to_static_str(request.method().as_str()); + let path = normalize_path_for_metrics(request.uri().path()); + Metrics::record_http_request(method, &path); + // Log the request start info!( target: "sgl_model_gateway::request", @@ -663,9 +667,6 @@ where let response = result?; let duration = start.elapsed(); - let status_class = status_to_class(response.status().as_u16()); - - Metrics::record_http_request(method, &path, status_class); Metrics::record_http_duration(method, &path, duration); Ok(response) @@ -673,18 +674,6 @@ where } } -#[inline] -fn status_to_class(status: u16) -> &'static str { - match status { - 100..=199 => "1xx", - 200..=299 => "2xx", - 300..=399 => "3xx", - 400..=499 => "4xx", - 500..=599 => "5xx", - _ => "unknown", - } -} - /// Normalize path for metrics to avoid high cardinality. /// Replaces dynamic segments (IDs, UUIDs) with `{id}` placeholder. /// Only allocates when normalization is needed; uses single-pass with byte offsets. diff --git a/sgl-model-gateway/src/observability/metrics.rs b/sgl-model-gateway/src/observability/metrics.rs index 6865b939d912..6f3d8d4eb027 100644 --- a/sgl-model-gateway/src/observability/metrics.rs +++ b/sgl-model-gateway/src/observability/metrics.rs @@ -102,7 +102,7 @@ pub fn init_metrics() { // Layer 1: HTTP metrics describe_counter!( "smg_http_requests_total", - "Total HTTP requests by method, path, and status" + "Total HTTP requests by method and path" ); describe_histogram!( "smg_http_request_duration_seconds", @@ -413,14 +413,13 @@ pub struct StreamingMetricsParams<'a> { impl Metrics { /// Record an HTTP request. - /// For best performance, pass static strings (use `method_to_static_str` for method, - /// `status_to_class` for status_class returns static, and cache normalized paths). - pub fn record_http_request(method: &'static str, path: &str, status_class: &'static str) { + /// Here we want a metric to directly reflect user's experience ("I am sending a request") + /// when viewing the router as a blackbox, and is bumped immediately when the request arrives. + pub fn record_http_request(method: &'static str, path: &str) { counter!( "smg_http_requests_total", "method" => method, "path" => path.to_string(), - "status" => status_class ) .increment(1); }