From 4a0de3651c848846126ee3b97e785e0549117e46 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 12 Dec 2024 13:58:57 +0530 Subject: [PATCH 1/4] update: fixed analytics --- crates/client/analytics/src/lib.rs | 20 +++++++++++++++++++- crates/client/mempool/src/lib.rs | 2 +- crates/client/mempool/src/metrics.rs | 8 ++++---- crates/node/src/service/rpc/metrics.rs | 10 +++++----- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/crates/client/analytics/src/lib.rs b/crates/client/analytics/src/lib.rs index 45e570d9a..a0cb74d30 100644 --- a/crates/client/analytics/src/lib.rs +++ b/crates/client/analytics/src/lib.rs @@ -1,5 +1,5 @@ use ::time::UtcOffset; -use opentelemetry::metrics::{Counter, Gauge, Histogram, Meter}; +use opentelemetry::metrics::{Counter, Gauge, Histogram, Meter, UpDownCounter}; use opentelemetry::trace::TracerProvider; use opentelemetry::{global, KeyValue}; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; @@ -198,6 +198,24 @@ pub fn register_counter_metric_instrument + Display>( T::register_counter(crate_meter, instrument_name, desc, unit) } +pub trait UpDownCounterType { + fn register_counter(meter: &Meter, name: String, description: String, unit: String) -> UpDownCounter; +} + +impl UpDownCounterType for f64 { + fn register_counter(meter: &Meter, name: String, description: String, unit: String) -> UpDownCounter { + meter.f64_up_down_counter(name).with_description(description).with_unit(unit).init() + } +} +pub fn register_up_down_counter_metric_instrument + Display>( + crate_meter: &Meter, + instrument_name: String, + desc: String, + unit: String, +) -> UpDownCounter { + T::register_counter(crate_meter, instrument_name, desc, unit) +} + pub trait HistogramType { fn register_histogram(meter: &Meter, name: String, description: String, unit: String) -> Histogram; } diff --git a/crates/client/mempool/src/lib.rs b/crates/client/mempool/src/lib.rs index d5bddc425..49828e408 100644 --- a/crates/client/mempool/src/lib.rs +++ b/crates/client/mempool/src/lib.rs @@ -185,7 +185,7 @@ impl Mempool { .expect("Poisoned lock") .insert_tx(MempoolTransaction { tx, arrived_at, converted_class }, force)?; - self.metrics.accepted_transaction_counter.add(1, &[]); + self.metrics.accepted_transaction_counter.add(1.0, &[]); } Ok(()) diff --git a/crates/client/mempool/src/metrics.rs b/crates/client/mempool/src/metrics.rs index 133e4c905..6b517c286 100644 --- a/crates/client/mempool/src/metrics.rs +++ b/crates/client/mempool/src/metrics.rs @@ -1,9 +1,9 @@ -use mc_analytics::register_counter_metric_instrument; -use opentelemetry::metrics::Counter; +use mc_analytics::register_up_down_counter_metric_instrument; +use opentelemetry::metrics::{Counter, UpDownCounter}; use opentelemetry::{global, KeyValue}; pub struct MempoolMetrics { - pub accepted_transaction_counter: Counter, + pub accepted_transaction_counter: UpDownCounter, } impl MempoolMetrics { @@ -17,7 +17,7 @@ impl MempoolMetrics { Some(common_scope_attributes.clone()), ); - let accepted_transaction_counter = register_counter_metric_instrument( + let accepted_transaction_counter = register_up_down_counter_metric_instrument( &mempool_meter, "accepted_transaction_count".to_string(), "A counter to show accepted transactions in the mempool".to_string(), diff --git a/crates/node/src/service/rpc/metrics.rs b/crates/node/src/service/rpc/metrics.rs index 91799172b..10ce49050 100644 --- a/crates/node/src/service/rpc/metrics.rs +++ b/crates/node/src/service/rpc/metrics.rs @@ -91,12 +91,12 @@ impl RpcMetrics { } pub(crate) fn ws_disconnect(&self, now: Instant) { - let micros = now.elapsed().as_secs(); + let millis = now.elapsed().as_millis(); if let Some(counter) = self.ws_sessions_closed.as_ref() { counter.add(1, &[]); } - self.ws_sessions_time.record(micros as f64, &[]); + self.ws_sessions_time.record(millis as f64, &[]); } pub(crate) fn on_call(&self, req: &Request, transport_label: &'static str) { @@ -113,15 +113,15 @@ impl RpcMetrics { tracing::trace!(target: "rpc_metrics", "[{transport_label}] on_response started_at={:?}", now); tracing::trace!(target: "rpc_metrics::extra", "[{transport_label}] result={}", rp.as_result()); - let micros = now.elapsed().as_micros(); + let millis = now.elapsed().as_millis(); tracing::debug!( target: "rpc_metrics", "[{transport_label}] {} call took {} μs", req.method_name(), - micros, + millis, ); - self.calls_time.record(micros as f64, &[KeyValue::new("method", req.method_name().to_string())]); + self.calls_time.record(millis as f64, &[KeyValue::new("method", req.method_name().to_string())]); self.calls_finished.add( 1, From 274b1dff9db4d3fba37eb074f1690397462c72f6 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 12 Dec 2024 14:02:19 +0530 Subject: [PATCH 2/4] update: changelog --- CHANGELOG.md | 1 + crates/client/mempool/src/metrics.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b7908014..5a7a354e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- fix: instrumentation code - feat(block_production): continue pending block on restart - feat(mempool): mempool transaction saving on db - feat(mempool): mempool transaction limits diff --git a/crates/client/mempool/src/metrics.rs b/crates/client/mempool/src/metrics.rs index 6b517c286..86f84f846 100644 --- a/crates/client/mempool/src/metrics.rs +++ b/crates/client/mempool/src/metrics.rs @@ -1,5 +1,5 @@ use mc_analytics::register_up_down_counter_metric_instrument; -use opentelemetry::metrics::{Counter, UpDownCounter}; +use opentelemetry::metrics::UpDownCounter; use opentelemetry::{global, KeyValue}; pub struct MempoolMetrics { From f2f27d2b4dac9e736b1f7d0cf6f5931be4b6faba Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Thu, 19 Dec 2024 15:19:54 +0530 Subject: [PATCH 3/4] update: removed up_down_counter --- crates/client/analytics/src/lib.rs | 20 +------------------- crates/client/mempool/src/lib.rs | 2 +- crates/client/mempool/src/metrics.rs | 8 ++++---- crates/node/src/service/rpc/metrics.rs | 2 +- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/crates/client/analytics/src/lib.rs b/crates/client/analytics/src/lib.rs index dd8dbdc37..b75a90b68 100644 --- a/crates/client/analytics/src/lib.rs +++ b/crates/client/analytics/src/lib.rs @@ -1,5 +1,5 @@ use ::time::UtcOffset; -use opentelemetry::metrics::{Counter, Gauge, Histogram, Meter, UpDownCounter}; +use opentelemetry::metrics::{Counter, Gauge, Histogram, Meter}; use opentelemetry::trace::TracerProvider; use opentelemetry::{global, KeyValue}; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; @@ -196,24 +196,6 @@ pub fn register_counter_metric_instrument + Display>( T::register_counter(crate_meter, instrument_name, desc, unit) } -pub trait UpDownCounterType { - fn register_counter(meter: &Meter, name: String, description: String, unit: String) -> UpDownCounter; -} - -impl UpDownCounterType for f64 { - fn register_counter(meter: &Meter, name: String, description: String, unit: String) -> UpDownCounter { - meter.f64_up_down_counter(name).with_description(description).with_unit(unit).init() - } -} -pub fn register_up_down_counter_metric_instrument + Display>( - crate_meter: &Meter, - instrument_name: String, - desc: String, - unit: String, -) -> UpDownCounter { - T::register_counter(crate_meter, instrument_name, desc, unit) -} - pub trait HistogramType { fn register_histogram(meter: &Meter, name: String, description: String, unit: String) -> Histogram; } diff --git a/crates/client/mempool/src/lib.rs b/crates/client/mempool/src/lib.rs index 6d3578b33..6103be0cd 100644 --- a/crates/client/mempool/src/lib.rs +++ b/crates/client/mempool/src/lib.rs @@ -187,7 +187,7 @@ impl Mempool { true, )?; - self.metrics.accepted_transaction_counter.add(1.0, &[]); + self.metrics.accepted_transaction_counter.add(1, &[]); } Ok(()) diff --git a/crates/client/mempool/src/metrics.rs b/crates/client/mempool/src/metrics.rs index 86f84f846..133e4c905 100644 --- a/crates/client/mempool/src/metrics.rs +++ b/crates/client/mempool/src/metrics.rs @@ -1,9 +1,9 @@ -use mc_analytics::register_up_down_counter_metric_instrument; -use opentelemetry::metrics::UpDownCounter; +use mc_analytics::register_counter_metric_instrument; +use opentelemetry::metrics::Counter; use opentelemetry::{global, KeyValue}; pub struct MempoolMetrics { - pub accepted_transaction_counter: UpDownCounter, + pub accepted_transaction_counter: Counter, } impl MempoolMetrics { @@ -17,7 +17,7 @@ impl MempoolMetrics { Some(common_scope_attributes.clone()), ); - let accepted_transaction_counter = register_up_down_counter_metric_instrument( + let accepted_transaction_counter = register_counter_metric_instrument( &mempool_meter, "accepted_transaction_count".to_string(), "A counter to show accepted transactions in the mempool".to_string(), diff --git a/crates/node/src/service/rpc/metrics.rs b/crates/node/src/service/rpc/metrics.rs index 10ce49050..469b58294 100644 --- a/crates/node/src/service/rpc/metrics.rs +++ b/crates/node/src/service/rpc/metrics.rs @@ -116,7 +116,7 @@ impl RpcMetrics { let millis = now.elapsed().as_millis(); tracing::debug!( target: "rpc_metrics", - "[{transport_label}] {} call took {} μs", + "[{transport_label}] {} call took {} ms", req.method_name(), millis, ); From aa6e5ed7953a5f0a00dc8de04a9c284a29f2b0b8 Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 21 Dec 2024 12:14:59 +0530 Subject: [PATCH 4/4] update: fixed rpc metric log --- crates/node/src/service/rpc/metrics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/node/src/service/rpc/metrics.rs b/crates/node/src/service/rpc/metrics.rs index 469b58294..2f4ae77db 100644 --- a/crates/node/src/service/rpc/metrics.rs +++ b/crates/node/src/service/rpc/metrics.rs @@ -116,7 +116,7 @@ impl RpcMetrics { let millis = now.elapsed().as_millis(); tracing::debug!( target: "rpc_metrics", - "[{transport_label}] {} call took {} ms", + "[{transport_label}] {} call took {:?}", req.method_name(), millis, );