Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): measure request/call time in seconds #5361

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions crates/rpc/rpc-builder/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ struct RpcServerConnectionMetrics {
requests_started: Counter,
/// The number of requests finished
requests_finished: Counter,
/// Latency for a single request/response pair
request_latency: Histogram,
/// Response for a single request/response pair
request_time_seconds: Histogram,
}

/// Metrics for the RPC calls
#[derive(Metrics, Clone)]
#[metrics(scope = "rpc_server.calls")]
struct RpcServerCallMetrics {
/// The number of calls started
calls_started: Counter,
started: Counter,
/// The number of successful calls
successful_calls: Counter,
successful: Counter,
/// The number of failed calls
failed_calls: Counter,
/// Latency for a single call
call_latency: Histogram,
failed: Counter,
/// Response for a single call
time_seconds: Histogram,
}

impl Logger for RpcServerMetrics {
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Logger for RpcServerMetrics {
_transport: TransportProtocol,
) {
let Some(call_metrics) = self.inner.call_metrics.get(method_name) else { return };
call_metrics.calls_started.increment(1);
call_metrics.started.increment(1);
}

fn on_result(
Expand All @@ -129,18 +129,18 @@ impl Logger for RpcServerMetrics {
let Some(call_metrics) = self.inner.call_metrics.get(method_name) else { return };

// capture call latency
call_metrics.call_latency.record(started_at.elapsed().as_millis() as f64);
call_metrics.time_seconds.record(started_at.elapsed().as_secs_f64());
if success.is_success() {
call_metrics.successful_calls.increment(1);
call_metrics.successful.increment(1);
} else {
call_metrics.failed_calls.increment(1);
call_metrics.failed.increment(1);
}
}

fn on_response(&self, _result: &str, started_at: Self::Instant, transport: TransportProtocol) {
let metrics = self.inner.connection_metrics.get_metrics(transport);
// capture request latency for this request/response pair
metrics.request_latency.record(started_at.elapsed().as_millis() as f64);
metrics.request_time_seconds.record(started_at.elapsed().as_secs_f64());
metrics.requests_finished.increment(1);
}

Expand Down
Loading
Loading