From 4a98b8fa0de2d3deb5567905f79760fb782952a1 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Wed, 22 Jul 2020 14:46:21 -0700 Subject: [PATCH] Add basic metrics to the syncer. --- Cargo.lock | 1 + zebra-consensus/Cargo.toml | 1 + zebra-consensus/src/checkpoint.rs | 2 ++ zebrad/src/commands/start/sync.rs | 13 +++++++++++++ 4 files changed, 17 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ad51097f..a1b72313 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2592,6 +2592,7 @@ dependencies = [ "color-eyre", "futures", "futures-util", + "metrics", "rand 0.7.3", "redjubjub", "spandoc", diff --git a/zebra-consensus/Cargo.toml b/zebra-consensus/Cargo.toml index 94d09ce5..e6365738 100644 --- a/zebra-consensus/Cargo.toml +++ b/zebra-consensus/Cargo.toml @@ -15,6 +15,7 @@ tokio = { version = "0.2.22", features = ["time", "sync", "stream", "tracing"] } tower = "0.3" tracing = "0.1.16" tracing-futures = "0.2.4" +metrics = "0.12" tower-batch = { path = "../tower-batch/" } zebra-chain = { path = "../zebra-chain" } diff --git a/zebra-consensus/src/checkpoint.rs b/zebra-consensus/src/checkpoint.rs index f2d37927..5ed62fa4 100644 --- a/zebra-consensus/src/checkpoint.rs +++ b/zebra-consensus/src/checkpoint.rs @@ -651,6 +651,8 @@ impl Service> for CheckpointVerifier { // TODO(teor): retry on failure (low priority, failures should be rare) self.process_checkpoint_range(); + metrics::gauge!("checkpoint.queued_slots", self.queued.len() as i64); + async move { // Remove the Result<..., RecvError> wrapper from the channel future rx.await diff --git a/zebrad/src/commands/start/sync.rs b/zebrad/src/commands/start/sync.rs index 8c7eb5a8..38982401 100644 --- a/zebrad/src/commands/start/sync.rs +++ b/zebrad/src/commands/start/sync.rs @@ -67,13 +67,25 @@ where pub async fn sync(&mut self) -> Result<(), Report> { loop { self.obtain_tips().await?; + metrics::gauge!( + "sync.prospective_tips.len", + self.prospective_tips.len() as i64 + ); + metrics::gauge!("sync.pending_blocks.len", self.pending_blocks.len() as i64); // ObtainTips Step 6 // // If there are any prospective tips, call ExtendTips. Continue this step until there are no more prospective tips. while !self.prospective_tips.is_empty() { tracing::debug!("extending prospective tips"); + self.extend_tips().await?; + + metrics::gauge!( + "sync.prospective_tips.len", + self.prospective_tips.len() as i64 + ); + metrics::gauge!("sync.pending_blocks.len", self.pending_blocks.len() as i64); tracing::debug!( pending.len = self.pending_blocks.len(), limit = LOOKAHEAD_LIMIT @@ -359,6 +371,7 @@ where Ok(_) => unreachable!("wrong response to block request"), Err(e) => return Err(e), }; + metrics::counter!("sync.downloaded_blocks", 1); verifier.ready_and().await?.call(block).await })