From f6646aa4520df61ed03c4982a8d33e7b5dddce8a Mon Sep 17 00:00:00 2001 From: Max Wolff Date: Wed, 12 Jul 2023 15:51:43 -0700 Subject: [PATCH] #3667 Add Dial Success Metric (#3729) --- crates/net/network/src/metrics.rs | 8 ++++++++ crates/net/network/src/session/mod.rs | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/net/network/src/metrics.rs b/crates/net/network/src/metrics.rs index d7969da80a..085b1f093b 100644 --- a/crates/net/network/src/metrics.rs +++ b/crates/net/network/src/metrics.rs @@ -45,6 +45,14 @@ pub struct NetworkMetrics { pub(crate) total_dropped_eth_requests_at_full_capacity: Counter, } +/// Metrics for SessionManager +#[derive(Metrics)] +#[metrics(scope = "network")] +pub struct SesssionManagerMetrics { + /// Number of dials that resulted in a peer being added to the peerset + pub(crate) total_dial_successes: Counter, +} + /// Metrics for the TransactionsManager #[derive(Metrics)] #[metrics(scope = "network")] diff --git a/crates/net/network/src/session/mod.rs b/crates/net/network/src/session/mod.rs index 7dda07cdd9..b0d628d48c 100644 --- a/crates/net/network/src/session/mod.rs +++ b/crates/net/network/src/session/mod.rs @@ -1,6 +1,7 @@ //! Support for handling peer sessions. use crate::{ message::PeerMessage, + metrics::SesssionManagerMetrics, session::{ active::ActiveSession, config::SessionCounter, @@ -101,6 +102,8 @@ pub(crate) struct SessionManager { active_session_rx: ReceiverStream, /// Used to measure inbound & outbound bandwidth across all managed streams bandwidth_meter: BandwidthMeter, + /// Metrics for the session manager. + metrics: SesssionManagerMetrics, } // === impl SessionManager === @@ -137,6 +140,7 @@ impl SessionManager { active_session_tx: MeteredSender::new(active_session_tx, "network_active_session"), active_session_rx: ReceiverStream::new(active_session_rx), bandwidth_meter, + metrics: Default::default(), } } @@ -473,6 +477,10 @@ impl SessionManager { self.active_sessions.insert(peer_id, handle); self.counter.inc_active(&direction); + if direction.is_outgoing() { + self.metrics.total_dial_successes.increment(1); + } + Poll::Ready(SessionEvent::SessionEstablished { peer_id, remote_addr, @@ -695,6 +703,11 @@ impl Direction { pub(crate) fn is_incoming(&self) -> bool { matches!(self, Direction::Incoming) } + + /// Returns `true` if this an outgoing connection. + pub(crate) fn is_outgoing(&self) -> bool { + matches!(self, Direction::Outgoing(_)) + } } impl std::fmt::Display for Direction {