From 1637b3ea4b3bbf44e48f36948e8556c0e1b54f13 Mon Sep 17 00:00:00 2001 From: Arun Koshy Date: Thu, 16 Jan 2025 13:24:38 -0800 Subject: [PATCH] add metrics --- consensus/core/src/authority_service.rs | 25 +++++++++++++++++++++++++ consensus/core/src/metrics.rs | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/consensus/core/src/authority_service.rs b/consensus/core/src/authority_service.rs index f0b8fa3144961..4f419d1e9d823 100644 --- a/consensus/core/src/authority_service.rs +++ b/consensus/core/src/authority_service.rs @@ -108,6 +108,13 @@ impl NetworkService for AuthorityService { ) .collect::>(); + self.context + .metrics + .node_metrics + .network_received_excluded_ancestors_from_authority + .with_label_values(&[peer_hostname]) + .inc_by(excluded_ancestors.len() as u64); + // Reject blocks not produced by the peer. if peer != signed_block.author() { self.context @@ -166,12 +173,30 @@ impl NetworkService for AuthorityService { let mut missing_excluded_ancestors = BTreeSet::new(); for excluded_ancestor in &excluded_ancestors { + let excluded_ancestor_hostname = &self + .context + .committee + .authority(excluded_ancestor.author) + .hostname; + self.context + .metrics + .node_metrics + .network_excluded_ancestors_count_by_authority + .with_label_values(&[excluded_ancestor_hostname]) + .inc(); if !self.dag_state.read().contains_block(excluded_ancestor) { missing_excluded_ancestors.insert(*excluded_ancestor); } } if !missing_excluded_ancestors.is_empty() { + self.context + .metrics + .node_metrics + .network_excluded_ancestors_sent_to_fetch + .with_label_values(&[peer_hostname]) + .inc_by(missing_excluded_ancestors.len() as u64); + let synchronizer = self.synchronizer.clone(); tokio::spawn(async move { // schedule the fetching of them from this peer in the background diff --git a/consensus/core/src/metrics.rs b/consensus/core/src/metrics.rs index 3e15953d96102..1e87288bb548b 100644 --- a/consensus/core/src/metrics.rs +++ b/consensus/core/src/metrics.rs @@ -128,6 +128,9 @@ pub(crate) struct NodeMetrics { pub(crate) synchronizer_missing_blocks_by_authority: IntCounterVec, pub(crate) synchronizer_current_missing_blocks_by_authority: IntGaugeVec, pub(crate) synchronizer_fetched_blocks_by_authority: IntCounterVec, + pub(crate) network_received_excluded_ancestors_from_authority: IntCounterVec, + pub(crate) network_excluded_ancestors_sent_to_fetch: IntCounterVec, + pub(crate) network_excluded_ancestors_count_by_authority: IntCounterVec, pub(crate) invalid_blocks: IntCounterVec, pub(crate) rejected_blocks: IntCounterVec, pub(crate) rejected_future_blocks: IntCounterVec, @@ -375,6 +378,24 @@ impl NodeMetrics { &["authority", "type"], registry, ).unwrap(), + network_received_excluded_ancestors_from_authority: register_int_counter_vec_with_registry!( + "network_received_excluded_ancestors_from_authority", + "Number of excluded ancestors received from each authority.", + &["authority"], + registry, + ).unwrap(), + network_excluded_ancestors_count_by_authority: register_int_counter_vec_with_registry!( + "network_excluded_ancestors_count_by_authority", + "Total number of excluded ancestors per authority.", + &["authority"], + registry, + ).unwrap(), + network_excluded_ancestors_sent_to_fetch: register_int_counter_vec_with_registry!( + "network_excluded_ancestors_sent_to_fetch", + "Number of excluded ancestors sent to fetch.", + &["authority"], + registry, + ).unwrap(), last_known_own_block_round: register_int_gauge_with_registry!( "last_known_own_block_round", "The highest round of our own block as this has been synced from peers during an amnesia recovery",