From 7e566201d1c23f033b8e1f08d4dcde59e401b97a Mon Sep 17 00:00:00 2001 From: Simon Paitrault Date: Wed, 28 Jun 2023 10:50:56 +0200 Subject: [PATCH] chore: adding batch size metric Signed-off-by: Simon Paitrault --- crates/topos-metrics/src/lib.rs | 8 +++++++- crates/topos-p2p/src/behaviour/gossip.rs | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/topos-metrics/src/lib.rs b/crates/topos-metrics/src/lib.rs index 7c0ddcf24..ce1df539d 100644 --- a/crates/topos-metrics/src/lib.rs +++ b/crates/topos-metrics/src/lib.rs @@ -1,4 +1,4 @@ -use prometheus::{self, register_int_gauge, IntCounter, IntGauge}; +use prometheus::{self, register_histogram, register_int_gauge, Histogram, IntCounter, IntGauge}; use lazy_static::lazy_static; use prometheus::register_int_counter; @@ -22,6 +22,12 @@ lazy_static! { "Number of gossipsub message sent." ) .unwrap(); + pub static ref P2P_GOSSIP_BATCH_SIZE: Histogram = register_histogram!( + "p2p_gossip_batch_size", + "Number of message sent in a gossip batch.", + vec![1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 20.0] + ).unwrap(); + // Double echo pub static ref DOUBLE_ECHO_BUFFER_CAPACITY: IntCounter = register_int_counter!( diff --git a/crates/topos-p2p/src/behaviour/gossip.rs b/crates/topos-p2p/src/behaviour/gossip.rs index 954b48159..30ea191f0 100644 --- a/crates/topos-p2p/src/behaviour/gossip.rs +++ b/crates/topos-p2p/src/behaviour/gossip.rs @@ -7,6 +7,7 @@ use libp2p::{ swarm::{NetworkBehaviour, THandlerInEvent, ToSwarm}, }; use serde::{Deserialize, Serialize}; +use topos_metrics::P2P_GOSSIP_BATCH_SIZE; use crate::{event::ComposedEvent, TOPOS_ECHO, TOPOS_GOSSIP, TOPOS_READY}; @@ -149,6 +150,7 @@ impl NetworkBehaviour for Behaviour { } } + P2P_GOSSIP_BATCH_SIZE.observe(echos.data.len() as f64); let msg = bincode::serialize::(&echos).expect("msg ser"); _ = self.gossipsub.publish(IdentTopic::new(TOPOS_ECHO), msg); @@ -164,6 +166,7 @@ impl NetworkBehaviour for Behaviour { } } + P2P_GOSSIP_BATCH_SIZE.observe(readies.data.len() as f64); let msg = bincode::serialize::(&readies).expect("msg ser"); _ = self.gossipsub.publish(IdentTopic::new(TOPOS_READY), msg);