Skip to content

Commit

Permalink
chore: adding batch size metric
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <[email protected]>
  • Loading branch information
Freyskeyd committed Jun 28, 2023
1 parent d755358 commit 7e56620
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/topos-metrics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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!(
Expand Down
3 changes: 3 additions & 0 deletions crates/topos-p2p/src/behaviour/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -149,6 +150,7 @@ impl NetworkBehaviour for Behaviour {
}
}

P2P_GOSSIP_BATCH_SIZE.observe(echos.data.len() as f64);
let msg = bincode::serialize::<Batch>(&echos).expect("msg ser");

_ = self.gossipsub.publish(IdentTopic::new(TOPOS_ECHO), msg);
Expand All @@ -164,6 +166,7 @@ impl NetworkBehaviour for Behaviour {
}
}

P2P_GOSSIP_BATCH_SIZE.observe(readies.data.len() as f64);
let msg = bincode::serialize::<Batch>(&readies).expect("msg ser");

_ = self.gossipsub.publish(IdentTopic::new(TOPOS_READY), msg);
Expand Down

0 comments on commit 7e56620

Please sign in to comment.