Skip to content

Commit 857ef25

Browse files
committed
Add metrics for subnet queries (#3721)
## Issue Addressed N/A ## Proposed Changes Add metrics for peers discovered in subnet discv5 queries.
1 parent 713b6a1 commit 857ef25

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

beacon_node/lighthouse_network/src/discovery/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,17 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
834834

835835
// Map each subnet query's min_ttl to the set of ENR's returned for that subnet.
836836
queries.iter().for_each(|query| {
837+
let query_str = match query.subnet {
838+
Subnet::Attestation(_) => "attestation",
839+
Subnet::SyncCommittee(_) => "sync_committee",
840+
};
841+
842+
if let Some(v) = metrics::get_int_counter(
843+
&metrics::TOTAL_SUBNET_QUERIES,
844+
&[query_str],
845+
) {
846+
v.inc();
847+
}
837848
// A subnet query has completed. Add back to the queue, incrementing retries.
838849
self.add_subnet_query(query.subnet, query.min_ttl, query.retries + 1);
839850

@@ -845,6 +856,12 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
845856
.filter(|enr| subnet_predicate(enr))
846857
.map(|enr| enr.peer_id())
847858
.for_each(|peer_id| {
859+
if let Some(v) = metrics::get_int_counter(
860+
&metrics::SUBNET_PEERS_FOUND,
861+
&[query_str],
862+
) {
863+
v.inc();
864+
}
848865
let other_min_ttl = mapped_results.get_mut(&peer_id);
849866

850867
// map peer IDs to the min_ttl furthest in the future

beacon_node/lighthouse_network/src/metrics.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ lazy_static! {
112112
&["client"]
113113
);
114114

115+
pub static ref SUBNET_PEERS_FOUND: Result<IntCounterVec> =
116+
try_create_int_counter_vec(
117+
"discovery_query_peers_found",
118+
"Total number of peers found in attestation subnets and sync subnets",
119+
&["type"]
120+
);
121+
pub static ref TOTAL_SUBNET_QUERIES: Result<IntCounterVec> =
122+
try_create_int_counter_vec(
123+
"discovery_total_queries",
124+
"Total number of discovery subnet queries",
125+
&["type"]
126+
);
127+
115128
/*
116129
* Inbound/Outbound peers
117130
*/

0 commit comments

Comments
 (0)