From 8c594ecbdb521dea373c2b836567fe37c1bb3c2a Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 9 Dec 2024 17:14:44 -0600 Subject: [PATCH] rpc: use full uri path for grpc request metrics When calculating the path to use for metrics, use the real path when the CONTENT_TYPE of the request is gRPC in order to get more granular metrics for gRPC services. For all other content types we'll continue to use axum::extract::MatchedPath. --- crates/sui-rpc-api/src/metrics.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/sui-rpc-api/src/metrics.rs b/crates/sui-rpc-api/src/metrics.rs index da8cf85150b81..267c649e151b1 100644 --- a/crates/sui-rpc-api/src/metrics.rs +++ b/crates/sui-rpc-api/src/metrics.rs @@ -68,11 +68,20 @@ impl MakeCallbackHandler for RpcMetricsMakeCallbackHandler { let start = Instant::now(); let metrics = self.metrics.clone(); - let path = if let Some(path) = request.extensions.get::() { - Cow::Owned(path.as_str().to_owned()) - } else { - Cow::Borrowed("unknown") - }; + let path = + if let Some(matched_path) = request.extensions.get::() { + if request + .headers + .get(&http::header::CONTENT_TYPE) + .is_some_and(|header| header == tonic::metadata::GRPC_CONTENT_TYPE) + { + Cow::Owned(request.uri.path().to_owned()) + } else { + Cow::Owned(matched_path.as_str().to_owned()) + } + } else { + Cow::Borrowed("unknown") + }; metrics .inflight_requests