mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 09:31:12 +00:00
network:bridge: fix peer_count metric (#3711)
The metric records the current protocol_version of the validator that just connected with the peer_map.len(), which contains all peers that connected, that has the effect the metric will be wrong since it won't tell us how many peers we have connected per version because it will always record the total number of peers Fix this by counting by version inside peer_map, additionally because that might be a bit heavier than len(), publish it only on-active leaves. --------- Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
This commit is contained in:
committed by
GitHub
parent
a2c9ab8c04
commit
e0c081dbd4
@@ -102,6 +102,30 @@ struct SharedInner {
|
||||
collation_peers: HashMap<PeerId, PeerData>,
|
||||
}
|
||||
|
||||
// Counts the number of peers that are connectioned using `version`
|
||||
fn count_peers_by_version(peers: &HashMap<PeerId, PeerData>) -> HashMap<ProtocolVersion, usize> {
|
||||
let mut by_version_count = HashMap::new();
|
||||
for peer in peers.values() {
|
||||
*(by_version_count.entry(peer.version).or_default()) += 1;
|
||||
}
|
||||
by_version_count
|
||||
}
|
||||
|
||||
// Notes the peer count
|
||||
fn note_peers_count(metrics: &Metrics, shared: &Shared) {
|
||||
let guard = shared.0.lock();
|
||||
let validation_stats = count_peers_by_version(&guard.validation_peers);
|
||||
let collation_stats = count_peers_by_version(&guard.collation_peers);
|
||||
|
||||
for (version, count) in validation_stats {
|
||||
metrics.note_peer_count(PeerSet::Validation, version, count)
|
||||
}
|
||||
|
||||
for (version, count) in collation_stats {
|
||||
metrics.note_peer_count(PeerSet::Collation, version, count)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum Mode {
|
||||
Syncing(Box<dyn SyncOracle + Send>),
|
||||
Active,
|
||||
|
||||
@@ -262,7 +262,6 @@ async fn handle_validation_message<AD>(
|
||||
}
|
||||
|
||||
metrics.on_peer_connected(peer_set, version);
|
||||
metrics.note_peer_count(peer_set, version, peer_map.len());
|
||||
|
||||
shared.local_view.clone().unwrap_or(View::default())
|
||||
};
|
||||
@@ -320,8 +319,6 @@ async fn handle_validation_message<AD>(
|
||||
let w = peer_map.remove(&peer).is_some();
|
||||
|
||||
metrics.on_peer_disconnected(peer_set, version);
|
||||
metrics.note_peer_count(peer_set, version, peer_map.len());
|
||||
|
||||
w
|
||||
};
|
||||
|
||||
@@ -524,7 +521,6 @@ async fn handle_collation_message<AD>(
|
||||
}
|
||||
|
||||
metrics.on_peer_connected(peer_set, version);
|
||||
metrics.note_peer_count(peer_set, version, peer_map.len());
|
||||
|
||||
shared.local_view.clone().unwrap_or(View::default())
|
||||
};
|
||||
@@ -575,7 +571,6 @@ async fn handle_collation_message<AD>(
|
||||
let w = peer_map.remove(&peer).is_some();
|
||||
|
||||
metrics.on_peer_disconnected(peer_set, version);
|
||||
metrics.note_peer_count(peer_set, version, peer_map.len());
|
||||
|
||||
w
|
||||
};
|
||||
@@ -832,6 +827,7 @@ where
|
||||
&metrics,
|
||||
¬ification_sinks,
|
||||
);
|
||||
note_peers_count(&metrics, &shared);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user