From ef8572f10d20427309bbd3833491cdd9fcbb7d22 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 9 Jul 2020 14:32:55 +0200 Subject: [PATCH] Add an authority_discovery_known_authorities_count metric (#6614) --- .../client/authority-discovery/src/addr_cache.rs | 5 +++++ substrate/client/authority-discovery/src/lib.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/substrate/client/authority-discovery/src/addr_cache.rs b/substrate/client/authority-discovery/src/addr_cache.rs index 96f589c5d3..0a27c1c443 100644 --- a/substrate/client/authority-discovery/src/addr_cache.rs +++ b/substrate/client/authority-discovery/src/addr_cache.rs @@ -68,6 +68,11 @@ where self.cache.insert(id, addresses); } + /// Returns the number of authority IDs in the cache. + pub fn num_ids(&self) -> usize { + self.cache.len() + } + // Each node should connect to a subset of all authorities. In order to prevent hot spots, this // selection is based on randomness. Selecting randomly each time we alter the address cache // would result in connection churn. To reduce this churn a node generates a seed on startup and diff --git a/substrate/client/authority-discovery/src/lib.rs b/substrate/client/authority-discovery/src/lib.rs index ba1c9f0fa8..1a4473d665 100644 --- a/substrate/client/authority-discovery/src/lib.rs +++ b/substrate/client/authority-discovery/src/lib.rs @@ -481,6 +481,11 @@ where if !remote_addresses.is_empty() { self.addr_cache.insert(authority_id.clone(), remote_addresses); + if let Some(metrics) = &self.metrics { + metrics.known_authorities_count.set( + self.addr_cache.num_ids().try_into().unwrap_or(std::u64::MAX) + ); + } self.update_peer_set_priority_group()?; } @@ -651,6 +656,7 @@ pub(crate) struct Metrics { request: Counter, dht_event_received: CounterVec, handle_value_found_event_failure: Counter, + known_authorities_count: Gauge, priority_group_size: Gauge, } @@ -697,6 +703,13 @@ impl Metrics { )?, registry, )?, + known_authorities_count: register( + Gauge::new( + "authority_discovery_known_authorities_count", + "Number of authorities known by authority discovery." + )?, + registry, + )?, priority_group_size: register( Gauge::new( "authority_discovery_priority_group_size",