From b47adb807e6d01c1f5f844d67e83686b85c49818 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Fri, 12 Dec 2025 13:18:23 +0800 Subject: [PATCH] Tiny add e2e http request arrival metric (#14893) --- sgl-model-gateway/src/middleware.rs | 2 ++ sgl-model-gateway/src/observability/metrics.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/sgl-model-gateway/src/middleware.rs b/sgl-model-gateway/src/middleware.rs index 6b61a1482..159458db3 100644 --- a/sgl-model-gateway/src/middleware.rs +++ b/sgl-model-gateway/src/middleware.rs @@ -307,6 +307,8 @@ impl OnRequest for RequestLogger { span.record("request_id", request_id.0.as_str()); } + RouterMetrics::record_http_request(); + // Log the request start info!( target: "sgl_model_gateway::request", diff --git a/sgl-model-gateway/src/observability/metrics.rs b/sgl-model-gateway/src/observability/metrics.rs index 49cd8c3c6..c8be8a1e7 100644 --- a/sgl-model-gateway/src/observability/metrics.rs +++ b/sgl-model-gateway/src/observability/metrics.rs @@ -270,6 +270,10 @@ pub fn init_metrics() { "Time to load and initialize tokenizer" ); + describe_counter!( + "sgl_router_http_requests_total", + "Total number of HTTP requests" + ); describe_counter!( "sgl_router_http_responses_total", "Total number of HTTP responses by status code" @@ -589,6 +593,16 @@ impl RouterMetrics { counter!("sgl_router_job_shutdown_rejected_total").increment(1); } + // This is different from the following: + // * sgl_router_requests_total: bump when a request is handled and response is to be returned, thus very different from this. + // * sgl_router_processed_requests_total: bump when routing decision is made. + // 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. + // TODO: add route name + pub fn record_http_request() { + counter!("sgl_router_http_requests_total").increment(1); + } + pub fn record_http_status_code(status_code: u16) { counter!("sgl_router_http_responses_total", "status_code" => status_code.to_string()