Skip to content

Commit 0581c97

Browse files
fzyzcjyJustinTong0323
authored andcommitted
Tiny support sgl-router http response status code metrics (sgl-project#14689)
1 parent 2cf7d1e commit 0581c97

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

sgl-model-gateway/src/middleware.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,12 @@ impl Default for ResponseLogger {
332332
impl<B> OnResponse<B> for ResponseLogger {
333333
fn on_response(self, response: &Response<B>, latency: Duration, span: &Span) {
334334
let status = response.status();
335+
let status_code = status.as_u16();
336+
337+
RouterMetrics::record_http_status_code(status_code);
335338

336339
// Record these in the span for structured logging/observability tools
337-
span.record("status_code", status.as_u16());
340+
span.record("status_code", status_code);
338341
// Use microseconds as integer to avoid format! string allocation
339342
span.record("latency", latency.as_micros() as u64);
340343

sgl-model-gateway/src/observability/metrics.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ pub fn init_metrics() {
263263
"sgl_tokenizer_factory_load_duration_seconds",
264264
"Time to load and initialize tokenizer"
265265
);
266+
267+
describe_counter!(
268+
"sgl_router_http_responses_total",
269+
"Total number of HTTP responses by status code"
270+
);
266271
}
267272

268273
pub fn start_prometheus(config: PrometheusConfig) {
@@ -563,6 +568,13 @@ impl RouterMetrics {
563568
pub fn record_job_shutdown_rejected() {
564569
counter!("sgl_router_job_shutdown_rejected_total").increment(1);
565570
}
571+
572+
pub fn record_http_status_code(status_code: u16) {
573+
counter!("sgl_router_http_responses_total",
574+
"status_code" => status_code.to_string()
575+
)
576+
.increment(1);
577+
}
566578
}
567579

568580
impl TokenizerMetrics {

0 commit comments

Comments
 (0)