From fe062a5bdfa9ade2b94de88cbd6b3946b72a94c3 Mon Sep 17 00:00:00 2001 From: Simon Paitrault Date: Mon, 29 Jan 2024 15:12:22 +0100 Subject: [PATCH] fix: fixing wrong use of IntCounterVec (#442) Signed-off-by: Simon Paitrault --- crates/topos-metrics/src/lib.rs | 3 +++ crates/topos-metrics/src/p2p.rs | 4 ++-- crates/topos-metrics/src/tests.rs | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 crates/topos-metrics/src/tests.rs diff --git a/crates/topos-metrics/src/lib.rs b/crates/topos-metrics/src/lib.rs index f935b8b6b..2628d8e0f 100644 --- a/crates/topos-metrics/src/lib.rs +++ b/crates/topos-metrics/src/lib.rs @@ -11,6 +11,9 @@ mod double_echo; mod p2p; mod storage; +#[cfg(test)] +mod tests; + pub use api::*; pub use double_echo::*; pub use p2p::*; diff --git a/crates/topos-metrics/src/p2p.rs b/crates/topos-metrics/src/p2p.rs index e7ee8561d..77fa99ac9 100644 --- a/crates/topos-metrics/src/p2p.rs +++ b/crates/topos-metrics/src/p2p.rs @@ -61,7 +61,7 @@ lazy_static! { register_int_counter_vec_with_registry!( "p2p_message_deserialize_failure_total", "Number of message deserialization failure.", - &["echo", "ready", "gossip"], + &["topic"], TOPOS_METRIC_REGISTRY ) .unwrap(); @@ -69,7 +69,7 @@ lazy_static! { register_int_counter_vec_with_registry!( "p2p_message_serialize_failure_total", "Number of message serialization failure.", - &["echo", "ready", "gossip"], + &["topic"], TOPOS_METRIC_REGISTRY ) .unwrap(); diff --git a/crates/topos-metrics/src/tests.rs b/crates/topos-metrics/src/tests.rs new file mode 100644 index 000000000..d3c63f432 --- /dev/null +++ b/crates/topos-metrics/src/tests.rs @@ -0,0 +1,21 @@ +use crate::p2p; + +#[test] +fn increment_echo_failure_ser() { + let m = &p2p::P2P_MESSAGE_SERIALIZE_FAILURE_TOTAL; + + m.with_label_values(&["echo"]).inc(); + + assert_eq!(m.get_metric_with_label_values(&["echo"]).unwrap().get(), 1); + assert_eq!(m.get_metric_with_label_values(&["ready"]).unwrap().get(), 0); +} + +#[test] +fn increment_echo_failure_des() { + let m = &p2p::P2P_MESSAGE_DESERIALIZE_FAILURE_TOTAL; + + m.with_label_values(&["echo"]).inc(); + + assert_eq!(m.get_metric_with_label_values(&["echo"]).unwrap().get(), 1); + assert_eq!(m.get_metric_with_label_values(&["ready"]).unwrap().get(), 0); +}