Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
overseer metrics: messages relayed
  • Loading branch information
Andronik Ordian committed Sep 30, 2020
commit ac1823d454ebfa748769cc188259fed1a88cf8b2
37 changes: 31 additions & 6 deletions node/overseer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ pub struct AllSubsystems<CV, CB, CS, SD, AD, BS, BD, P, PoVD, RA, AS, NB, CA, CG
struct MetricsInner {
activated_heads_total: prometheus::Counter<prometheus::U64>,
deactivated_heads_total: prometheus::Counter<prometheus::U64>,
messages_relayed_total: prometheus::Counter<prometheus::U64>,
}

#[derive(Default, Clone)]
Expand All @@ -487,6 +488,12 @@ impl Metrics {
metrics.deactivated_heads_total.inc();
}
}

fn on_message_relayed(&self) {
if let Some(metrics) = &self.0 {
metrics.messages_relayed_total.inc();
}
}
}

impl metrics::Metrics for Metrics {
Expand All @@ -506,6 +513,13 @@ impl metrics::Metrics for Metrics {
)?,
registry,
)?,
messages_relayed_total: prometheus::register(
prometheus::Counter::new(
"parachain_messages_relayed_total",
"Number of messages relayed by Overseer."
)?,
registry,
)?,
};
Ok(Metrics(Some(metrics)))
}
Expand Down Expand Up @@ -1046,10 +1060,11 @@ where
}

async fn route_message(&mut self, msg: AllMessages) {
self.metrics.on_message_relayed();
match msg {
AllMessages::CandidateValidation(msg) => {
if let Some(ref mut s) = self.candidate_validation_subsystem.instance {
let _= s.tx.send(FromOverseer::Communication { msg }).await;
let _ = s.tx.send(FromOverseer::Communication { msg }).await;
}
}
AllMessages::CandidateBacking(msg) => {
Expand Down Expand Up @@ -1209,6 +1224,7 @@ fn spawn<S: SpawnNamed, M: Send + 'static>(
#[cfg(test)]
mod tests {
use std::sync::atomic;
use std::collections::HashMap;
use futures::{executor, pin_mut, select, channel::mpsc, FutureExt};

use polkadot_primitives::v1::{BlockData, CollatorPair, PoV};
Expand Down Expand Up @@ -1435,27 +1451,36 @@ mod tests {

handler.block_imported(second_block).await.unwrap();
handler.block_imported(third_block).await.unwrap();
handler.send_msg(AllMessages::CandidateValidation(test_candidate_validation_msg())).await.unwrap();
handler.stop().await.unwrap();

select! {
res = overseer_fut => {
assert!(res.is_ok());
let (activated, deactivated) = extract_metrics(&registry);
assert_eq!(activated, 3);
assert_eq!(deactivated, 2);
let metrics = extract_metrics(&registry);
assert_eq!(metrics.get("activated").copied().unwrap(), 3);
assert_eq!(metrics.get("deactivated").copied().unwrap(), 2);
assert_eq!(metrics.get("relayed").copied().unwrap(), 1);
},
complete => (),
}
});
}

fn extract_metrics(registry: &prometheus::Registry) -> (u64, u64) {
fn extract_metrics(registry: &prometheus::Registry) -> HashMap<&'static str, u64> {
let gather = registry.gather();
assert_eq!(gather[0].get_name(), "parachain_activated_heads_total");
assert_eq!(gather[1].get_name(), "parachain_deactivated_heads_total");
assert_eq!(gather[2].get_name(), "parachain_messages_relayed_total");
let activated = gather[0].get_metric()[0].get_counter().get_value() as u64;
let deactivated = gather[1].get_metric()[0].get_counter().get_value() as u64;
(activated, deactivated)
let relayed = gather[2].get_metric()[0].get_counter().get_value() as u64;

let mut result = HashMap::new();
result.insert("activated", activated);
result.insert("deactivated", deactivated);
result.insert("relayed", relayed);
result
}

// Spawn a subsystem that immediately exits.
Expand Down