Skip to content

Commit

Permalink
feat: add metrics for dropped outgoing messages (#10225)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
nkysg and mattsse authored Aug 9, 2024
1 parent 50397cd commit c8a332f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/net/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub struct NetworkMetrics {
pub struct SessionManagerMetrics {
/// Number of successful outgoing dial attempts.
pub(crate) total_dial_successes: Counter,
/// Number of dropped outgoing peer messages.
pub(crate) total_outgoing_peer_messages_dropped: Counter,
}

/// Metrics for the [`TransactionsManager`](crate::transactions::TransactionsManager).
Expand Down
15 changes: 13 additions & 2 deletions crates/net/network/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use secp256k1::SecretKey;
use tokio::{
io::{AsyncRead, AsyncWrite},
net::TcpStream,
sync::{mpsc, oneshot},
sync::{mpsc, mpsc::error::TrySendError, oneshot},
};
use tokio_stream::wrappers::ReceiverStream;
use tokio_util::sync::PollSender;
Expand Down Expand Up @@ -346,7 +346,18 @@ impl SessionManager {
/// Sends a message to the peer's session
pub fn send_message(&mut self, peer_id: &PeerId, msg: PeerMessage) {
if let Some(session) = self.active_sessions.get_mut(peer_id) {
let _ = session.commands_to_session.try_send(SessionCommand::Message(msg));
let _ = session.commands_to_session.try_send(SessionCommand::Message(msg)).inspect_err(
|e| {
if let TrySendError::Full(_) = e {
debug!(
target: "net::session",
?peer_id,
"session command buffer full, dropping message"
);
self.metrics.total_outgoing_peer_messages_dropped.increment(1);
}
},
);
}
}

Expand Down

0 comments on commit c8a332f

Please sign in to comment.