diff --git a/sgl-model-gateway/src/observability/metrics.rs b/sgl-model-gateway/src/observability/metrics.rs index 2fa4fcb6641b..ae1bbefb62cf 100644 --- a/sgl-model-gateway/src/observability/metrics.rs +++ b/sgl-model-gateway/src/observability/metrics.rs @@ -34,6 +34,10 @@ pub fn init_metrics() { "sgl_router_request_errors_total", "Total number of request errors by route and error type" ); + describe_counter!( + "sgl_router_upstream_http_responses_total", + "Total number of upstream engine HTTP responses by status code" + ); describe_counter!( "sgl_router_retries_total", "Total number of request retries by route" @@ -321,6 +325,15 @@ impl RouterMetrics { .increment(1); } + // TODO unify metric names + pub fn record_upstream_http_response(route: &str, status_code: u16) { + counter!("sgl_router_upstream_http_responses_total", + "route" => route.to_string(), + "status_code" => status_code.to_string() + ) + .increment(1); + } + pub fn record_retry(route: &str) { counter!("sgl_router_retries_total", "route" => route.to_string() diff --git a/sgl-model-gateway/src/routers/http/router.rs b/sgl-model-gateway/src/routers/http/router.rs index 7aad2c3f7229..73b049abf736 100644 --- a/sgl-model-gateway/src/routers/http/router.rs +++ b/sgl-model-gateway/src/routers/http/router.rs @@ -531,6 +531,8 @@ impl Router { } }; + RouterMetrics::record_upstream_http_response(route, res.status().as_u16()); + let status = StatusCode::from_u16(res.status().as_u16()) .unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);