Skip to content

Commit d603881

Browse files
authored
Add PeerDAS metrics to track subnets without peers (#6928)
Currently we track a key metric `PEERS_PER_COLUMN_SUBNET` in a getter `good_peers_on_sampling_subnets`. Another PR #6922 deletes that function, so we have to move the metric anyway. This PR moves that metric computation to the metrics spawned task which is refreshed every 5 seconds. I also added a few more useful metrics. The total set and intended usage is: - `sync_peers_per_column_subnet`: Track health of overall subnets in your node - `sync_peers_per_custody_column_subnet`: Track health of the subnets your node needs. We should track this metric closely in our dashboards with a heatmap and bar plot - ~~`sync_column_subnets_with_zero_peers`: Is equivalent to the Grafana query `count(sync_peers_per_column_subnet == 0) by (instance)`. We may prefer to skip it, but I believe it's the most important metric as if `sync_column_subnets_with_zero_peers > 0` your node stalls.~~ - ~~`sync_custody_column_subnets_with_zero_peers`: `count(sync_peers_per_custody_column_subnet == 0) by (instance)`~~
1 parent 3992d6b commit d603881

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ impl<E: EthSpec> PeerInfo<E> {
234234
self.custody_subnets.contains(subnet)
235235
}
236236

237+
/// Returns an iterator on this peer's custody subnets
238+
pub fn custody_subnets_iter(&self) -> impl Iterator<Item = &DataColumnSubnetId> {
239+
self.custody_subnets.iter()
240+
}
241+
237242
/// Returns true if the peer is connected to a long-lived subnet.
238243
pub fn has_long_lived_subnet(&self) -> bool {
239244
// Check the meta_data

beacon_node/network/src/metrics.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub use metrics::*;
1414
use std::sync::{Arc, LazyLock};
1515
use strum::AsRefStr;
1616
use strum::IntoEnumIterator;
17+
use types::DataColumnSubnetId;
1718
use types::EthSpec;
1819

1920
pub const SUCCESS: &str = "SUCCESS";
@@ -374,11 +375,18 @@ pub static PEERS_PER_SYNC_TYPE: LazyLock<Result<IntGaugeVec>> = LazyLock::new(||
374375
});
375376
pub static PEERS_PER_COLUMN_SUBNET: LazyLock<Result<IntGaugeVec>> = LazyLock::new(|| {
376377
try_create_int_gauge_vec(
377-
"peers_per_column_subnet",
378+
"sync_peers_per_column_subnet",
378379
"Number of connected peers per column subnet",
379380
&["subnet_id"],
380381
)
381382
});
383+
pub static PEERS_PER_CUSTODY_COLUMN_SUBNET: LazyLock<Result<IntGaugeVec>> = LazyLock::new(|| {
384+
try_create_int_gauge_vec(
385+
"sync_peers_per_custody_column_subnet",
386+
"Number of connected peers per custody column subnet",
387+
&["subnet_id"],
388+
)
389+
});
382390
pub static SYNCING_CHAINS_COUNT: LazyLock<Result<IntGaugeVec>> = LazyLock::new(|| {
383391
try_create_int_gauge_vec(
384392
"sync_range_chains",
@@ -746,16 +754,42 @@ pub fn update_sync_metrics<E: EthSpec>(network_globals: &Arc<NetworkGlobals<E>>)
746754

747755
// count per sync status, the number of connected peers
748756
let mut peers_per_sync_type = FnvHashMap::default();
749-
for sync_type in network_globals
750-
.peers
751-
.read()
752-
.connected_peers()
753-
.map(|(_peer_id, info)| info.sync_status().as_str())
754-
{
757+
let mut peers_per_column_subnet = FnvHashMap::default();
758+
759+
for (_, info) in network_globals.peers.read().connected_peers() {
760+
let sync_type = info.sync_status().as_str();
755761
*peers_per_sync_type.entry(sync_type).or_default() += 1;
762+
763+
for subnet in info.custody_subnets_iter() {
764+
*peers_per_column_subnet.entry(*subnet).or_default() += 1;
765+
}
756766
}
757767

758768
for (sync_type, peer_count) in peers_per_sync_type {
759769
set_gauge_entry(&PEERS_PER_SYNC_TYPE, &[sync_type], peer_count);
760770
}
771+
772+
let all_column_subnets =
773+
(0..network_globals.spec.data_column_sidecar_subnet_count).map(DataColumnSubnetId::new);
774+
let custody_column_subnets = network_globals.sampling_subnets.iter();
775+
776+
// Iterate all subnet values to set to zero the empty entries in peers_per_column_subnet
777+
for subnet in all_column_subnets {
778+
set_gauge_entry(
779+
&PEERS_PER_COLUMN_SUBNET,
780+
&[&format!("{subnet}")],
781+
peers_per_column_subnet.get(&subnet).copied().unwrap_or(0),
782+
);
783+
}
784+
785+
// Registering this metric is a duplicate for supernodes but helpful for fullnodes. This way
786+
// operators can monitor the health of only the subnets of their interest without complex
787+
// Grafana queries.
788+
for subnet in custody_column_subnets {
789+
set_gauge_entry(
790+
&PEERS_PER_CUSTODY_COLUMN_SUBNET,
791+
&[&format!("{subnet}")],
792+
peers_per_column_subnet.get(subnet).copied().unwrap_or(0),
793+
);
794+
}
761795
}

beacon_node/network/src/sync/range_sync/chain.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::batch::{BatchInfo, BatchProcessingResult, BatchState};
22
use super::RangeSyncType;
33
use crate::metrics;
4-
use crate::metrics::PEERS_PER_COLUMN_SUBNET;
54
use crate::network_beacon_processor::ChainSegmentProcessId;
65
use crate::sync::network_context::RangeRequestId;
76
use crate::sync::{network_context::SyncNetworkContext, BatchOperationOutcome, BatchProcessResult};
@@ -10,7 +9,6 @@ use beacon_chain::BeaconChainTypes;
109
use fnv::FnvHashMap;
1110
use lighthouse_network::service::api_types::Id;
1211
use lighthouse_network::{PeerAction, PeerId};
13-
use metrics::set_int_gauge;
1412
use rand::seq::SliceRandom;
1513
use rand::Rng;
1614
use slog::{crit, debug, o, warn};
@@ -1106,11 +1104,6 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
11061104
.good_custody_subnet_peer(*subnet_id)
11071105
.count();
11081106

1109-
set_int_gauge(
1110-
&PEERS_PER_COLUMN_SUBNET,
1111-
&[&subnet_id.to_string()],
1112-
peer_count as i64,
1113-
);
11141107
peer_count > 0
11151108
});
11161109
peers_on_all_custody_subnets

0 commit comments

Comments
 (0)