From 1d29a7065e47c93450c991e6e4d140123ef1cf28 Mon Sep 17 00:00:00 2001 From: Renato Dinhani Date: Fri, 7 Jun 2024 08:49:10 -0300 Subject: [PATCH] feat: track if rpc response returned data --- src/eth/rpc/rpc_middleware.rs | 14 +++++++++++--- src/infra/metrics/metrics_definitions.rs | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/eth/rpc/rpc_middleware.rs b/src/eth/rpc/rpc_middleware.rs index 5db0b5118..124650d67 100644 --- a/src/eth/rpc/rpc_middleware.rs +++ b/src/eth/rpc/rpc_middleware.rs @@ -21,6 +21,7 @@ use crate::eth::primitives::SoliditySignature; use crate::eth::primitives::TransactionInput; use crate::eth::rpc::next_rpc_param; use crate::eth::rpc::parse_rpc_rlp; +use crate::if_else; #[cfg(feature = "metrics")] use crate::infra::metrics; @@ -121,13 +122,15 @@ impl> Future for RpcResponse { let elapsed = proj.start.elapsed(); // trace response + let response_success = response.is_success(); + let response_result = response.as_result(); tracing::info!( id = %proj.id, method = %proj.method, function = %proj.function.clone().unwrap_or_default(), duration_us = %elapsed.as_micros(), - success = %response.is_success(), - result = %response.as_result(), + success = %response_success, + result = %response_result, "rpc response" ); @@ -136,7 +139,12 @@ impl> Future for RpcResponse { { let active = ACTIVE_REQUESTS.fetch_sub(1, Ordering::Relaxed) - 1; metrics::set_rpc_requests_active(active, proj.method.clone(), proj.function.clone()); - metrics::inc_rpc_requests_finished(elapsed, proj.method.clone(), proj.function.clone(), response.is_success()); + + let mut rpc_result = "error"; + if response_success { + rpc_result = if_else!(response_result.contains("\"result\":null"), "missing", "present"); + } + metrics::inc_rpc_requests_finished(elapsed, proj.method.clone(), proj.function.clone(), rpc_result, response.is_success()); } } diff --git a/src/infra/metrics/metrics_definitions.rs b/src/infra/metrics/metrics_definitions.rs index eff4d2a3d..0970ffcad 100644 --- a/src/infra/metrics/metrics_definitions.rs +++ b/src/infra/metrics/metrics_definitions.rs @@ -11,7 +11,7 @@ metrics! { counter rpc_requests_started{method, function} [], "Number of JSON-RPC requests that finished." - histogram_duration rpc_requests_finished{method, function, success} [], + histogram_duration rpc_requests_finished{method, function, result, success} [], "Number of JSON-RPC subscriptions active right now." gauge rpc_subscriptions_active{subscription} []