From 798de8337baece8dc96883bdc68f38b733cd8624 Mon Sep 17 00:00:00 2001
From: Max Inden <mail@max-inden.de>
Date: Tue, 21 Apr 2020 10:54:37 +0200
Subject: [PATCH] client/authority-discovery: Add metric exposing priority
 group size (#5707)

Expose the amount of addresses that are passed from the authority
discovery module down to the network peer set manager as a priority
group in order to connect to the corresponding nodes.

```
authority_discovery_priority_group_size 10
```
---
 substrate/client/authority-discovery/src/lib.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/substrate/client/authority-discovery/src/lib.rs b/substrate/client/authority-discovery/src/lib.rs
index 2cf455f17ba..91e8293dec8 100644
--- a/substrate/client/authority-discovery/src/lib.rs
+++ b/substrate/client/authority-discovery/src/lib.rs
@@ -475,6 +475,10 @@ where
 	fn update_peer_set_priority_group(&self) -> Result<()> {
 		let addresses = self.addr_cache.get_subset();
 
+		if let Some(metrics) = &self.metrics {
+			metrics.priority_group_size.set(addresses.len().try_into().unwrap_or(std::u64::MAX));
+		}
+
 		debug!(
 			target: LOG_TARGET,
 			"Applying priority group {:?} to peerset.", addresses,
@@ -599,6 +603,7 @@ pub(crate) struct Metrics {
 	amount_last_published: Gauge<U64>,
 	request: Counter<U64>,
 	dht_event_received: CounterVec<U64>,
+	priority_group_size: Gauge<U64>,
 }
 
 impl Metrics {
@@ -637,6 +642,13 @@ impl Metrics {
 				)?,
 				registry,
 			)?,
+			priority_group_size: register(
+				Gauge::new(
+					"authority_discovery_priority_group_size",
+					"Number of addresses passed to the peer set as a priority group."
+				)?,
+				registry,
+			)?,
 		})
 	}
 }
-- 
GitLab