mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add metrics for dropped outgoing messages (#10225)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -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).
|
||||
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user