Tiny add e2e http request arrival metric (#14893)

This commit is contained in:
fzyzcjy
2025-12-12 13:18:23 +08:00
committed by GitHub
parent b2b5bdb06e
commit b47adb807e
2 changed files with 16 additions and 0 deletions
+2
View File
@@ -307,6 +307,8 @@ impl<B> OnRequest<B> 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",
@@ -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()