From 7ea866d146ad44ab6fe0b3a4acf1d5f41eef0598 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Wed, 20 Oct 2021 17:47:56 +0000 Subject: [PATCH 1/7] Update `metrics` dependency to version 0.17 And also update the `metrics-exporter-prometheus` to version 0.6.1. These updates are to make sure Tokio 1 is supported. --- Cargo.toml | 2 -- zebrad/Cargo.toml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ff18db1154c..e22567c3983 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,6 @@ panic = "abort" # awaiting stable versions which all depend on tokio 1.0, see #1086 for details hyper = { git = "https://github.com/hyperium/hyper", rev = "ed2b22a7f66899d338691552fbcb6c0f2f4e06b9" } -metrics = { git = "https://github.com/ZcashFoundation/metrics", rev = "971133128e5aebe3ad177acffc6154449736cfa2" } -metrics-exporter-prometheus = { git = "https://github.com/ZcashFoundation/metrics", rev = "971133128e5aebe3ad177acffc6154449736cfa2" } tower = { git = "https://github.com/tower-rs/tower", rev = "d4d1c67c6a0e4213a52abcc2b9df6cc58276ee39" } # TODO: remove these after a new librustzcash release. diff --git a/zebrad/Cargo.toml b/zebrad/Cargo.toml index 176d66dec20..9b545b53d06 100644 --- a/zebrad/Cargo.toml +++ b/zebrad/Cargo.toml @@ -36,8 +36,8 @@ tracing-flame = "0.1.0" tracing-journald = "0.1.0" tracing-subscriber = { version = "0.2.25", features = ["tracing-log"] } tracing-error = "0.1.2" -metrics = "0.13.0-alpha.8" -metrics-exporter-prometheus = "0.1.0-alpha.7" +metrics = "0.17.0" +metrics-exporter-prometheus = "0.6.1" dirs = "4.0.0" inferno = { version = "0.10.7", default-features = false } From 265d6e25332200d707a9b89c500969359f5bb1c7 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Fri, 29 Oct 2021 13:43:08 +0000 Subject: [PATCH 2/7] Remove unnecessary conversion Suggested by a Clippy lint. --- zebrad/src/components/mempool/storage/verified_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebrad/src/components/mempool/storage/verified_set.rs b/zebrad/src/components/mempool/storage/verified_set.rs index 07a8224a62d..8bb5f5c8a9e 100644 --- a/zebrad/src/components/mempool/storage/verified_set.rs +++ b/zebrad/src/components/mempool/storage/verified_set.rs @@ -267,6 +267,6 @@ impl VerifiedSet { "zcash.mempool.size.bytes", self.transactions_serialized_size as _ ); - metrics::gauge!("zcash.mempool.cost.bytes", u64::from(self.total_cost) as _); + metrics::gauge!("zcash.mempool.cost.bytes", self.total_cost as _); } } From 3537c302417e09a1577c02e7b130cdc1272b2f3e Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Wed, 20 Oct 2021 17:49:13 +0000 Subject: [PATCH 3/7] Use `f64` as the histogram data type `u64` isn't supported as the histogram data type in newer versions of `metrics`. --- zebrad/src/components/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zebrad/src/components/sync.rs b/zebrad/src/components/sync.rs index 0385269bbdf..169fbf0a6a7 100644 --- a/zebrad/src/components/sync.rs +++ b/zebrad/src/components/sync.rs @@ -485,7 +485,7 @@ where let new_download_len = download_set.len(); let new_hashes = new_download_len - prev_download_len; tracing::debug!(new_hashes, "added hashes to download set"); - metrics::histogram!("sync.obtain.response.hash.count", new_hashes as u64); + metrics::histogram!("sync.obtain.response.hash.count", new_hashes as f64); } Ok(_) => unreachable!("network returned wrong response"), // We ignore this error because we made multiple fanout requests. @@ -621,7 +621,7 @@ where let new_download_len = download_set.len(); let new_hashes = new_download_len - prev_download_len; tracing::debug!(new_hashes, "added hashes to download set"); - metrics::histogram!("sync.extend.response.hash.count", new_hashes as u64); + metrics::histogram!("sync.extend.response.hash.count", new_hashes as f64); } Ok(_) => unreachable!("network returned wrong response"), // We ignore this error because we made multiple fanout requests. From a8725dbfded3f2efe25da6bbd9f9cc4e7629121f Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Wed, 20 Oct 2021 17:54:15 +0000 Subject: [PATCH 4/7] Simplify build version counter Remove all constants and use the new `metrics::incement_counter!` macro. --- zebrad/src/components/metrics.rs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/zebrad/src/components/metrics.rs b/zebrad/src/components/metrics.rs index c4d5137f50c..a753cf8d13b 100644 --- a/zebrad/src/components/metrics.rs +++ b/zebrad/src/components/metrics.rs @@ -23,24 +23,10 @@ impl MetricsEndpoint { // Expose binary metadata to metrics, using a single time series with // value 1: // https://www.robustperception.io/exposing-the-software-version-to-prometheus - // - // We manually expand the metrics::increment!() macro because it only - // supports string literals for metrics names, preventing us from - // using concat!() to build the name. - static METRIC_NAME: [metrics::SharedString; 2] = [ - metrics::SharedString::const_str(env!("CARGO_PKG_NAME")), - metrics::SharedString::const_str("build.info"), - ]; - static METRIC_LABELS: [metrics::Label; 1] = - [metrics::Label::from_static_parts( - "version", - env!("CARGO_PKG_VERSION"), - )]; - static METRIC_KEY: metrics::KeyData = - metrics::KeyData::from_static_parts(&METRIC_NAME, &METRIC_LABELS); - if let Some(recorder) = metrics::try_recorder() { - recorder.increment_counter(metrics::Key::Borrowed(&METRIC_KEY), 1); - } + metrics::increment_counter!( + format!("{}.build.info", env!("CARGO_PKG_NAME")), + "version" => env!("CARGO_PKG_VERSION") + ); } Err(e) => panic!( "Opening metrics endpoint listener {:?} failed: {:?}. \ From 5dd8d4db1c1629a6597aeb214b39f7fa8fd33203 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Fri, 22 Oct 2021 21:41:37 +0000 Subject: [PATCH 5/7] Change metrics output line to match on The snapshot string isn't included in the newer version of `metrics-exporter-prometheus`. --- zebrad/tests/acceptance.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index 20bd4c0e8b1..eeddb837e6c 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -1127,7 +1127,7 @@ async fn metrics_endpoint() -> Result<()> { let output = output.assert_failure()?; output.any_output_line_contains( - "metrics snapshot", + "# TYPE zebrad_build_info counter", &body, "metrics exporter response", "the metrics response header", From ea71cec1e03728613b8b9bed15e5ce0b9a881895 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Thu, 28 Oct 2021 20:36:08 +0000 Subject: [PATCH 6/7] Update `metrics` dependency from other crates Update other `zebra` crates so that only one version of `metrics` is used. --- zebra-consensus/Cargo.toml | 2 +- zebra-network/Cargo.toml | 2 +- zebra-state/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zebra-consensus/Cargo.toml b/zebra-consensus/Cargo.toml index f3ecf5aee7c..d4d84ac0309 100644 --- a/zebra-consensus/Cargo.toml +++ b/zebra-consensus/Cargo.toml @@ -23,7 +23,7 @@ serde = { version = "1", features = ["serde_derive"] } futures = "0.3.17" futures-util = "0.3.17" -metrics = "0.13.0-alpha.8" +metrics = "0.17" thiserror = "1.0.30" tokio = { version = "0.3.6", features = ["time", "sync", "stream", "tracing"] } tower = { version = "0.4", features = ["timeout", "util", "buffer"] } diff --git a/zebra-network/Cargo.toml b/zebra-network/Cargo.toml index 49a1bb47875..677b97d7168 100644 --- a/zebra-network/Cargo.toml +++ b/zebra-network/Cargo.toml @@ -28,7 +28,7 @@ tokio = { version = "0.3.6", features = ["net", "time", "stream", "tracing", "ma tokio-util = { version = "0.5", features = ["codec"] } tower = { version = "0.4", features = ["retry", "discover", "load", "load-shed", "timeout", "util", "buffer"] } -metrics = "0.13.0-alpha.8" +metrics = "0.17" tracing = "0.1" tracing-futures = "0.2" tracing-error = { version = "0.1.2", features = ["traced-error"] } diff --git a/zebra-state/Cargo.toml b/zebra-state/Cargo.toml index b8790991b9b..45421a8589e 100644 --- a/zebra-state/Cargo.toml +++ b/zebra-state/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["serde_derive"] } bincode = "1" futures = "0.3.17" -metrics = "0.13.0-alpha.8" +metrics = "0.17" tower = { version = "0.4", features = ["buffer", "util"] } tracing = "0.1" thiserror = "1.0.30" From c7065849ff956d832c9f35cbafab39216259cc72 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Mon, 1 Nov 2021 21:34:30 +0000 Subject: [PATCH 7/7] Include patch version for `metrics` dependency Use a strict version specification. --- zebra-consensus/Cargo.toml | 2 +- zebra-network/Cargo.toml | 2 +- zebra-state/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/zebra-consensus/Cargo.toml b/zebra-consensus/Cargo.toml index d4d84ac0309..3626f33850c 100644 --- a/zebra-consensus/Cargo.toml +++ b/zebra-consensus/Cargo.toml @@ -23,7 +23,7 @@ serde = { version = "1", features = ["serde_derive"] } futures = "0.3.17" futures-util = "0.3.17" -metrics = "0.17" +metrics = "0.17.0" thiserror = "1.0.30" tokio = { version = "0.3.6", features = ["time", "sync", "stream", "tracing"] } tower = { version = "0.4", features = ["timeout", "util", "buffer"] } diff --git a/zebra-network/Cargo.toml b/zebra-network/Cargo.toml index 677b97d7168..7a3f7817639 100644 --- a/zebra-network/Cargo.toml +++ b/zebra-network/Cargo.toml @@ -28,7 +28,7 @@ tokio = { version = "0.3.6", features = ["net", "time", "stream", "tracing", "ma tokio-util = { version = "0.5", features = ["codec"] } tower = { version = "0.4", features = ["retry", "discover", "load", "load-shed", "timeout", "util", "buffer"] } -metrics = "0.17" +metrics = "0.17.0" tracing = "0.1" tracing-futures = "0.2" tracing-error = { version = "0.1.2", features = ["traced-error"] } diff --git a/zebra-state/Cargo.toml b/zebra-state/Cargo.toml index 45421a8589e..5fccfdee0d1 100644 --- a/zebra-state/Cargo.toml +++ b/zebra-state/Cargo.toml @@ -19,7 +19,7 @@ serde = { version = "1", features = ["serde_derive"] } bincode = "1" futures = "0.3.17" -metrics = "0.17" +metrics = "0.17.0" tower = { version = "0.4", features = ["buffer", "util"] } tracing = "0.1" thiserror = "1.0.30"