Skip to content

Commit

Permalink
beacon node: move connected peer metrics,
Browse files Browse the repository at this point in the history
put them before the ban status checks to avoid negative counts as each FromSwarm::ConnectionClosed
event is always paired with an earlier FromSwarm::ConnectionEstablished, and when we ban before
incrementing metrics we return earlier.
  • Loading branch information
jxs committed Sep 13, 2023
1 parent a4faad5 commit 85b2df5
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,30 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
metrics::check_nat();
}

// increment prometheus metrics
if self.metrics_enabled {
match remote_addr.iter().find(|proto| {
matches!(
proto,
multiaddr::Protocol::QuicV1 | multiaddr::Protocol::Tcp(_)
)
}) {
Some(multiaddr::Protocol::QuicV1) => {
metrics::inc_gauge(&metrics::QUIC_PEERS_CONNECTED);
}
Some(multiaddr::Protocol::Tcp(_)) => {
metrics::inc_gauge(&metrics::TCP_PEERS_CONNECTED);
}
Some(_) => unreachable!(),
None => {
error!(self.log, "Connection established via unknown transport"; "addr" => %remote_addr)
}
};

self.update_connected_peer_metrics();
metrics::inc_counter(&metrics::PEER_CONNECT_EVENT_COUNT);
}

// Check to make sure the peer is not supposed to be banned
match self.ban_status(&peer_id) {
// TODO: directly emit the ban event?
Expand Down Expand Up @@ -267,28 +291,6 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
address
}
};

// increment prometheus metrics
if self.metrics_enabled {
match remote_addr.iter().find(|proto| {
matches!(
proto,
multiaddr::Protocol::QuicV1 | multiaddr::Protocol::Tcp(_)
)
}) {
Some(multiaddr::Protocol::QuicV1) => {
metrics::inc_gauge(&metrics::QUIC_PEERS_CONNECTED);
}
Some(multiaddr::Protocol::Tcp(_)) => {
metrics::inc_gauge(&metrics::TCP_PEERS_CONNECTED);
}
Some(_) => unreachable!(),
None => error!(self.log, "Connected via unknown transport"; "addr" => %remote_addr),
};

self.update_connected_peer_metrics();
metrics::inc_counter(&metrics::PEER_CONNECT_EVENT_COUNT);
}
}

fn on_connection_closed(
Expand Down

0 comments on commit 85b2df5

Please sign in to comment.