Skip to content

Commit

Permalink
update: fixed analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Dec 12, 2024
1 parent 031da9e commit 4a0de36
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
20 changes: 19 additions & 1 deletion crates/client/analytics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -198,6 +198,24 @@ pub fn register_counter_metric_instrument<T: CounterType<T> + Display>(
T::register_counter(crate_meter, instrument_name, desc, unit)
}

pub trait UpDownCounterType<T> {
fn register_counter(meter: &Meter, name: String, description: String, unit: String) -> UpDownCounter<T>;
}

impl UpDownCounterType<f64> for f64 {
fn register_counter(meter: &Meter, name: String, description: String, unit: String) -> UpDownCounter<f64> {
meter.f64_up_down_counter(name).with_description(description).with_unit(unit).init()
}
}
pub fn register_up_down_counter_metric_instrument<T: UpDownCounterType<T> + Display>(
crate_meter: &Meter,
instrument_name: String,
desc: String,
unit: String,
) -> UpDownCounter<T> {
T::register_counter(crate_meter, instrument_name, desc, unit)
}

pub trait HistogramType<T> {
fn register_histogram(meter: &Meter, name: String, description: String, unit: String) -> Histogram<T>;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/client/mempool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
8 changes: 4 additions & 4 deletions crates/client/mempool/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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<u64>,
pub accepted_transaction_counter: UpDownCounter<f64>,
}

impl MempoolMetrics {
Expand All @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions crates/node/src/service/rpc/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 4a0de36

Please sign in to comment.