From da0b20e5b282beadfb0bea9a1d10d73481630228 Mon Sep 17 00:00:00 2001 From: Simon Paitrault Date: Tue, 27 Jun 2023 16:03:14 +0200 Subject: [PATCH] chore: adding more metrics Signed-off-by: Simon Paitrault --- crates/topos-metrics/src/lib.rs | 25 ++++++++++++++++++- .../src/runtime/handle_event/gossipsub.rs | 2 ++ .../src/double_echo/mod.rs | 10 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/crates/topos-metrics/src/lib.rs b/crates/topos-metrics/src/lib.rs index 89643b982..4e490974c 100644 --- a/crates/topos-metrics/src/lib.rs +++ b/crates/topos-metrics/src/lib.rs @@ -1,9 +1,15 @@ -use prometheus::{self, IntCounter}; +use prometheus::{self, register_int_gauge, IntCounter, IntGauge}; use lazy_static::lazy_static; use prometheus::register_int_counter; lazy_static! { + // p2p + pub static ref P2P_EVENT_STREAM_CAPACITY: IntCounter = register_int_counter!( + "p2p_event_stream_capacity", + "Number of time the p2p event stream was almost at capacity." + ).unwrap(); + pub static ref MESSAGE_RECEIVED_ON_GOSSIP: IntCounter = register_int_counter!("gossip_message_count", "Number of gossip message received.") .unwrap(); @@ -16,6 +22,23 @@ lazy_static! { "Number of gossipsub message sent." ) .unwrap(); + + // Double echo + pub static ref DOUBLE_ECHO_BUFFER_CAPACITY: IntCounter = register_int_counter!( + "double_echo_buffer_capacity", + "Number of time the double echo buffer was at capacity." + ).unwrap(); + pub static ref DOUBLE_ECHO_CURRENT_BUFFER_SIZE: IntGauge = register_int_gauge!( + "double_echo_current_buffer_size", + "Current size of the double echo buffer." + ).unwrap(); + + pub static ref DOUBLE_ECHO_BUFFERED_MESSAGE_COUNT: IntGauge = register_int_gauge!( + "double_echo_buffered_message_count", + "Number of message buffered in the double echo buffer." + ).unwrap(); + + pub static ref CERTIFICATE_RECEIVED: IntCounter = register_int_counter!("certificate_received", "Number of certificate received.").unwrap(); pub static ref CERTIFICATE_RECEIVED_FROM_GOSSIP: IntCounter = register_int_counter!( diff --git a/crates/topos-p2p/src/runtime/handle_event/gossipsub.rs b/crates/topos-p2p/src/runtime/handle_event/gossipsub.rs index 5270767a7..72a2ae6e2 100644 --- a/crates/topos-p2p/src/runtime/handle_event/gossipsub.rs +++ b/crates/topos-p2p/src/runtime/handle_event/gossipsub.rs @@ -1,6 +1,7 @@ use libp2p::gossipsub::{Event as GossipsubEvent, Message}; use topos_metrics::{ MESSAGE_RECEIVED_ON_ECHO, MESSAGE_RECEIVED_ON_GOSSIP, MESSAGE_RECEIVED_ON_READY, + P2P_EVENT_STREAM_CAPACITY, }; use tracing::{error, info}; @@ -22,6 +23,7 @@ impl EventHandler for Runtime { { if self.event_sender.capacity() >= *constant::CAPACITY_EVENT_STREAM_BUFFER { tracing::error!("P2P Event sender is almost full, dropping event"); + P2P_EVENT_STREAM_CAPACITY.inc(); } info!("Received message from {:?} on topic {:?}", source, topic); diff --git a/crates/topos-tce-broadcast/src/double_echo/mod.rs b/crates/topos-tce-broadcast/src/double_echo/mod.rs index f15b55049..0fbcb4a7a 100644 --- a/crates/topos-tce-broadcast/src/double_echo/mod.rs +++ b/crates/topos-tce-broadcast/src/double_echo/mod.rs @@ -10,6 +10,8 @@ use tokio::sync::{broadcast, mpsc, oneshot}; use topos_core::uci::{Certificate, CertificateId}; use topos_metrics::{ CERTIFICATE_RECEIVED, CERTIFICATE_RECEIVED_FROM_API, CERTIFICATE_RECEIVED_FROM_GOSSIP, + DOUBLE_ECHO_BUFFERED_MESSAGE_COUNT, DOUBLE_ECHO_BUFFER_CAPACITY, + DOUBLE_ECHO_CURRENT_BUFFER_SIZE, }; use topos_p2p::Client as NetworkClient; use topos_p2p::PeerId; @@ -149,9 +151,12 @@ impl DoubleEcho { debug!("DoubleEchoCommand::Broadcast certificate_id: {}", cert.id); if self.buffer.len() < self.max_buffer_size { self.buffer.push_back((need_gossip, cert)); + DOUBLE_ECHO_CURRENT_BUFFER_SIZE.inc(); if let Ok(pending) = maybe_pending { self.last_pending_certificate = pending; } + } else { + DOUBLE_ECHO_BUFFER_CAPACITY.inc(); } }); } @@ -206,6 +211,7 @@ impl DoubleEcho { certificate_id, ctx, }); + DOUBLE_ECHO_BUFFERED_MESSAGE_COUNT.inc(); } } }.await; @@ -243,6 +249,7 @@ impl DoubleEcho { certificate_id, ctx, }); + DOUBLE_ECHO_BUFFERED_MESSAGE_COUNT.inc(); } } }.await; @@ -292,6 +299,7 @@ impl DoubleEcho { // TODO: Remove the unused_variables attribute when the feature direct is removed #[allow(unused_variables)] if let Some((need_gossip, cert)) = self.buffer.pop_front() { + DOUBLE_ECHO_CURRENT_BUFFER_SIZE.dec(); if let Some(ctx) = self.span_tracker.get(&cert.id) { let span = info_span!( parent: ctx, @@ -314,6 +322,7 @@ impl DoubleEcho { if let Some(messages) = self.buffered_messages.remove(&cert_id) { for message in messages { + DOUBLE_ECHO_BUFFERED_MESSAGE_COUNT.dec(); match message { DoubleEchoCommand::Echo { from_peer, @@ -385,6 +394,7 @@ impl DoubleEcho { { self.last_pending_certificate = pending; self.buffer.push_back((true, certificate)); + DOUBLE_ECHO_CURRENT_BUFFER_SIZE.inc(); } else { info!("No more certificate to broadcast"); }