Skip to main content

o_sfu/runtime/http_server/
request_metrics.rs

1//! Control request counters and in-flight gauges.
2//!
3//! Request tracking wraps authorization and extraction to include rejected requests
4//! and unsupported methods. Diagnostics paths are excluded from these counters.
5
6use std::sync::Arc;
7
8use axum::{
9    extract::{MatchedPath, Request, State},
10    middleware::Next,
11    response::Response,
12};
13
14use super::contract::route;
15use crate::runtime::metrics::{HttpRoute, RuntimeMetrics};
16
17pub(super) async fn track_request(
18    State(metrics): State<Arc<RuntimeMetrics>>,
19    path: MatchedPath,
20    request: Request,
21    next: Next,
22) -> Response {
23    let route = match path.as_str() {
24        route::v1::NOOP => HttpRoute::Noop,
25        route::v1::STATS => HttpRoute::Stats,
26        route::v1::CHANNEL => HttpRoute::Room,
27        route::v1::DISCONNECT => HttpRoute::Disconnect,
28        route::METRICS => HttpRoute::Metrics,
29        _ => return next.run(request).await,
30    };
31    let _guard = metrics.track_http_request(route);
32    next.run(request).await
33}