Skip to content
Merged
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
31 changes: 28 additions & 3 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,11 @@ pub async fn start_rpc(
keystore: keystore.clone(),
})
.layer(LogLayer::default())
.layer(MetricsLayer::default())
// `ParallelBatchLayer` has to be the last layer
.layer(ParallelBatchLayer::new(max_response_body_size));
// `ParallelBatchLayer` fans a batch out into per-entry `call`s, so it must be
// outer to `MetricsLayer` for batched methods to be measured. Both must stay
// inner to the batch-transforming layers above.
.layer(ParallelBatchLayer::new(max_response_body_size))
.layer(MetricsLayer::default());
let mut jsonrpsee_svc = svc_builder
.set_rpc_middleware(rpc_middleware)
.build(methods, stop_handle);
Expand Down Expand Up @@ -949,6 +951,29 @@ mod tests {
assert_eq!(batch_response.num_successful_calls(), 2);
assert_eq!(batch_response.num_failed_calls(), 0);

// `eth_chainId` is only ever requested inside the batch above, so its presence in the RPC
// timing metric proves batched methods flow through `MetricsLayer`. Guards against batch
// entries bypassing metrics (which happens if `MetricsLayer` is outer to `ParallelBatchLayer`).
let mut encoded = String::new();
prometheus_client::encoding::text::encode_registry(
&mut encoded,
&crate::metrics::default_registry(),
)
.unwrap();
let recorded = encoded.lines().any(|line| {
line.starts_with("rpc_processing_time_count{")
&& line.contains(r#"method="eth_chainId""#)
&& line
.rsplit(' ')
.next()
.and_then(|v| v.parse::<u64>().ok())
.is_some_and(|count| count == 1)
});
assert!(
recorded,
"batched method `eth_chainId` was not recorded in rpc_processing_time:\n{encoded}"
);
Comment thread
LesnyRumcajs marked this conversation as resolved.

// Gracefully shutdown the RPC server
println!("sending shutdown signal");
shutdown_send.send(()).await.unwrap();
Expand Down
Loading