Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add metrics for dropped outgoing messages #10225

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 dial attempts.
mattsse marked this conversation as resolved.
Show resolved Hide resolved
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
Loading