Skip to content

Commit

Permalink
rpc: use full uri path for grpc request metrics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bmwill committed Dec 11, 2024
1 parent 9a50f39 commit 8c594ec
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions crates/sui-rpc-api/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<axum::extract::MatchedPath>() {
Cow::Owned(path.as_str().to_owned())
} else {
Cow::Borrowed("unknown")
};
let path =
if let Some(matched_path) = request.extensions.get::<axum::extract::MatchedPath>() {
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
Expand Down

0 comments on commit 8c594ec

Please sign in to comment.