From 7ac43b985b11826c5f2eaacc39e0e814e0caf30a Mon Sep 17 00:00:00 2001 From: psteinroe Date: Tue, 6 Jan 2026 11:28:55 +0100 Subject: [PATCH 1/2] chore: cleanup metrics --- src/metrics/failover.rs | 38 ++++++-------------------------------- src/stream.rs | 5 +++-- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/metrics/failover.rs b/src/metrics/failover.rs index 332405a..ec1ca17 100644 --- a/src/metrics/failover.rs +++ b/src/metrics/failover.rs @@ -1,5 +1,5 @@ use metrics::{ - Unit, counter, describe_counter, describe_gauge, describe_histogram, gauge, histogram, + Unit, describe_gauge, describe_histogram, gauge, histogram, }; /// Metric name for tracking if a stream is currently in failover mode. @@ -7,14 +7,8 @@ use metrics::{ /// This gauge is set to 1 when the stream is in failover mode and 0 otherwise. const STREAM_FAILOVER_ACTIVE: &str = "stream_failover_active"; -/// Metric name for counting the total number of times a stream has entered failover mode. -const STREAM_FAILOVER_ENTERED_TOTAL: &str = "stream_failover_entered_total"; - -/// Metric name for counting the total number of times a stream has successfully recovered from failover. -const STREAM_FAILOVER_RECOVERED_TOTAL: &str = "stream_failover_recovered_total"; - /// Metric name for recording the time spent in failover mode. -const STREAM_FAILOVER_DURATION_SECONDS: &str = "stream_failover_duration_seconds"; +const STREAM_FAILOVER_DURATION_MILLISECONDS: &str = "stream_failover_duration_milliseconds"; /// Label key for stream identifier. const STREAM_ID_LABEL: &str = "stream_id"; @@ -26,18 +20,8 @@ pub(crate) fn register_failover_metrics() { Unit::Count, "Whether the stream is currently in failover mode (1 = failover, 0 = healthy)" ); - describe_counter!( - STREAM_FAILOVER_ENTERED_TOTAL, - Unit::Count, - "Total number of times the stream has entered failover mode" - ); - describe_counter!( - STREAM_FAILOVER_RECOVERED_TOTAL, - Unit::Count, - "Total number of times the stream has successfully recovered from failover" - ); describe_histogram!( - STREAM_FAILOVER_DURATION_SECONDS, + STREAM_FAILOVER_DURATION_MILLISECONDS, Unit::Seconds, "Time spent in failover mode before recovery" ); @@ -45,11 +29,6 @@ pub(crate) fn register_failover_metrics() { /// Records that the stream has entered failover mode. pub fn record_failover_entered(stream_id: u64) { - counter!( - STREAM_FAILOVER_ENTERED_TOTAL, - STREAM_ID_LABEL => stream_id.to_string() - ) - .increment(1); gauge!( STREAM_FAILOVER_ACTIVE, STREAM_ID_LABEL => stream_id.to_string() @@ -58,20 +37,15 @@ pub fn record_failover_entered(stream_id: u64) { } /// Records that the stream has recovered from failover mode. -pub fn record_failover_recovered(stream_id: u64, duration_seconds: f64) { - counter!( - STREAM_FAILOVER_RECOVERED_TOTAL, - STREAM_ID_LABEL => stream_id.to_string() - ) - .increment(1); +pub fn record_failover_recovered(stream_id: u64, duration_milliseconds: f64) { gauge!( STREAM_FAILOVER_ACTIVE, STREAM_ID_LABEL => stream_id.to_string() ) .set(0.0); histogram!( - STREAM_FAILOVER_DURATION_SECONDS, + STREAM_FAILOVER_DURATION_MILLISECONDS, STREAM_ID_LABEL => stream_id.to_string() ) - .record(duration_seconds); + .record(duration_milliseconds); } diff --git a/src/stream.rs b/src/stream.rs index 22abaec..13e0604 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -223,8 +223,9 @@ where } // Record successful failover recovery - let failover_duration_seconds = (Utc::now() - failover_start).num_seconds() as f64; - metrics::record_failover_recovered(self.config.id, failover_duration_seconds); + let failover_duration_milliseconds = + (Utc::now() - failover_start).num_milliseconds() as f64; + metrics::record_failover_recovered(self.config.id, failover_duration_milliseconds); self.store .store_stream_status(StreamStatus::Healthy) From 0c3917cb7c380f66c55fde6e9164c4836b9fa4f4 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Tue, 6 Jan 2026 12:00:56 +0100 Subject: [PATCH 2/2] fix: format --- src/metrics/failover.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/metrics/failover.rs b/src/metrics/failover.rs index ec1ca17..d52ac4d 100644 --- a/src/metrics/failover.rs +++ b/src/metrics/failover.rs @@ -1,6 +1,4 @@ -use metrics::{ - Unit, describe_gauge, describe_histogram, gauge, histogram, -}; +use metrics::{Unit, describe_gauge, describe_histogram, gauge, histogram}; /// Metric name for tracking if a stream is currently in failover mode. ///