Skip to content

Commit

Permalink
fix: fixing wrong use of IntCounterVec (#442)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <simon.paitrault@gmail.com>
  • Loading branch information
Freyskeyd authored Jan 29, 2024
1 parent 6c7e342 commit fe062a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crates/topos-metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
4 changes: 2 additions & 2 deletions crates/topos-metrics/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ 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();
pub static ref P2P_MESSAGE_SERIALIZE_FAILURE_TOTAL: IntCounterVec =
register_int_counter_vec_with_registry!(
"p2p_message_serialize_failure_total",
"Number of message serialization failure.",
&["echo", "ready", "gossip"],
&["topic"],
TOPOS_METRIC_REGISTRY
)
.unwrap();
Expand Down
21 changes: 21 additions & 0 deletions crates/topos-metrics/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit fe062a5

Please sign in to comment.