Skip to content

Commit

Permalink
chore: adding more metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <[email protected]>
  • Loading branch information
Freyskeyd committed Jun 27, 2023
1 parent 952fc6b commit da0b20e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/topos-metrics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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!(
Expand Down
2 changes: 2 additions & 0 deletions crates/topos-p2p/src/runtime/handle_event/gossipsub.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -22,6 +23,7 @@ impl EventHandler<GossipEvent> 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);
Expand Down
10 changes: 10 additions & 0 deletions crates/topos-tce-broadcast/src/double_echo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
});
}
Expand Down Expand Up @@ -206,6 +211,7 @@ impl DoubleEcho {
certificate_id,
ctx,
});
DOUBLE_ECHO_BUFFERED_MESSAGE_COUNT.inc();
}
}
}.await;
Expand Down Expand Up @@ -243,6 +249,7 @@ impl DoubleEcho {
certificate_id,
ctx,
});
DOUBLE_ECHO_BUFFERED_MESSAGE_COUNT.inc();
}
}
}.await;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit da0b20e

Please sign in to comment.