Skip to content

Commit

Permalink
add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
arun-koshy committed Jan 16, 2025
1 parent 06d5c34 commit 1637b3e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
25 changes: 25 additions & 0 deletions consensus/core/src/authority_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ impl<C: CoreThreadDispatcher> NetworkService for AuthorityService<C> {
)
.collect::<Vec<BlockRef>>();

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
Expand Down Expand Up @@ -166,12 +173,30 @@ impl<C: CoreThreadDispatcher> NetworkService for AuthorityService<C> {

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
Expand Down
21 changes: 21 additions & 0 deletions consensus/core/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1637b3e

Please sign in to comment.