From e5ac4810a230d8ec93f91e24840c5b9405f0f6d7 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 7 Dec 2021 16:04:24 +0000 Subject: [PATCH 01/63] Add runtime metrics provider Signed-off-by: Andrei Sandu --- node/metrics/Cargo.toml | 3 + node/metrics/src/lib.rs | 2 + node/metrics/src/runtime.rs | 129 ++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 node/metrics/src/runtime.rs diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index 776cd72ce0d3..6062801438c1 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -12,6 +12,9 @@ futures-timer = "3.0.2" metered-channel = { path = "../metered-channel" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } [features] default = [] diff --git a/node/metrics/src/lib.rs b/node/metrics/src/lib.rs index af635f621d73..05313b1e7100 100644 --- a/node/metrics/src/lib.rs +++ b/node/metrics/src/lib.rs @@ -29,6 +29,8 @@ pub use metered_channel as metered; /// Cyclic metric collection support. pub mod metronome; pub use self::metronome::Metronome; +pub mod runtime; +pub use self::runtime::logger_hook; /// This module reexports Prometheus types and defines the [`Metrics`] trait. pub mod metrics { diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs new file mode 100644 index 000000000000..cd2eedcd8a9a --- /dev/null +++ b/node/metrics/src/runtime.rs @@ -0,0 +1,129 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Runtime Metrics helpers. +//! +//! Builds on top of Substrate wasm tracing support. + +use std::{ + collections::hash_map::HashMap, + sync::{Arc, Mutex}, +}; +use substrate_prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64}; + +/// We only support CounterVec for now. +/// TODO: add more when needed. +#[derive(Clone, Default)] +pub struct Metrics { + counter_vecs: Arc>>>, +} + +/// Runtime metrics wrapper. +#[derive(Clone)] +pub struct RuntimeMetricsProvider(Registry, Metrics); + +/// Metric label +#[derive(Clone)] +pub struct RuntimeMetricLabel(&'static str); + +impl RuntimeMetricLabel { + /// Returns the inner static string. + pub fn as_str(&self) -> &'static str { + self.0 + } +} + +impl From<&'static str> for RuntimeMetricLabel { + fn from(s: &'static str) -> Self { + Self(s) + } +} +impl RuntimeMetricsProvider { + /// Creates new instance. + pub fn new(metrics_registry: Registry) -> Self { + Self(metrics_registry, Metrics::default()) + } + + /// Register a counter vec metric. + pub fn register_countervec( + &self, + metric_name: &str, + description: &str, + label: RuntimeMetricLabel, + ) -> Result<(), PrometheusError> { + if !self.1.counter_vecs.lock().expect("bad lock").contains_key(metric_name) { + let counter_vec = register( + CounterVec::new(Opts::new(metric_name, description), &[label.as_str()])?, + &self.0, + )?; + + self.1 + .counter_vecs + .lock() + .expect("bad lock") + .insert(metric_name.to_owned(), counter_vec); + } + + Ok(()) + } + + /// Increment a counter vec by a value. + pub fn inc_counter_by(&self, name: &str, value: u64, label: RuntimeMetricLabel) { + match self.register_countervec(name, "default description", label.clone()) { + Ok(_) => { + // The metric is in the hashmap, unwrap won't panic. + self + .1 + .counter_vecs + .lock() + .expect("bad lock") + .get_mut(name) + .unwrap() + .with_label_values(&[label.as_str()]) + .inc_by(value); + }, + Err(_) => {}, + } + } +} + +impl sc_tracing::TraceHandler for RuntimeMetricsProvider { + fn handle_span(&self, _span: &sc_tracing::SpanDatum) {} + fn handle_event(&self, event: &sc_tracing::TraceEvent) { + // DUMMY impl + // TODO: parse TraceEvent to extract metric update information. + + println!("Hey it works: {:?}", event.values.string_values.get("params")); + self.inc_counter_by( + "runtime_metric_test", + 1024, + "test_label".into(), + ); + } +} + +/// Returns the custom profiling closure that we'll apply to the LoggerBuilder. +pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () { + |logger_builder, config| { + if config.prometheus_registry().is_none() { + return + } + + let registry = config.prometheus_registry().cloned().unwrap(); + let metrics_provider = RuntimeMetricsProvider::new(registry); + logger_builder.with_custom_profiling(vec![Box::new(metrics_provider)]); + } +} From f2fedf5c8778fa758780326c64dded13a4712441 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 7 Dec 2021 16:04:56 +0000 Subject: [PATCH 02/63] Runner changes Signed-off-by: Andrei Sandu --- cli/src/command.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index a862840cad2d..25ce6a699496 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -223,8 +223,17 @@ pub fn run_node(run: Cli, overseer_gen: impl service::OverseerGen) -> Result<()> run_node_inner(run, overseer_gen) } -fn run_node_inner(cli: Cli, overseer_gen: impl service::OverseerGen) -> Result<()> { - let runner = cli.create_runner(&cli.run.base).map_err(Error::from)?; +fn run_node_inner( + cli: Cli, + overseer_gen: impl service::OverseerGen, + logger_hook: F, +) -> Result<()> +where + F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), +{ + let runner = cli + .create_runner_with_logger_hook::(&cli.run.base, logger_hook) + .map_err(Error::from)?; let chain_spec = &runner.config().chain_spec; set_default_ss58_version(chain_spec); @@ -265,12 +274,18 @@ fn run_node_inner(cli: Cli, overseer_gen: impl service::OverseerGen) -> Result<( }) } +/// TODO: Start the node with support for publishing runtime metrics. +pub fn run_with_wasm_metrics() -> Result<()> { + Ok(()) +} + /// Parses polkadot specific CLI arguments and run the service. pub fn run() -> Result<()> { let cli = Cli::from_args(); match &cli.subcommand { - None => run_node_inner(cli, service::RealOverseerGen), + // TODO: gate by feature `runtime_metrics`. + None => run_node_inner(cli, service::RealOverseerGen, polkadot_node_metrics::logger_hook()), Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?) From 3932b89737264105fca43e647aea50c1fbbd430b Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 7 Dec 2021 16:05:16 +0000 Subject: [PATCH 03/63] Some sample metrics in paras_inherent Signed-off-by: Andrei Sandu --- Cargo.lock | 3 ++ runtime/parachains/src/paras_inherent/mod.rs | 42 +++++++++++++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1045dc148237..e536812b9332 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6352,6 +6352,9 @@ dependencies = [ "futures 0.3.18", "futures-timer 3.0.2", "metered-channel", + "sc-cli", + "sc-service", + "sc-tracing", "substrate-prometheus-endpoint", ] diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 86fd19772efd..cd8637bc2ec8 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -260,13 +260,11 @@ impl Pallet { parent_header, mut disputes, } = data; - - let parent_header_hash = parent_header.hash(); + sp_io::init_tracing(); log::debug!( target: LOG_TARGET, - "[enter_inner] parent_header={:?} bitfields.len(): {}, backed_candidates.len(): {}, disputes.len(): {}", - parent_header_hash, + "[enter] bitfields.len(): {}, backed_candidates.len(): {}, disputes.len() {}", signed_bitfields.len(), backed_candidates.len(), disputes.len() @@ -275,7 +273,7 @@ impl Pallet { // Check that the submitted parent header indeed corresponds to the previous block hash. let parent_hash = >::parent_hash(); ensure!( - parent_header_hash.as_ref() == parent_hash.as_ref(), + parent_header.hash().as_ref() == parent_hash.as_ref(), Error::::InvalidParentHeader, ); @@ -286,6 +284,14 @@ impl Pallet { let disputes_weight = dispute_statements_weight::(&disputes); let max_block_weight = ::BlockWeights::get().max_block; + sp_tracing::event!( + target: "metrics", + sp_tracing::Level::TRACE, + metric = "create_inherent_prefilter_weight", + op = "inc", + value = candidate_weight + bitfields_weight + disputes_weight + ); + // Potentially trim inherent data to ensure processing will be within weight limits let total_weight = { @@ -374,6 +380,14 @@ impl Pallet { disputed_bitfield }; + sp_tracing::event!( + target: "metrics", + sp_tracing::Level::TRACE, + metric = "create_inherent_bitfields_processed", + op = "inc", + value = signed_bitfields.len() + ); + // Process new availability bitfields, yielding any availability cores whose // work has now concluded. let freed_concluded = >::process_bitfields( @@ -404,6 +418,16 @@ impl Pallet { &scheduled[..], ); + + // TODO: define metrics macros. + sp_tracing::event!( + target: "metrics", + sp_tracing::Level::TRACE, + metric = "create_inherent_candidates_processed", + op = "inc", + value = backed_candidates.len() + ); + // Process backed candidates according to scheduled cores. let parent_storage_root = parent_header.state_root().clone(); let inclusion::ProcessedCandidates::<::Hash> { @@ -432,6 +456,14 @@ impl Pallet { // this is max config.ump_service_total_weight let _ump_weight = >::process_pending_upward_messages(); + sp_tracing::event!( + target: "metrics", + sp_tracing::Level::TRACE, + metric = "create_inherent_total_weight", + op = "inc", + value = total_weight + ); + Ok(Some(total_weight).into()) } } From c9099e9b5d0044f45e3ab8f51b0565679f0a6502 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 7 Dec 2021 16:05:41 +0000 Subject: [PATCH 04/63] update cargo toml Signed-off-by: Andrei Sandu --- Cargo.lock | 3 +++ Cargo.toml | 1 + cli/Cargo.toml | 3 +++ node/client/Cargo.toml | 6 ++++++ node/service/Cargo.toml | 8 ++++++++ runtime/kusama/Cargo.toml | 1 + runtime/parachains/Cargo.toml | 2 ++ runtime/polkadot/Cargo.toml | 1 + runtime/rococo/Cargo.toml | 2 ++ runtime/westend/Cargo.toml | 1 + 10 files changed, 28 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e536812b9332..b7b135eca1eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5864,9 +5864,11 @@ dependencies = [ "futures 0.3.18", "log", "polkadot-node-core-pvf", + "polkadot-node-metrics", "polkadot-service", "sc-cli", "sc-service", + "sc-tracing", "sp-core", "sp-trie", "structopt", @@ -6778,6 +6780,7 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", + "sp-tracing", "xcm", "xcm-executor", ] diff --git a/Cargo.toml b/Cargo.toml index 9e5bd3f7b64c..f0eca3339150 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,6 +116,7 @@ panic = "unwind" runtime-benchmarks= [ "polkadot-cli/runtime-benchmarks" ] try-runtime = [ "polkadot-cli/try-runtime" ] disputes = [ "polkadot-cli/disputes" ] +with-tracing = [ "polkadot-cli/with-tracing" ] # Configuration for building a .deb package - for use with `cargo-deb` [package.metadata.deb] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8d4dff1c8e3b..abde4f0dc933 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -27,6 +27,8 @@ frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", bran try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } +sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } +polkadot-node-metrics = { path = "../node/metrics" } # this crate is used only to enable `trie-memory-tracker` feature # see https://github.com/paritytech/substrate/pull/6745 @@ -62,3 +64,4 @@ rococo-native = [ "service/rococo-native" ] malus = [ "full-node", "service/malus" ] disputes = [ "service/disputes" ] +with-tracing = ["service/with-tracing"] diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index a17346f3eb08..59b6e8af928c 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -45,3 +45,9 @@ polkadot = ["polkadot-runtime"] kusama = ["kusama-runtime"] rococo = ["rococo-runtime"] westend = ["westend-runtime"] +with-tracing = [ + "rococo-runtime/with-tracing", + "kusama-runtime/with-tracing", + "westend-runtime/with-tracing", + "polkadot-runtime/with-tracing", +] diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index b82b01a5a1f7..cbce4c04471d 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -173,3 +173,11 @@ try-runtime = [ ] malus = ["full-node"] disputes = ["polkadot-node-core-dispute-coordinator/disputes"] +with-tracing = [ + "polkadot-client/with-tracing", + "rococo-runtime/with-tracing", + "westend-runtime/with-tracing", + "kusama-runtime/with-tracing", + "polkadot-runtime/with-tracing", + "polkadot-runtime-parachains/with-tracing" +] \ No newline at end of file diff --git a/runtime/kusama/Cargo.toml b/runtime/kusama/Cargo.toml index d535c0a8be7a..2e7cb557a07f 100644 --- a/runtime/kusama/Cargo.toml +++ b/runtime/kusama/Cargo.toml @@ -264,3 +264,4 @@ disable-runtime-api = [] on-chain-release-build = [ "sp-api/disable-logging", ] +with-tracing = ["frame-executive/with-tracing", "sp-io/with-tracing"] diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index b57ae12a1bf7..6b842a674adc 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -23,6 +23,7 @@ sp-session = { git = "https://github.com/paritytech/substrate", branch = "master sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } +sp-tracing = { version = "4.0.0-dev", branch = "master", git = "https://github.com/paritytech/substrate", default-features = false } pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -98,3 +99,4 @@ try-runtime = [ "pallet-timestamp/try-runtime", "pallet-vesting/try-runtime", ] +with-tracing = ["sp-tracing/with-tracing"] diff --git a/runtime/polkadot/Cargo.toml b/runtime/polkadot/Cargo.toml index a2511ad2db95..3bdbee095d7d 100644 --- a/runtime/polkadot/Cargo.toml +++ b/runtime/polkadot/Cargo.toml @@ -251,3 +251,4 @@ disable-runtime-api = [] on-chain-release-build = [ "sp-api/disable-logging", ] +with-tracing = ["frame-executive/with-tracing", "sp-io/with-tracing"] diff --git a/runtime/rococo/Cargo.toml b/runtime/rococo/Cargo.toml index e8d2d15ef502..e0fb2b40b516 100644 --- a/runtime/rococo/Cargo.toml +++ b/runtime/rococo/Cargo.toml @@ -203,3 +203,5 @@ try-runtime = [ "runtime-common/try-runtime", "pallet-multisig/try-runtime", ] + +with-tracing = ["runtime-parachains/with-tracing", "frame-executive/with-tracing", "sp-io/with-tracing"] \ No newline at end of file diff --git a/runtime/westend/Cargo.toml b/runtime/westend/Cargo.toml index 95dca2e3478e..41f2a43c490f 100644 --- a/runtime/westend/Cargo.toml +++ b/runtime/westend/Cargo.toml @@ -248,3 +248,4 @@ try-runtime = [ # runtime without clashing with the runtime API exported functions # in WASM. disable-runtime-api = [] +with-tracing = ["frame-executive/with-tracing", "sp-io/with-tracing"] From 21c967bb3b8abd86c55ca959e831b93fd9c9787c Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 7 Dec 2021 16:06:13 +0000 Subject: [PATCH 05/63] fmt Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index cd2eedcd8a9a..2251d95286de 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -38,7 +38,7 @@ pub struct RuntimeMetricsProvider(Registry, Metrics); /// Metric label #[derive(Clone)] pub struct RuntimeMetricLabel(&'static str); - + impl RuntimeMetricLabel { /// Returns the inner static string. pub fn as_str(&self) -> &'static str { @@ -85,15 +85,14 @@ impl RuntimeMetricsProvider { match self.register_countervec(name, "default description", label.clone()) { Ok(_) => { // The metric is in the hashmap, unwrap won't panic. - self - .1 - .counter_vecs - .lock() - .expect("bad lock") - .get_mut(name) - .unwrap() - .with_label_values(&[label.as_str()]) - .inc_by(value); + self.1 + .counter_vecs + .lock() + .expect("bad lock") + .get_mut(name) + .unwrap() + .with_label_values(&[label.as_str()]) + .inc_by(value); }, Err(_) => {}, } @@ -107,11 +106,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { // TODO: parse TraceEvent to extract metric update information. println!("Hey it works: {:?}", event.values.string_values.get("params")); - self.inc_counter_by( - "runtime_metric_test", - 1024, - "test_label".into(), - ); + self.inc_counter_by("runtime_metric_test", 1024, "test_label".into()); } } From b6205b2e8e5f9444057694a185a0b7a15c747798 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 7 Dec 2021 16:10:45 +0000 Subject: [PATCH 06/63] bug Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 2251d95286de..45a2bdef5dd1 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -106,6 +106,8 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { // TODO: parse TraceEvent to extract metric update information. println!("Hey it works: {:?}", event.values.string_values.get("params")); + // BUG: the metrics registered/updated here are not yet visibile in the + // Prometheus exporter, even if register/update calls are successful. self.inc_counter_by("runtime_metric_test", 1024, "test_label".into()); } } From e058dc1dc75c321f0e1b31ed38a9e414d662bae8 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 7 Dec 2021 16:19:09 +0000 Subject: [PATCH 07/63] more fmt after merge Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 2 +- runtime/parachains/src/paras_inherent/mod.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 45a2bdef5dd1..c19743941fc3 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -106,7 +106,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { // TODO: parse TraceEvent to extract metric update information. println!("Hey it works: {:?}", event.values.string_values.get("params")); - // BUG: the metrics registered/updated here are not yet visibile in the + // BUG: the metrics registered/updated here are not yet visibile in the // Prometheus exporter, even if register/update calls are successful. self.inc_counter_by("runtime_metric_test", 1024, "test_label".into()); } diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index cd8637bc2ec8..524973ce7fdd 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -292,7 +292,6 @@ impl Pallet { value = candidate_weight + bitfields_weight + disputes_weight ); - // Potentially trim inherent data to ensure processing will be within weight limits let total_weight = { if candidate_weight @@ -387,7 +386,7 @@ impl Pallet { op = "inc", value = signed_bitfields.len() ); - + // Process new availability bitfields, yielding any availability cores whose // work has now concluded. let freed_concluded = >::process_bitfields( @@ -418,7 +417,6 @@ impl Pallet { &scheduled[..], ); - // TODO: define metrics macros. sp_tracing::event!( target: "metrics", From 0d9760abd17448a2cf02057018bfcc2edbd422ee Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 13:01:16 +0000 Subject: [PATCH 08/63] Refactor metric prefix override Signed-off-by: Andrei Sandu --- cli/src/cli.rs | 8 ++++++++ cli/src/command.rs | 7 +++++-- node/metrics/src/runtime.rs | 1 - node/service/src/lib.rs | 11 ----------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index b6555db73e18..2af676ee775a 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -121,3 +121,11 @@ pub struct Cli { #[structopt(flatten)] pub run: RunCmd, } + +impl Cli { + /// Updates the prometheus metric prefix. + /// Must be called before `CliConfiguration::create_configuration()`. + pub fn update_prometheus_metric_prefix(&mut self, prefix: &'static str) { + self.run.base.prometheus_metric_prefix = prefix; + } +} \ No newline at end of file diff --git a/cli/src/command.rs b/cli/src/command.rs index 25ce6a699496..be9e207bc389 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -230,7 +230,7 @@ fn run_node_inner( ) -> Result<()> where F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), -{ +{ let runner = cli .create_runner_with_logger_hook::(&cli.run.base, logger_hook) .map_err(Error::from)?; @@ -281,7 +281,10 @@ pub fn run_with_wasm_metrics() -> Result<()> { /// Parses polkadot specific CLI arguments and run the service. pub fn run() -> Result<()> { - let cli = Cli::from_args(); + let mut cli: Cli = Cli::from_args(); + + // Override the default substrate metric prefix. + cli.update_prometheus_metric_prefix("polkadot"); match &cli.subcommand { // TODO: gate by feature `runtime_metrics`. diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index c19743941fc3..5a31cb3bd77f 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -118,7 +118,6 @@ pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Con if config.prometheus_registry().is_none() { return } - let registry = config.prometheus_registry().cloned().unwrap(); let metrics_provider = RuntimeMetricsProvider::new(registry); logger_builder.with_custom_profiling(vec![Box::new(metrics_provider)]); diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 16e1fcd7432a..62779a3f3019 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -272,15 +272,6 @@ impl IdentifyVariant for Box { } } -// If we're using prometheus, use a registry with a prefix of `polkadot`. -fn set_prometheus_registry(config: &mut Configuration) -> Result<(), Error> { - if let Some(PrometheusConfig { registry, .. }) = config.prometheus_config.as_mut() { - *registry = Registry::new_custom(Some("polkadot".into()), None)?; - } - - Ok(()) -} - /// Initialize the `Jeager` collector. The destination must listen /// on the given address and port for `UDP` packets. #[cfg(any(test, feature = "full-node"))] @@ -344,8 +335,6 @@ where RuntimeApiCollection>, ExecutorDispatch: NativeExecutionDispatch + 'static, { - set_prometheus_registry(config)?; - let telemetry = config .telemetry_endpoints .clone() From ae187f792a3d56350f657ff3b5842c5af4cbf9db Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 13:01:47 +0000 Subject: [PATCH 09/63] fmt Signed-off-by: Andrei Sandu --- cli/src/cli.rs | 2 +- cli/src/command.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 2af676ee775a..3a25354d562c 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -128,4 +128,4 @@ impl Cli { pub fn update_prometheus_metric_prefix(&mut self, prefix: &'static str) { self.run.base.prometheus_metric_prefix = prefix; } -} \ No newline at end of file +} diff --git a/cli/src/command.rs b/cli/src/command.rs index be9e207bc389..82e476db7574 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -230,7 +230,7 @@ fn run_node_inner( ) -> Result<()> where F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), -{ +{ let runner = cli .create_runner_with_logger_hook::(&cli.run.base, logger_hook) .map_err(Error::from)?; From 3189117571bf3eba6fa67c58e272de605691bacf Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 13:02:11 +0000 Subject: [PATCH 10/63] remove bug comment Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 5a31cb3bd77f..be8cb6c40cf3 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -104,10 +104,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { fn handle_event(&self, event: &sc_tracing::TraceEvent) { // DUMMY impl // TODO: parse TraceEvent to extract metric update information. - println!("Hey it works: {:?}", event.values.string_values.get("params")); - // BUG: the metrics registered/updated here are not yet visibile in the - // Prometheus exporter, even if register/update calls are successful. self.inc_counter_by("runtime_metric_test", 1024, "test_label".into()); } } From 561c4149a9dc306436eecf0f51d6e76841ca960e Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 16:41:36 +0000 Subject: [PATCH 11/63] Add runtime metric primitives Signed-off-by: Andrei Sandu --- primitives/src/v0.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/primitives/src/v0.rs b/primitives/src/v0.rs index 64163d04bdd7..2928f814782e 100644 --- a/primitives/src/v0.rs +++ b/primitives/src/v0.rs @@ -923,6 +923,30 @@ pub mod fisherman { } } +// TODO: add feature gate. +/// Runtime metric operations. +#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, TypeInfo)] +pub enum RuntimeMetricOp { + /// Increment metric by value. + Increment(u64), +} + +/// Runtime metric update event. +#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, TypeInfo)] +pub struct RuntimeMetricUpdate { + /// The name of the metric. + pub metric_name: Vec, + /// The operation applied to the metric. + pub op: RuntimeMetricOp, +} + +impl RuntimeMetricUpdate { + /// Returns the metric name. + pub fn metric_name(&self) -> &str { + unsafe { sp_std::str::from_utf8_unchecked(&self.metric_name) } + } +} + #[cfg(test)] mod tests { use super::*; From bf5e5ebc49d76d29a75608a075f1a79fbf4468e5 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 16:49:08 +0000 Subject: [PATCH 12/63] Impl trace event parsing Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index be8cb6c40cf3..3214bec640b5 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -23,6 +23,8 @@ use std::{ sync::{Arc, Mutex}, }; use substrate_prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64}; +use primitives::v0::{RuntimeMetricUpdate, RuntimeMetricOp}; +use codec::Decode; /// We only support CounterVec for now. /// TODO: add more when needed. @@ -35,7 +37,11 @@ pub struct Metrics { #[derive(Clone)] pub struct RuntimeMetricsProvider(Registry, Metrics); -/// Metric label +/// A set of metric labels. +#[derive(Clone)] +pub struct RuntimeMetricLabels(Vec); + +/// A metric label value. #[derive(Clone)] pub struct RuntimeMetricLabel(&'static str); @@ -102,10 +108,33 @@ impl RuntimeMetricsProvider { impl sc_tracing::TraceHandler for RuntimeMetricsProvider { fn handle_span(&self, _span: &sc_tracing::SpanDatum) {} fn handle_event(&self, event: &sc_tracing::TraceEvent) { - // DUMMY impl - // TODO: parse TraceEvent to extract metric update information. - println!("Hey it works: {:?}", event.values.string_values.get("params")); - self.inc_counter_by("runtime_metric_test", 1024, "test_label".into()); + if event.target.ne("metrics") { + return + } + + if let Some(update_op_str) = event.values.string_values.get("params").cloned() { + // TODO: Fix ugly hack because the payload comes in as a formatted string. + const SKIP_CHARS: usize = " { update_op: ".len(); + + match RuntimeMetricUpdate::decode(&mut update_op_str[SKIP_CHARS..].as_bytes()) { + Ok(update_op) => { + self.parse_metric_update(update_op); + }, + Err(e) => { + tracing::error!("TraceEvent decode failed: {:?}", e); + } + } + } + } +} + +impl RuntimeMetricsProvider { + fn parse_metric_update(&self, update: RuntimeMetricUpdate) { + match update.op { + RuntimeMetricOp::Increment(value) => { + self.inc_counter_by(update.metric_name(), value, "test_label".into()); + } + } } } From e3385de52be8decbb715c6846010cfc39cbb74a0 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 16:50:01 +0000 Subject: [PATCH 13/63] Update metrics Signed-off-by: Andrei Sandu --- node/metrics/Cargo.toml | 4 ++ runtime/parachains/src/paras_inherent/mod.rs | 69 ++++++++++++-------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index 6062801438c1..830677a94b71 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -8,6 +8,7 @@ description = "Subsystem traits and message definitions" [dependencies] futures = "0.3.17" futures-timer = "3.0.2" +tracing = "0.1.29" metered-channel = { path = "../metered-channel" } @@ -15,6 +16,9 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } +codec = { package = "parity-scale-codec", version = "2.2.0" } +sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } +primitives = { package = "polkadot-primitives", path = "../../primitives/" } [features] default = [] diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 524973ce7fdd..44b915ec1918 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -55,6 +55,40 @@ use sp_std::{ vec::Vec, }; +// TODO: Find a better place for all of this stuff: +#[cfg(not(feature = "std"))] +use primitives::v0::{RuntimeMetricUpdate, RuntimeMetricOp}; + +// TODO: implement a define_metric macro that builds a metric object +// with the Prometheus interface. +#[cfg(not(feature = "std"))] +/// Increment counter vec metric by specified value. +macro_rules! inc_counter_vec { + ($metric:ident, $value:expr) => { + let metric_update = RuntimeMetricUpdate { + metric_name: sp_std::vec::Vec::from(stringify!($metric)), + op: RuntimeMetricOp::Increment($value.try_into().unwrap_or(0)) + }.encode(); + + // This is safe, we only care about the metric name being a valid utf8 str, + // which is enforced above. + unsafe { + let update_op = sp_std::str::from_utf8_unchecked(&metric_update); + + sp_tracing::event!( + target: "metrics", + sp_tracing::Level::TRACE, + update_op + ); + } + }; +} + +#[cfg(feature = "std")] +macro_rules! inc_counter_vec { + ($metric:ident, $value:expr) => {} +} + mod misc; mod weights; @@ -284,13 +318,8 @@ impl Pallet { let disputes_weight = dispute_statements_weight::(&disputes); let max_block_weight = ::BlockWeights::get().max_block; - sp_tracing::event!( - target: "metrics", - sp_tracing::Level::TRACE, - metric = "create_inherent_prefilter_weight", - op = "inc", - value = candidate_weight + bitfields_weight + disputes_weight - ); + + inc_counter_vec!(create_inherent_prefilter_weight, candidate_weight + bitfields_weight + disputes_weight); // Potentially trim inherent data to ensure processing will be within weight limits let total_weight = { @@ -379,13 +408,7 @@ impl Pallet { disputed_bitfield }; - sp_tracing::event!( - target: "metrics", - sp_tracing::Level::TRACE, - metric = "create_inherent_bitfields_processed", - op = "inc", - value = signed_bitfields.len() - ); + inc_counter_vec!(create_inherent_bitfields_processed, signed_bitfields.len()); // Process new availability bitfields, yielding any availability cores whose // work has now concluded. @@ -417,14 +440,8 @@ impl Pallet { &scheduled[..], ); - // TODO: define metrics macros. - sp_tracing::event!( - target: "metrics", - sp_tracing::Level::TRACE, - metric = "create_inherent_candidates_processed", - op = "inc", - value = backed_candidates.len() - ); + + inc_counter_vec!(create_inherent_candidates_processed, backed_candidates.len()); // Process backed candidates according to scheduled cores. let parent_storage_root = parent_header.state_root().clone(); @@ -454,13 +471,7 @@ impl Pallet { // this is max config.ump_service_total_weight let _ump_weight = >::process_pending_upward_messages(); - sp_tracing::event!( - target: "metrics", - sp_tracing::Level::TRACE, - metric = "create_inherent_total_weight", - op = "inc", - value = total_weight - ); + inc_counter_vec!(create_inherent_total_weight, total_weight); Ok(Some(total_weight).into()) } From 267fc852c2b09645d95db43e36930260e0a536f2 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 16:50:23 +0000 Subject: [PATCH 14/63] cargo lock Signed-off-by: Andrei Sandu --- Cargo.lock | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b7b135eca1eb..ddb161439617 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6354,10 +6354,14 @@ dependencies = [ "futures 0.3.18", "futures-timer 3.0.2", "metered-channel", + "parity-scale-codec", + "polkadot-primitives", "sc-cli", "sc-service", "sc-tracing", + "sp-tracing", "substrate-prometheus-endpoint", + "tracing", ] [[package]] From 82356e532b704650615b4c068d33ac20b0651eaf Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 16:50:53 +0000 Subject: [PATCH 15/63] fmt Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 8 ++++---- runtime/parachains/src/paras_inherent/mod.rs | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 3214bec640b5..9e0a0b595c92 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -18,13 +18,13 @@ //! //! Builds on top of Substrate wasm tracing support. +use codec::Decode; +use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; use std::{ collections::hash_map::HashMap, sync::{Arc, Mutex}, }; use substrate_prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64}; -use primitives::v0::{RuntimeMetricUpdate, RuntimeMetricOp}; -use codec::Decode; /// We only support CounterVec for now. /// TODO: add more when needed. @@ -122,7 +122,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { }, Err(e) => { tracing::error!("TraceEvent decode failed: {:?}", e); - } + }, } } } @@ -133,7 +133,7 @@ impl RuntimeMetricsProvider { match update.op { RuntimeMetricOp::Increment(value) => { self.inc_counter_by(update.metric_name(), value, "test_label".into()); - } + }, } } } diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 44b915ec1918..017e244cc2c6 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -57,7 +57,7 @@ use sp_std::{ // TODO: Find a better place for all of this stuff: #[cfg(not(feature = "std"))] -use primitives::v0::{RuntimeMetricUpdate, RuntimeMetricOp}; +use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; // TODO: implement a define_metric macro that builds a metric object // with the Prometheus interface. @@ -69,12 +69,12 @@ macro_rules! inc_counter_vec { metric_name: sp_std::vec::Vec::from(stringify!($metric)), op: RuntimeMetricOp::Increment($value.try_into().unwrap_or(0)) }.encode(); - - // This is safe, we only care about the metric name being a valid utf8 str, + + // This is safe, we only care about the metric name being a valid utf8 str, // which is enforced above. unsafe { let update_op = sp_std::str::from_utf8_unchecked(&metric_update); - + sp_tracing::event!( target: "metrics", sp_tracing::Level::TRACE, @@ -86,7 +86,7 @@ macro_rules! inc_counter_vec { #[cfg(feature = "std")] macro_rules! inc_counter_vec { - ($metric:ident, $value:expr) => {} + ($metric:ident, $value:expr) => {}; } mod misc; @@ -319,7 +319,10 @@ impl Pallet { let max_block_weight = ::BlockWeights::get().max_block; - inc_counter_vec!(create_inherent_prefilter_weight, candidate_weight + bitfields_weight + disputes_weight); + inc_counter_vec!( + create_inherent_prefilter_weight, + candidate_weight + bitfields_weight + disputes_weight + ); // Potentially trim inherent data to ensure processing will be within weight limits let total_weight = { @@ -440,7 +443,6 @@ impl Pallet { &scheduled[..], ); - inc_counter_vec!(create_inherent_candidates_processed, backed_candidates.len()); // Process backed candidates according to scheduled cores. From 41c4034ebe90b47fbb2a64823cd5588bfff04c81 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 8 Dec 2021 19:24:55 +0000 Subject: [PATCH 16/63] Fix target check Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 9e0a0b595c92..ae2afd54b624 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -108,7 +108,8 @@ impl RuntimeMetricsProvider { impl sc_tracing::TraceHandler for RuntimeMetricsProvider { fn handle_span(&self, _span: &sc_tracing::SpanDatum) {} fn handle_event(&self, event: &sc_tracing::TraceEvent) { - if event.target.ne("metrics") { + let target = event.values.string_values.get("target"); + if target.is_none() || target.unwrap().ne("metrics") { return } From 6d8cb157b63844dc4f4b7db64b75aeee53b468c9 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 16:07:33 +0000 Subject: [PATCH 17/63] Runtime metrics primitives Signed-off-by: Andrei Sandu --- primitives/src/v0.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/primitives/src/v0.rs b/primitives/src/v0.rs index 2928f814782e..435e08a0ad27 100644 --- a/primitives/src/v0.rs +++ b/primitives/src/v0.rs @@ -947,6 +947,50 @@ impl RuntimeMetricUpdate { } } +/// A set of metric labels. +pub type RuntimeMetricLabels = Vec; + +/// A metric label. +#[derive(Clone, Default)] +pub struct RuntimeMetricLabel(Vec); + +/// A metric label value. +#[derive(Clone, Default)] +pub struct RuntimeMetricLabelValue(Vec); + +/// A set of metric label values. +pub type RuntimeMetricLabelValues = Vec; + +/// Trait for converting Vec to &str. +pub trait AsStr { + /// Return a str reference. + fn as_str(&self) -> Option<&str>; +} + +impl AsStr for RuntimeMetricLabel { + fn as_str(&self) -> Option<&str> { + sp_std::str::from_utf8(&self.0).ok() + } +} + +impl AsStr for RuntimeMetricLabelValue { + fn as_str(&self) -> Option<&str> { + sp_std::str::from_utf8(&self.0).ok() + } +} + +impl From<&'static str> for RuntimeMetricLabel { + fn from(s: &'static str) -> Self { + Self(s.as_bytes().to_vec()) + } +} + +impl From<&'static str> for RuntimeMetricLabelValue { + fn from(s: &'static str) -> Self { + Self(s.as_bytes().to_vec()) + } +} + #[cfg(test)] mod tests { use super::*; From d2381ea06086ce42e3f0dbc206a73f39f23689c2 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 16:07:58 +0000 Subject: [PATCH 18/63] Review feedback Signed-off-by: Andrei Sandu --- cli/src/cli.rs | 7 ------- cli/src/command.rs | 3 --- 2 files changed, 10 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 3a25354d562c..384aba8c765d 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -122,10 +122,3 @@ pub struct Cli { pub run: RunCmd, } -impl Cli { - /// Updates the prometheus metric prefix. - /// Must be called before `CliConfiguration::create_configuration()`. - pub fn update_prometheus_metric_prefix(&mut self, prefix: &'static str) { - self.run.base.prometheus_metric_prefix = prefix; - } -} diff --git a/cli/src/command.rs b/cli/src/command.rs index 82e476db7574..34ea43e0121f 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -283,9 +283,6 @@ pub fn run_with_wasm_metrics() -> Result<()> { pub fn run() -> Result<()> { let mut cli: Cli = Cli::from_args(); - // Override the default substrate metric prefix. - cli.update_prometheus_metric_prefix("polkadot"); - match &cli.subcommand { // TODO: gate by feature `runtime_metrics`. None => run_node_inner(cli, service::RealOverseerGen, polkadot_node_metrics::logger_hook()), From 155c9b719e1e92a2e05f0bc2a6bdc583d3ca0ea0 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 16:08:31 +0000 Subject: [PATCH 19/63] Runtime metrics crate Signed-off-by: Andrei Sandu --- runtime/metrics/Cargo.toml | 22 +++++++++ runtime/metrics/src/lib.rs | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 runtime/metrics/Cargo.toml create mode 100644 runtime/metrics/src/lib.rs diff --git a/runtime/metrics/Cargo.toml b/runtime/metrics/Cargo.toml new file mode 100644 index 000000000000..c00c6a144fbe --- /dev/null +++ b/runtime/metrics/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "polkadot-runtime-metrics" +version = "0.9.13" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false} +sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +parity-scale-codec = { version = "2.3.1", default-features = false } +primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false } + +[features] +default = ["std"] +no_std = [] +std = [ + "sp-std/std", + "sp-tracing/std", + "parity-scale-codec/std", + "primitives/std", +] +with-tracing = ["sp-tracing/with-tracing"] diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs new file mode 100644 index 000000000000..d3108318e64b --- /dev/null +++ b/runtime/metrics/src/lib.rs @@ -0,0 +1,91 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Runtime metric interface similar to native Prometheus metrics. + +#![cfg_attr(not(feature = "std"), no_std)] +use primitives::v0::{RuntimeMetricLabels, RuntimeMetricLabelValues}; + +#[cfg(not(feature = "std"))] +use parity_scale_codec::Encode; + +#[cfg(not(feature = "std"))] +use primitives::v0::{RuntimeMetricUpdate,RuntimeMetricOp}; + +#[cfg(not(feature = "std"))] +pub struct CounterVec { + name: &'static str, + labels: RuntimeMetricLabels, + label_values: RuntimeMetricLabelValues, +} + +#[cfg(not(feature = "std"))] +impl CounterVec { + /// Create a new counter vec metric. + pub fn new(name: &'static str) -> Self { + Self::new_with_labels(name, sp_std::vec::Vec::new()) + } + + pub fn new_with_labels(name: &'static str, labels: RuntimeMetricLabels) -> Self { + CounterVec { + name, + labels, + label_values: RuntimeMetricLabelValues::default(), + } + } + /// Set label values. + pub fn with_label_values(&mut self, label_values: RuntimeMetricLabelValues) -> &Self { + self.label_values = label_values; + self + } + + /// Increment metric by value. + pub fn inc_by(&mut self, value: u64) { + let metric_update = RuntimeMetricUpdate { + metric_name: sp_std::vec::Vec::from(self.name), + op: RuntimeMetricOp::Increment(value) + }.encode(); + + // This is safe, we only care about the metric name which is static str. + unsafe { + let update_op = sp_std::str::from_utf8_unchecked(&metric_update); + + sp_tracing::event!( + target: "metrics", + sp_tracing::Level::TRACE, + update_op = update_op + ); + } + + self.label_values.clear(); + } +} + +#[cfg(feature = "std")] +pub struct CounterVec; + +/// Dummy implementation. +#[cfg(feature = "std")] +impl CounterVec { + pub fn new(_: &'static str) -> Self { CounterVec } + pub fn new_with_labels(_: &'static str, _: RuntimeMetricLabels) -> Self { CounterVec } + + pub fn with_label_values(&mut self, _: RuntimeMetricLabelValues) -> &Self { + self + } + + pub fn inc_by(&mut self, _: u64) {} +} \ No newline at end of file From 2f2780563c6c76392d2507600a4e0c21b1caee37 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 16:08:49 +0000 Subject: [PATCH 20/63] Node side runtime metric changes Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index ae2afd54b624..df5980ee4e20 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -19,7 +19,7 @@ //! Builds on top of Substrate wasm tracing support. use codec::Decode; -use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; +use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate, RuntimeMetricLabel, AsStr}; use std::{ collections::hash_map::HashMap, sync::{Arc, Mutex}, @@ -32,31 +32,10 @@ use substrate_prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, pub struct Metrics { counter_vecs: Arc>>>, } - /// Runtime metrics wrapper. #[derive(Clone)] pub struct RuntimeMetricsProvider(Registry, Metrics); -/// A set of metric labels. -#[derive(Clone)] -pub struct RuntimeMetricLabels(Vec); - -/// A metric label value. -#[derive(Clone)] -pub struct RuntimeMetricLabel(&'static str); - -impl RuntimeMetricLabel { - /// Returns the inner static string. - pub fn as_str(&self) -> &'static str { - self.0 - } -} - -impl From<&'static str> for RuntimeMetricLabel { - fn from(s: &'static str) -> Self { - Self(s) - } -} impl RuntimeMetricsProvider { /// Creates new instance. pub fn new(metrics_registry: Registry) -> Self { @@ -72,7 +51,7 @@ impl RuntimeMetricsProvider { ) -> Result<(), PrometheusError> { if !self.1.counter_vecs.lock().expect("bad lock").contains_key(metric_name) { let counter_vec = register( - CounterVec::new(Opts::new(metric_name, description), &[label.as_str()])?, + CounterVec::new(Opts::new(metric_name, description), &[label.as_str().expect("invalid metric label")])?, &self.0, )?; @@ -97,7 +76,7 @@ impl RuntimeMetricsProvider { .expect("bad lock") .get_mut(name) .unwrap() - .with_label_values(&[label.as_str()]) + .with_label_values(&[label.as_str().expect("invalid metric label")]) .inc_by(value); }, Err(_) => {}, @@ -108,20 +87,21 @@ impl RuntimeMetricsProvider { impl sc_tracing::TraceHandler for RuntimeMetricsProvider { fn handle_span(&self, _span: &sc_tracing::SpanDatum) {} fn handle_event(&self, event: &sc_tracing::TraceEvent) { - let target = event.values.string_values.get("target"); - if target.is_none() || target.unwrap().ne("metrics") { + if event.values.string_values.get("target").unwrap_or(&String::default()).ne("metrics") { return } if let Some(update_op_str) = event.values.string_values.get("params").cloned() { // TODO: Fix ugly hack because the payload comes in as a formatted string. const SKIP_CHARS: usize = " { update_op: ".len(); - + println!("Decoding: {:?}", update_op_str); match RuntimeMetricUpdate::decode(&mut update_op_str[SKIP_CHARS..].as_bytes()) { Ok(update_op) => { + println!("Received metric: {:?}", update_op); self.parse_metric_update(update_op); }, Err(e) => { + println!("Failed to decode metric: {:?}", e); tracing::error!("TraceEvent decode failed: {:?}", e); }, } @@ -147,6 +127,6 @@ pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Con } let registry = config.prometheus_registry().cloned().unwrap(); let metrics_provider = RuntimeMetricsProvider::new(registry); - logger_builder.with_custom_profiling(vec![Box::new(metrics_provider)]); + logger_builder.with_custom_profiling(Box::new(metrics_provider)); } } From cfd62ab5ddea2da0f933e82cb14891e151556451 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 16:09:17 +0000 Subject: [PATCH 21/63] use runtime CounterVec instead of macro Signed-off-by: Andrei Sandu --- runtime/parachains/Cargo.toml | 4 +- runtime/parachains/src/paras_inherent/mod.rs | 84 ++++++++++---------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 6b842a674adc..bb0a663cc269 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -43,6 +43,7 @@ primitives = { package = "polkadot-primitives", path = "../../primitives", defau rand = { version = "0.8.3", default-features = false } rand_chacha = { version = "0.3.1", default-features = false } +polkadot-runtime-metrics = { path = "../metrics", default-features = false} [dev-dependencies] futures = "0.3.17" @@ -83,6 +84,7 @@ std = [ "xcm/std", "xcm-executor/std", "log/std", + "polkadot-runtime-metrics/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -99,4 +101,4 @@ try-runtime = [ "pallet-timestamp/try-runtime", "pallet-vesting/try-runtime", ] -with-tracing = ["sp-tracing/with-tracing"] +with-tracing = ["sp-tracing/with-tracing", "polkadot-runtime-metrics/with-tracing"] diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 017e244cc2c6..34b5262d97c1 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -55,39 +55,41 @@ use sp_std::{ vec::Vec, }; -// TODO: Find a better place for all of this stuff: -#[cfg(not(feature = "std"))] -use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; - -// TODO: implement a define_metric macro that builds a metric object -// with the Prometheus interface. -#[cfg(not(feature = "std"))] -/// Increment counter vec metric by specified value. -macro_rules! inc_counter_vec { - ($metric:ident, $value:expr) => { - let metric_update = RuntimeMetricUpdate { - metric_name: sp_std::vec::Vec::from(stringify!($metric)), - op: RuntimeMetricOp::Increment($value.try_into().unwrap_or(0)) - }.encode(); - - // This is safe, we only care about the metric name being a valid utf8 str, - // which is enforced above. - unsafe { - let update_op = sp_std::str::from_utf8_unchecked(&metric_update); - - sp_tracing::event!( - target: "metrics", - sp_tracing::Level::TRACE, - update_op - ); - } - }; -} +use polkadot_runtime_metrics::CounterVec; -#[cfg(feature = "std")] -macro_rules! inc_counter_vec { - ($metric:ident, $value:expr) => {}; -} +// TODO: Find a better place for all of this stuff: +// #[cfg(not(feature = "std"))] +// use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; + +// // TODO: implement a define_metric macro that builds a metric object +// // with the Prometheus interface. +// #[cfg(not(feature = "std"))] +// /// Increment counter vec metric by specified value. +// macro_rules! inc_counter_vec { +// ($metric:ident, $value:expr) => { +// let metric_update = RuntimeMetricUpdate { +// metric_name: sp_std::vec::Vec::from(stringify!($metric)), +// op: RuntimeMetricOp::Increment($value.try_into().unwrap_or(0)) +// }.encode(); + +// // This is safe, we only care about the metric name being a valid utf8 str, +// // which is enforced above. +// unsafe { +// let update_op = sp_std::str::from_utf8_unchecked(&metric_update); + +// sp_tracing::event!( +// target: "metrics", +// sp_tracing::Level::TRACE, +// update_op +// ); +// } +// }; +// } + +// #[cfg(feature = "std")] +// macro_rules! inc_counter_vec { +// ($metric:ident, $value:expr) => {}; +// } mod misc; mod weights; @@ -295,6 +297,10 @@ impl Pallet { mut disputes, } = data; sp_io::init_tracing(); + let mut prefilter_weight_metric = CounterVec::new("polkadot_create_inherent_prefilter_weight"); + let mut bitfields_processed_metric = CounterVec::new("polkadot_create_inherent_bitfields_processed"); + let mut candidates_processed_metric = CounterVec::new("polkadot_create_inherent_candidates_processed"); + let mut total_weight_metric = CounterVec::new("create_inherent_total_weight"); log::debug!( target: LOG_TARGET, @@ -319,10 +325,7 @@ impl Pallet { let max_block_weight = ::BlockWeights::get().max_block; - inc_counter_vec!( - create_inherent_prefilter_weight, - candidate_weight + bitfields_weight + disputes_weight - ); + prefilter_weight_metric.inc_by(candidate_weight + bitfields_weight + disputes_weight); // Potentially trim inherent data to ensure processing will be within weight limits let total_weight = { @@ -411,8 +414,7 @@ impl Pallet { disputed_bitfield }; - inc_counter_vec!(create_inherent_bitfields_processed, signed_bitfields.len()); - + bitfields_processed_metric.inc_by(signed_bitfields.len().try_into().unwrap_or_default()); // Process new availability bitfields, yielding any availability cores whose // work has now concluded. let freed_concluded = >::process_bitfields( @@ -443,8 +445,8 @@ impl Pallet { &scheduled[..], ); - inc_counter_vec!(create_inherent_candidates_processed, backed_candidates.len()); - + candidates_processed_metric.inc_by(backed_candidates.len().try_into().unwrap_or_default()); + // Process backed candidates according to scheduled cores. let parent_storage_root = parent_header.state_root().clone(); let inclusion::ProcessedCandidates::<::Hash> { @@ -473,7 +475,7 @@ impl Pallet { // this is max config.ump_service_total_weight let _ump_weight = >::process_pending_upward_messages(); - inc_counter_vec!(create_inherent_total_weight, total_weight); + total_weight_metric.inc_by(total_weight); Ok(Some(total_weight).into()) } From e6855e114eb8f9cb4fedd11590035059001542cf Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 16:11:07 +0000 Subject: [PATCH 22/63] fmt nice Signed-off-by: Andrei Sandu --- cli/src/cli.rs | 1 - node/metrics/src/runtime.rs | 15 +++++++++--- runtime/metrics/src/lib.rs | 25 ++++++++++---------- runtime/parachains/src/paras_inherent/mod.rs | 11 +++++---- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 384aba8c765d..b6555db73e18 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -121,4 +121,3 @@ pub struct Cli { #[structopt(flatten)] pub run: RunCmd, } - diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index df5980ee4e20..9731c9c37bc0 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -19,7 +19,7 @@ //! Builds on top of Substrate wasm tracing support. use codec::Decode; -use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate, RuntimeMetricLabel, AsStr}; +use primitives::v0::{AsStr, RuntimeMetricLabel, RuntimeMetricOp, RuntimeMetricUpdate}; use std::{ collections::hash_map::HashMap, sync::{Arc, Mutex}, @@ -51,7 +51,10 @@ impl RuntimeMetricsProvider { ) -> Result<(), PrometheusError> { if !self.1.counter_vecs.lock().expect("bad lock").contains_key(metric_name) { let counter_vec = register( - CounterVec::new(Opts::new(metric_name, description), &[label.as_str().expect("invalid metric label")])?, + CounterVec::new( + Opts::new(metric_name, description), + &[label.as_str().expect("invalid metric label")], + )?, &self.0, )?; @@ -87,7 +90,13 @@ impl RuntimeMetricsProvider { impl sc_tracing::TraceHandler for RuntimeMetricsProvider { fn handle_span(&self, _span: &sc_tracing::SpanDatum) {} fn handle_event(&self, event: &sc_tracing::TraceEvent) { - if event.values.string_values.get("target").unwrap_or(&String::default()).ne("metrics") { + if event + .values + .string_values + .get("target") + .unwrap_or(&String::default()) + .ne("metrics") + { return } diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index d3108318e64b..1f17705e7085 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -17,13 +17,13 @@ //! Runtime metric interface similar to native Prometheus metrics. #![cfg_attr(not(feature = "std"), no_std)] -use primitives::v0::{RuntimeMetricLabels, RuntimeMetricLabelValues}; +use primitives::v0::{RuntimeMetricLabelValues, RuntimeMetricLabels}; #[cfg(not(feature = "std"))] use parity_scale_codec::Encode; #[cfg(not(feature = "std"))] -use primitives::v0::{RuntimeMetricUpdate,RuntimeMetricOp}; +use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; #[cfg(not(feature = "std"))] pub struct CounterVec { @@ -40,11 +40,7 @@ impl CounterVec { } pub fn new_with_labels(name: &'static str, labels: RuntimeMetricLabels) -> Self { - CounterVec { - name, - labels, - label_values: RuntimeMetricLabelValues::default(), - } + CounterVec { name, labels, label_values: RuntimeMetricLabelValues::default() } } /// Set label values. pub fn with_label_values(&mut self, label_values: RuntimeMetricLabelValues) -> &Self { @@ -56,8 +52,9 @@ impl CounterVec { pub fn inc_by(&mut self, value: u64) { let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(self.name), - op: RuntimeMetricOp::Increment(value) - }.encode(); + op: RuntimeMetricOp::Increment(value), + } + .encode(); // This is safe, we only care about the metric name which is static str. unsafe { @@ -80,12 +77,16 @@ pub struct CounterVec; /// Dummy implementation. #[cfg(feature = "std")] impl CounterVec { - pub fn new(_: &'static str) -> Self { CounterVec } - pub fn new_with_labels(_: &'static str, _: RuntimeMetricLabels) -> Self { CounterVec } + pub fn new(_: &'static str) -> Self { + CounterVec + } + pub fn new_with_labels(_: &'static str, _: RuntimeMetricLabels) -> Self { + CounterVec + } pub fn with_label_values(&mut self, _: RuntimeMetricLabelValues) -> &Self { self } pub fn inc_by(&mut self, _: u64) {} -} \ No newline at end of file +} diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 34b5262d97c1..9676897bdf44 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -297,9 +297,12 @@ impl Pallet { mut disputes, } = data; sp_io::init_tracing(); - let mut prefilter_weight_metric = CounterVec::new("polkadot_create_inherent_prefilter_weight"); - let mut bitfields_processed_metric = CounterVec::new("polkadot_create_inherent_bitfields_processed"); - let mut candidates_processed_metric = CounterVec::new("polkadot_create_inherent_candidates_processed"); + let mut prefilter_weight_metric = + CounterVec::new("polkadot_create_inherent_prefilter_weight"); + let mut bitfields_processed_metric = + CounterVec::new("polkadot_create_inherent_bitfields_processed"); + let mut candidates_processed_metric = + CounterVec::new("polkadot_create_inherent_candidates_processed"); let mut total_weight_metric = CounterVec::new("create_inherent_total_weight"); log::debug!( @@ -446,7 +449,7 @@ impl Pallet { ); candidates_processed_metric.inc_by(backed_candidates.len().try_into().unwrap_or_default()); - + // Process backed candidates according to scheduled cores. let parent_storage_root = parent_header.state_root().clone(); let inclusion::ProcessedCandidates::<::Hash> { From 90b78c87de9d46a7be0bcaa292655c9406fb8d93 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 16:12:13 +0000 Subject: [PATCH 23/63] remove dead code Signed-off-by: Andrei Sandu --- runtime/parachains/src/paras_inherent/mod.rs | 35 -------------------- 1 file changed, 35 deletions(-) diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 9676897bdf44..802a29a94a4b 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -56,41 +56,6 @@ use sp_std::{ }; use polkadot_runtime_metrics::CounterVec; - -// TODO: Find a better place for all of this stuff: -// #[cfg(not(feature = "std"))] -// use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; - -// // TODO: implement a define_metric macro that builds a metric object -// // with the Prometheus interface. -// #[cfg(not(feature = "std"))] -// /// Increment counter vec metric by specified value. -// macro_rules! inc_counter_vec { -// ($metric:ident, $value:expr) => { -// let metric_update = RuntimeMetricUpdate { -// metric_name: sp_std::vec::Vec::from(stringify!($metric)), -// op: RuntimeMetricOp::Increment($value.try_into().unwrap_or(0)) -// }.encode(); - -// // This is safe, we only care about the metric name being a valid utf8 str, -// // which is enforced above. -// unsafe { -// let update_op = sp_std::str::from_utf8_unchecked(&metric_update); - -// sp_tracing::event!( -// target: "metrics", -// sp_tracing::Level::TRACE, -// update_op -// ); -// } -// }; -// } - -// #[cfg(feature = "std")] -// macro_rules! inc_counter_vec { -// ($metric:ident, $value:expr) => {}; -// } - mod misc; mod weights; From ff02191ed1ecb35ede6e3451e7d39f287fce6614 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 20:52:21 +0000 Subject: [PATCH 24/63] base58 decoding Signed-off-by: Andrei Sandu --- node/metrics/Cargo.toml | 1 + node/metrics/src/runtime.rs | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index 830677a94b71..8186844334af 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -19,6 +19,7 @@ sc-service = { git = "https://github.com/paritytech/substrate", branch = "master codec = { package = "parity-scale-codec", version = "2.2.0" } sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } primitives = { package = "polkadot-primitives", path = "../../primitives/" } +bs58 = { version = "0.4.0", features = ["alloc"] } [features] default = [] diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 9731c9c37bc0..e60e5a99b440 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -100,11 +100,13 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { return } - if let Some(update_op_str) = event.values.string_values.get("params").cloned() { + if let Some(update_op_bs48) = event.values.string_values.get("params").cloned() { // TODO: Fix ugly hack because the payload comes in as a formatted string. - const SKIP_CHARS: usize = " { update_op: ".len(); - println!("Decoding: {:?}", update_op_str); - match RuntimeMetricUpdate::decode(&mut update_op_str[SKIP_CHARS..].as_bytes()) { + + // Deserialize the metric update struct. + match RuntimeMetricUpdate::decode( + &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs48).as_ref(), + ) { Ok(update_op) => { println!("Received metric: {:?}", update_op); self.parse_metric_update(update_op); @@ -126,6 +128,23 @@ impl RuntimeMetricsProvider { }, } } + + // Returns the `bs58` encoded metric update operation. + fn parse_event_params(event_params: &String) -> Vec { + println!("params: {}", event_params); + + // Shave " }" suffix. + let new_len = event_params.len() - 2; + let event_params = &event_params[..new_len]; + + // Shave " { update_op: " prefix. + const SKIP_CHARS: usize = " { update_op: ".len(); + let metric_update_op = &event_params[SKIP_CHARS..]; + + println!("Metric updatet op {}", metric_update_op); + + bs58::decode(metric_update_op.as_bytes()).into_vec().unwrap_or_default() + } } /// Returns the custom profiling closure that we'll apply to the LoggerBuilder. From 975e46b81916970ae73b0f0efedf52aeaa634271 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 20:52:47 +0000 Subject: [PATCH 25/63] base58 encoding Signed-off-by: Andrei Sandu --- runtime/metrics/Cargo.toml | 3 +++ runtime/metrics/src/lib.rs | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/runtime/metrics/Cargo.toml b/runtime/metrics/Cargo.toml index c00c6a144fbe..4d9b06fb1103 100644 --- a/runtime/metrics/Cargo.toml +++ b/runtime/metrics/Cargo.toml @@ -10,6 +10,8 @@ sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master parity-scale-codec = { version = "2.3.1", default-features = false } primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false } +bs58 = { version = "0.4.0", default-features = false, features = ["alloc"] } + [features] default = ["std"] no_std = [] @@ -18,5 +20,6 @@ std = [ "sp-tracing/std", "parity-scale-codec/std", "primitives/std", + "bs58/std" ] with-tracing = ["sp-tracing/with-tracing"] diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index 1f17705e7085..b3c86dc98f8e 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -34,21 +34,23 @@ pub struct CounterVec { #[cfg(not(feature = "std"))] impl CounterVec { - /// Create a new counter vec metric. + /// Create a new counter metric. pub fn new(name: &'static str) -> Self { Self::new_with_labels(name, sp_std::vec::Vec::new()) } + /// Create a new counter metric with specified `labels`. pub fn new_with_labels(name: &'static str, labels: RuntimeMetricLabels) -> Self { CounterVec { name, labels, label_values: RuntimeMetricLabelValues::default() } } + /// Set label values. pub fn with_label_values(&mut self, label_values: RuntimeMetricLabelValues) -> &Self { self.label_values = label_values; self } - /// Increment metric by value. + /// Increment by `value`. pub fn inc_by(&mut self, value: u64) { let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(self.name), @@ -56,14 +58,15 @@ impl CounterVec { } .encode(); - // This is safe, we only care about the metric name which is static str. + // `from_utf8_unchecked` is safe, we only care about the `metric_name` which is static str. unsafe { - let update_op = sp_std::str::from_utf8_unchecked(&metric_update); + let update_op = + bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); sp_tracing::event!( target: "metrics", sp_tracing::Level::TRACE, - update_op = update_op + update_op = update_op.as_str() ); } From 6be0e3bd13b01c4e7dd1d73cc146087fd9f084b6 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 20:53:00 +0000 Subject: [PATCH 26/63] fix warn Signed-off-by: Andrei Sandu --- cli/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 34ea43e0121f..701d216904fb 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -281,7 +281,7 @@ pub fn run_with_wasm_metrics() -> Result<()> { /// Parses polkadot specific CLI arguments and run the service. pub fn run() -> Result<()> { - let mut cli: Cli = Cli::from_args(); + let cli: Cli = Cli::from_args(); match &cli.subcommand { // TODO: gate by feature `runtime_metrics`. From fd612f1afc96318b54a1ef408131aa978ae152cc Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 9 Dec 2021 20:55:45 +0000 Subject: [PATCH 27/63] typo Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index e60e5a99b440..20d30e55e23b 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -100,12 +100,12 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { return } - if let Some(update_op_bs48) = event.values.string_values.get("params").cloned() { + if let Some(update_op_bs58) = event.values.string_values.get("params").cloned() { // TODO: Fix ugly hack because the payload comes in as a formatted string. // Deserialize the metric update struct. match RuntimeMetricUpdate::decode( - &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs48).as_ref(), + &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs58).as_ref(), ) { Ok(update_op) => { println!("Received metric: {:?}", update_op); From 609bb7409e4faae37878ab7405d4b7dc7a824390 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 13:10:12 +0000 Subject: [PATCH 28/63] Review feedback Signed-off-by: Andrei Sandu --- node/metrics/Cargo.toml | 4 +- node/metrics/src/runtime.rs | 98 +++++++++++++++++++++-------------- primitives/src/v0.rs | 68 ------------------------ primitives/src/v1/mod.rs | 74 ++++++++++++++++++++++++++ runtime/metrics/src/lib.rs | 8 ++- runtime/parachains/Cargo.toml | 2 +- 6 files changed, 141 insertions(+), 113 deletions(-) diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index 8186844334af..dffe11b534ec 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -15,11 +15,11 @@ metered-channel = { path = "../metered-channel" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } codec = { package = "parity-scale-codec", version = "2.2.0" } -sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } primitives = { package = "polkadot-primitives", path = "../../primitives/" } bs58 = { version = "0.4.0", features = ["alloc"] } +log = "0.4.13" [features] default = [] diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 20d30e55e23b..d3eff054d011 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -19,14 +19,16 @@ //! Builds on top of Substrate wasm tracing support. use codec::Decode; -use primitives::v0::{AsStr, RuntimeMetricLabel, RuntimeMetricOp, RuntimeMetricUpdate}; +use primitives::v1::{AsStr, RuntimeMetricLabel, RuntimeMetricOp, RuntimeMetricUpdate}; use std::{ collections::hash_map::HashMap, sync::{Arc, Mutex}, }; use substrate_prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64}; -/// We only support CounterVec for now. +const LOG_TARGET: &'static str = "metrics::runtime"; + +/// Support only CounterVec for now. /// TODO: add more when needed. #[derive(Clone, Default)] pub struct Metrics { @@ -49,22 +51,29 @@ impl RuntimeMetricsProvider { description: &str, label: RuntimeMetricLabel, ) -> Result<(), PrometheusError> { - if !self.1.counter_vecs.lock().expect("bad lock").contains_key(metric_name) { - let counter_vec = register( - CounterVec::new( - Opts::new(metric_name, description), - &[label.as_str().expect("invalid metric label")], - )?, - &self.0, - )?; - - self.1 - .counter_vecs - .lock() - .expect("bad lock") - .insert(metric_name.to_owned(), counter_vec); + match self.1.counter_vecs.lock() { + Ok(mut unlocked_hashtable) => { + if unlocked_hashtable.contains_key(metric_name) { + return Ok(()) + } + + unlocked_hashtable.insert( + metric_name.to_owned(), + register( + CounterVec::new( + Opts::new(metric_name, description), + &[label.as_str().unwrap_or("default")], + )?, + &self.0, + )?, + ); + }, + Err(e) => tracing::error!( + target: LOG_TARGET, + "Failed to acquire the `counter_vecs` lock: {:?}", + e + ); } - Ok(()) } @@ -72,17 +81,27 @@ impl RuntimeMetricsProvider { pub fn inc_counter_by(&self, name: &str, value: u64, label: RuntimeMetricLabel) { match self.register_countervec(name, "default description", label.clone()) { Ok(_) => { - // The metric is in the hashmap, unwrap won't panic. - self.1 - .counter_vecs - .lock() - .expect("bad lock") - .get_mut(name) - .unwrap() - .with_label_values(&[label.as_str().expect("invalid metric label")]) - .inc_by(value); + let _ = self.1.counter_vecs.lock().map(|mut unlocked_hashtable| { + if let Some(counter_vec) = unlocked_hashtable.get_mut(name) { + counter_vec + .with_label_values(&[label.as_str().expect("invalid metric label")]) + .inc_by(value); + } else { + tracing::error!( + target: LOG_TARGET, + "Cannot increment counter `{}`, metric not in hashtable", + name + ); + } + }); }, - Err(_) => {}, + Err(e) => { + tracing::error!( + target: LOG_TARGET, + "Faied to register metric `{}`: {:?}", + name, e + ); + } } } } @@ -101,11 +120,9 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { } if let Some(update_op_bs58) = event.values.string_values.get("params").cloned() { - // TODO: Fix ugly hack because the payload comes in as a formatted string. - // Deserialize the metric update struct. match RuntimeMetricUpdate::decode( - &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs58).as_ref(), + &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs58).unwrap_or_default().as_slice(), ) { Ok(update_op) => { println!("Received metric: {:?}", update_op); @@ -130,20 +147,21 @@ impl RuntimeMetricsProvider { } // Returns the `bs58` encoded metric update operation. - fn parse_event_params(event_params: &String) -> Vec { - println!("params: {}", event_params); - + fn parse_event_params(event_params: &String) -> Option> { // Shave " }" suffix. - let new_len = event_params.len() - 2; + let new_len = event_params.len().saturating_sub(2); let event_params = &event_params[..new_len]; // Shave " { update_op: " prefix. - const SKIP_CHARS: usize = " { update_op: ".len(); - let metric_update_op = &event_params[SKIP_CHARS..]; - - println!("Metric updatet op {}", metric_update_op); - - bs58::decode(metric_update_op.as_bytes()).into_vec().unwrap_or_default() + const SKIP_CHARS: &'static str = " { update_op: "; + if SKIP_CHARS.len() < event_params.len() { + if SKIP_CHARS.eq_ignore_ascii_case(&event_params[..SKIP_CHARS.len()]) { + return bs58::decode(&event_params[SKIP_CHARS.len()..].as_bytes()).into_vec().ok() + } + } + + // No event was parsed + None } } diff --git a/primitives/src/v0.rs b/primitives/src/v0.rs index 435e08a0ad27..64163d04bdd7 100644 --- a/primitives/src/v0.rs +++ b/primitives/src/v0.rs @@ -923,74 +923,6 @@ pub mod fisherman { } } -// TODO: add feature gate. -/// Runtime metric operations. -#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, TypeInfo)] -pub enum RuntimeMetricOp { - /// Increment metric by value. - Increment(u64), -} - -/// Runtime metric update event. -#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, TypeInfo)] -pub struct RuntimeMetricUpdate { - /// The name of the metric. - pub metric_name: Vec, - /// The operation applied to the metric. - pub op: RuntimeMetricOp, -} - -impl RuntimeMetricUpdate { - /// Returns the metric name. - pub fn metric_name(&self) -> &str { - unsafe { sp_std::str::from_utf8_unchecked(&self.metric_name) } - } -} - -/// A set of metric labels. -pub type RuntimeMetricLabels = Vec; - -/// A metric label. -#[derive(Clone, Default)] -pub struct RuntimeMetricLabel(Vec); - -/// A metric label value. -#[derive(Clone, Default)] -pub struct RuntimeMetricLabelValue(Vec); - -/// A set of metric label values. -pub type RuntimeMetricLabelValues = Vec; - -/// Trait for converting Vec to &str. -pub trait AsStr { - /// Return a str reference. - fn as_str(&self) -> Option<&str>; -} - -impl AsStr for RuntimeMetricLabel { - fn as_str(&self) -> Option<&str> { - sp_std::str::from_utf8(&self.0).ok() - } -} - -impl AsStr for RuntimeMetricLabelValue { - fn as_str(&self) -> Option<&str> { - sp_std::str::from_utf8(&self.0).ok() - } -} - -impl From<&'static str> for RuntimeMetricLabel { - fn from(s: &'static str) -> Self { - Self(s.as_bytes().to_vec()) - } -} - -impl From<&'static str> for RuntimeMetricLabelValue { - fn from(s: &'static str) -> Self { - Self(s.as_bytes().to_vec()) - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index c183df37cebe..b02b009083da 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -1416,6 +1416,80 @@ pub fn supermajority_threshold(n: usize) -> usize { n - byzantine_threshold(n) } +// TODO: add feature gate. +/// Runtime metric operations. +#[derive(Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub enum RuntimeMetricOp { + /// Increment metric by value. + Increment(u64), +} + +/// Runtime metric update event. +#[derive(Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RuntimeMetricUpdate { + /// The name of the metric. + pub metric_name: Vec, + /// The operation applied to the metric. + pub op: RuntimeMetricOp, +} + +impl RuntimeMetricUpdate { + /// Returns the metric name. + pub fn metric_name(&self) -> &str { + #[cfg(feature = "std")] + return std::str::from_utf8(&self.metric_name).unwrap_or("invalid_metric_name"); + + #[cfg(not(feature = "std"))] + return sp_std::str::from_utf8(&self.metric_name).unwrap_or("invalid_metric_name"); + } +} + +/// A set of metric labels. +pub type RuntimeMetricLabels = Vec; + +/// A metric label. +#[derive(Clone, Default)] +pub struct RuntimeMetricLabel(Vec); + +/// A metric label value. +#[derive(Clone, Default)] +pub struct RuntimeMetricLabelValue(Vec); + +/// A set of metric label values. +pub type RuntimeMetricLabelValues = Vec; + +/// Trait for converting Vec to &str. +pub trait AsStr { + /// Return a str reference. + fn as_str(&self) -> Option<&str>; +} + +impl AsStr for RuntimeMetricLabel { + fn as_str(&self) -> Option<&str> { + sp_std::str::from_utf8(&self.0).ok() + } +} + +impl AsStr for RuntimeMetricLabelValue { + fn as_str(&self) -> Option<&str> { + sp_std::str::from_utf8(&self.0).ok() + } +} + +impl From<&'static str> for RuntimeMetricLabel { + fn from(s: &'static str) -> Self { + Self(s.as_bytes().to_vec()) + } +} + +impl From<&'static str> for RuntimeMetricLabelValue { + fn from(s: &'static str) -> Self { + Self(s.as_bytes().to_vec()) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index b3c86dc98f8e..f53184b4dc1d 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -15,15 +15,19 @@ // along with Polkadot. If not, see . //! Runtime metric interface similar to native Prometheus metrics. +//! +//! This is intended to be used only for testing and debugging and **must never +//! be used in production**. It requires the Substrate wasm tracing support +//! and command line configuration: `--tracing-targets wasm_tracing=trace`. #![cfg_attr(not(feature = "std"), no_std)] -use primitives::v0::{RuntimeMetricLabelValues, RuntimeMetricLabels}; +use primitives::v1::{RuntimeMetricLabelValues, RuntimeMetricLabels}; #[cfg(not(feature = "std"))] use parity_scale_codec::Encode; #[cfg(not(feature = "std"))] -use primitives::v0::{RuntimeMetricOp, RuntimeMetricUpdate}; +use primitives::v1::{RuntimeMetricOp, RuntimeMetricUpdate}; #[cfg(not(feature = "std"))] pub struct CounterVec { diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index bb0a663cc269..07675bdb035a 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -23,7 +23,7 @@ sp-session = { git = "https://github.com/paritytech/substrate", branch = "master sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } -sp-tracing = { version = "4.0.0-dev", branch = "master", git = "https://github.com/paritytech/substrate", default-features = false } +sp-tracing = { version = "4.0.0-dev", branch = "master", git = "https://github.com/paritytech/substrate", default-features = false, optional = true } pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } From c07f5cce90583da332b0ced4d8adead22f50b097 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 14:21:27 +0000 Subject: [PATCH 29/63] Finish label support Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 49 ++++------- primitives/src/v1/mod.rs | 89 +++++++++++++++----- runtime/metrics/src/lib.rs | 36 ++++++-- runtime/parachains/src/paras_inherent/mod.rs | 8 ++ 4 files changed, 119 insertions(+), 63 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index d3eff054d011..5e3d275cc4b3 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -19,7 +19,7 @@ //! Builds on top of Substrate wasm tracing support. use codec::Decode; -use primitives::v1::{AsStr, RuntimeMetricLabel, RuntimeMetricOp, RuntimeMetricUpdate}; +use primitives::v1::{RuntimeMetricOp, RuntimeMetricUpdate, RuntimeMetricRegisterParams, RuntimeMetricLabelValues}; use std::{ collections::hash_map::HashMap, sync::{Arc, Mutex}, @@ -48,8 +48,7 @@ impl RuntimeMetricsProvider { pub fn register_countervec( &self, metric_name: &str, - description: &str, - label: RuntimeMetricLabel, + params: &RuntimeMetricRegisterParams ) -> Result<(), PrometheusError> { match self.1.counter_vecs.lock() { Ok(mut unlocked_hashtable) => { @@ -61,8 +60,8 @@ impl RuntimeMetricsProvider { metric_name.to_owned(), register( CounterVec::new( - Opts::new(metric_name, description), - &[label.as_str().unwrap_or("default")], + Opts::new(metric_name, params.description()), + ¶ms.labels(), )?, &self.0, )?, @@ -72,37 +71,26 @@ impl RuntimeMetricsProvider { target: LOG_TARGET, "Failed to acquire the `counter_vecs` lock: {:?}", e - ); + ) } Ok(()) } /// Increment a counter vec by a value. - pub fn inc_counter_by(&self, name: &str, value: u64, label: RuntimeMetricLabel) { - match self.register_countervec(name, "default description", label.clone()) { - Ok(_) => { - let _ = self.1.counter_vecs.lock().map(|mut unlocked_hashtable| { - if let Some(counter_vec) = unlocked_hashtable.get_mut(name) { - counter_vec - .with_label_values(&[label.as_str().expect("invalid metric label")]) - .inc_by(value); - } else { - tracing::error!( - target: LOG_TARGET, - "Cannot increment counter `{}`, metric not in hashtable", - name - ); - } - }); - }, - Err(e) => { + pub fn inc_counter_by(&self, name: &str, value: u64, labels: &RuntimeMetricLabelValues) { + let _ = self.1.counter_vecs.lock().map(|mut unlocked_hashtable| { + if let Some(counter_vec) = unlocked_hashtable.get_mut(name) { + counter_vec + .with_label_values(&labels.as_str()) + .inc_by(value); + } else { tracing::error!( target: LOG_TARGET, - "Faied to register metric `{}`: {:?}", - name, e + "Cannot increment counter `{}`, metric not in registered or present in hashtable", + name ); } - } + }); } } @@ -140,9 +128,8 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { impl RuntimeMetricsProvider { fn parse_metric_update(&self, update: RuntimeMetricUpdate) { match update.op { - RuntimeMetricOp::Increment(value) => { - self.inc_counter_by(update.metric_name(), value, "test_label".into()); - }, + RuntimeMetricOp::Register(ref params) => { let _ = self.register_countervec(update.metric_name(), ¶ms); } + RuntimeMetricOp::Increment(value, ref labels) => self.inc_counter_by(update.metric_name(), value, labels) } } @@ -159,7 +146,7 @@ impl RuntimeMetricsProvider { return bs58::decode(&event_params[SKIP_CHARS.len()..].as_bytes()).into_vec().ok() } } - + // No event was parsed None } diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index b02b009083da..03862696a572 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -1421,8 +1421,27 @@ pub fn supermajority_threshold(n: usize) -> usize { #[derive(Encode, Decode)] #[cfg_attr(feature = "std", derive(Debug))] pub enum RuntimeMetricOp { + /// Register a new metric. + Register(RuntimeMetricRegisterParams), /// Increment metric by value. - Increment(u64), + Increment(u64, RuntimeMetricLabelValues), +} + +/// Metric registration parameters. +#[derive(Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RuntimeMetricRegisterParams { + description: Vec, + labels: RuntimeMetricLabels, +} + +impl RuntimeMetricRegisterParams { + /// Create new metric registration params. + pub fn new(description: Vec, labels: RuntimeMetricLabels) -> Self { + Self { + description, labels + } + } } /// Runtime metric update event. @@ -1435,30 +1454,66 @@ pub struct RuntimeMetricUpdate { pub op: RuntimeMetricOp, } +fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { + #[cfg(feature = "std")] + return std::str::from_utf8(v).unwrap_or(default); + + #[cfg(not(feature = "std"))] + return sp_std::str::from_utf8(v).unwrap_or(default); +} + +impl RuntimeMetricRegisterParams { + /// Returns the metric description. + pub fn description(&self) -> &str { + vec_to_str(&self.description, "No description provided.") + } + + /// Returns a labels as Vec<&str>. + pub fn labels(&self) -> Vec<&str> { + self.labels.as_str() + } +} + +impl RuntimeMetricLabels { + /// Returns a labels as Vec<&str>. + pub fn as_str(&self) -> Vec<&str> { + self.0.iter().map(|label_vec| vec_to_str(&label_vec.0, "invalid_label")).collect() + } + + /// Return the inner values as vec. + pub fn clear(&mut self) { + self.0.clear(); + } +} + +impl From> for RuntimeMetricLabels { + fn from(v: Vec<&'static str>) -> RuntimeMetricLabels { + RuntimeMetricLabels(v.iter().map(|label| RuntimeMetricLabel(label.as_bytes().to_vec())).collect()) + } +} + impl RuntimeMetricUpdate { /// Returns the metric name. pub fn metric_name(&self) -> &str { - #[cfg(feature = "std")] - return std::str::from_utf8(&self.metric_name).unwrap_or("invalid_metric_name"); - - #[cfg(not(feature = "std"))] - return sp_std::str::from_utf8(&self.metric_name).unwrap_or("invalid_metric_name"); + vec_to_str(&self.metric_name, "invalid_metric_name") } } /// A set of metric labels. -pub type RuntimeMetricLabels = Vec; +#[derive(Clone, Default, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RuntimeMetricLabels(Vec); /// A metric label. -#[derive(Clone, Default)] +#[derive(Clone, Default, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] pub struct RuntimeMetricLabel(Vec); /// A metric label value. -#[derive(Clone, Default)] -pub struct RuntimeMetricLabelValue(Vec); +pub type RuntimeMetricLabelValue = RuntimeMetricLabel; /// A set of metric label values. -pub type RuntimeMetricLabelValues = Vec; +pub type RuntimeMetricLabelValues = RuntimeMetricLabels; /// Trait for converting Vec to &str. pub trait AsStr { @@ -1472,24 +1527,12 @@ impl AsStr for RuntimeMetricLabel { } } -impl AsStr for RuntimeMetricLabelValue { - fn as_str(&self) -> Option<&str> { - sp_std::str::from_utf8(&self.0).ok() - } -} - impl From<&'static str> for RuntimeMetricLabel { fn from(s: &'static str) -> Self { Self(s.as_bytes().to_vec()) } } -impl From<&'static str> for RuntimeMetricLabelValue { - fn from(s: &'static str) -> Self { - Self(s.as_bytes().to_vec()) - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index f53184b4dc1d..77dc1af3be30 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -27,12 +27,11 @@ use primitives::v1::{RuntimeMetricLabelValues, RuntimeMetricLabels}; use parity_scale_codec::Encode; #[cfg(not(feature = "std"))] -use primitives::v1::{RuntimeMetricOp, RuntimeMetricUpdate}; +use primitives::v1::{ RuntimeMetricOp, RuntimeMetricUpdate,RuntimeMetricRegisterParams }; #[cfg(not(feature = "std"))] pub struct CounterVec { name: &'static str, - labels: RuntimeMetricLabels, label_values: RuntimeMetricLabelValues, } @@ -40,16 +39,35 @@ pub struct CounterVec { impl CounterVec { /// Create a new counter metric. pub fn new(name: &'static str) -> Self { - Self::new_with_labels(name, sp_std::vec::Vec::new()) + Self::new_with_labels(name, "No description provided", RuntimeMetricLabels::default()) } /// Create a new counter metric with specified `labels`. - pub fn new_with_labels(name: &'static str, labels: RuntimeMetricLabels) -> Self { - CounterVec { name, labels, label_values: RuntimeMetricLabelValues::default() } + pub fn new_with_labels(name: &'static str, description: &'static str, labels: RuntimeMetricLabels) -> Self { + // Send a register metric operation to node side. + let metric_update = RuntimeMetricUpdate { + metric_name: sp_std::vec::Vec::from(name), + op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new(sp_std::vec::Vec::from(description),labels)), + } + .encode(); + + // `from_utf8_unchecked` is safe, we only care about the `metric_name` which is static str. + unsafe { + let register_metric_op = + bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); + + sp_tracing::event!( + target: "metrics", + sp_tracing::Level::TRACE, + update_op = register_metric_op.as_str() + ); + } + + CounterVec { name, label_values: RuntimeMetricLabelValues::default() } } /// Set label values. - pub fn with_label_values(&mut self, label_values: RuntimeMetricLabelValues) -> &Self { + pub fn with_label_values(&mut self, label_values: RuntimeMetricLabelValues) -> &mut Self { self.label_values = label_values; self } @@ -58,7 +76,7 @@ impl CounterVec { pub fn inc_by(&mut self, value: u64) { let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(self.name), - op: RuntimeMetricOp::Increment(value), + op: RuntimeMetricOp::Increment(value, self.label_values.clone()), } .encode(); @@ -87,11 +105,11 @@ impl CounterVec { pub fn new(_: &'static str) -> Self { CounterVec } - pub fn new_with_labels(_: &'static str, _: RuntimeMetricLabels) -> Self { + pub fn new_with_labels(_name: &'static str, _description: &'static str, _labels: RuntimeMetricLabels) -> Self { CounterVec } - pub fn with_label_values(&mut self, _: RuntimeMetricLabelValues) -> &Self { + pub fn with_label_values(&mut self, _: RuntimeMetricLabelValues) -> &mut Self { self } diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 802a29a94a4b..b38ae6400028 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -269,6 +269,14 @@ impl Pallet { let mut candidates_processed_metric = CounterVec::new("polkadot_create_inherent_candidates_processed"); let mut total_weight_metric = CounterVec::new("create_inherent_total_weight"); + let mut disputes_processed = CounterVec::new_with_labels( + "polkadot_create_inherent_disputes_processed", + "Counts the how many dispute signatures have been checked", + sp_std::vec!["validity".into()].into() + ); + + disputes_processed.with_label_values(sp_std::vec!["valid".into()].into()).inc_by(100); + disputes_processed.with_label_values(sp_std::vec!["invalid".into()].into()).inc_by(200); log::debug!( target: LOG_TARGET, From 06af03b1b06fa897b6f294800a745d9fa1767cf8 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 14:22:16 +0000 Subject: [PATCH 30/63] fmt Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 27 ++++++++++++-------- primitives/src/v1/mod.rs | 17 +++++++----- runtime/metrics/src/lib.rs | 23 ++++++++++++----- runtime/parachains/src/paras_inherent/mod.rs | 12 ++++++--- 4 files changed, 51 insertions(+), 28 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 5e3d275cc4b3..d1f714849f25 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -19,7 +19,9 @@ //! Builds on top of Substrate wasm tracing support. use codec::Decode; -use primitives::v1::{RuntimeMetricOp, RuntimeMetricUpdate, RuntimeMetricRegisterParams, RuntimeMetricLabelValues}; +use primitives::v1::{ + RuntimeMetricLabelValues, RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate, +}; use std::{ collections::hash_map::HashMap, sync::{Arc, Mutex}, @@ -48,7 +50,7 @@ impl RuntimeMetricsProvider { pub fn register_countervec( &self, metric_name: &str, - params: &RuntimeMetricRegisterParams + params: &RuntimeMetricRegisterParams, ) -> Result<(), PrometheusError> { match self.1.counter_vecs.lock() { Ok(mut unlocked_hashtable) => { @@ -71,7 +73,7 @@ impl RuntimeMetricsProvider { target: LOG_TARGET, "Failed to acquire the `counter_vecs` lock: {:?}", e - ) + ), } Ok(()) } @@ -80,9 +82,7 @@ impl RuntimeMetricsProvider { pub fn inc_counter_by(&self, name: &str, value: u64, labels: &RuntimeMetricLabelValues) { let _ = self.1.counter_vecs.lock().map(|mut unlocked_hashtable| { if let Some(counter_vec) = unlocked_hashtable.get_mut(name) { - counter_vec - .with_label_values(&labels.as_str()) - .inc_by(value); + counter_vec.with_label_values(&labels.as_str()).inc_by(value); } else { tracing::error!( target: LOG_TARGET, @@ -110,7 +110,9 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { if let Some(update_op_bs58) = event.values.string_values.get("params").cloned() { // Deserialize the metric update struct. match RuntimeMetricUpdate::decode( - &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs58).unwrap_or_default().as_slice(), + &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs58) + .unwrap_or_default() + .as_slice(), ) { Ok(update_op) => { println!("Received metric: {:?}", update_op); @@ -128,8 +130,11 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { impl RuntimeMetricsProvider { fn parse_metric_update(&self, update: RuntimeMetricUpdate) { match update.op { - RuntimeMetricOp::Register(ref params) => { let _ = self.register_countervec(update.metric_name(), ¶ms); } - RuntimeMetricOp::Increment(value, ref labels) => self.inc_counter_by(update.metric_name(), value, labels) + RuntimeMetricOp::Register(ref params) => { + let _ = self.register_countervec(update.metric_name(), ¶ms); + }, + RuntimeMetricOp::Increment(value, ref labels) => + self.inc_counter_by(update.metric_name(), value, labels), } } @@ -141,10 +146,10 @@ impl RuntimeMetricsProvider { // Shave " { update_op: " prefix. const SKIP_CHARS: &'static str = " { update_op: "; - if SKIP_CHARS.len() < event_params.len() { + if SKIP_CHARS.len() < event_params.len() { if SKIP_CHARS.eq_ignore_ascii_case(&event_params[..SKIP_CHARS.len()]) { return bs58::decode(&event_params[SKIP_CHARS.len()..].as_bytes()).into_vec().ok() - } + } } // No event was parsed diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index 03862696a572..82d35e73801b 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -1438,9 +1438,7 @@ pub struct RuntimeMetricRegisterParams { impl RuntimeMetricRegisterParams { /// Create new metric registration params. pub fn new(description: Vec, labels: RuntimeMetricLabels) -> Self { - Self { - description, labels - } + Self { description, labels } } } @@ -1456,10 +1454,10 @@ pub struct RuntimeMetricUpdate { fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { #[cfg(feature = "std")] - return std::str::from_utf8(v).unwrap_or(default); + return std::str::from_utf8(v).unwrap_or(default) #[cfg(not(feature = "std"))] - return sp_std::str::from_utf8(v).unwrap_or(default); + return sp_std::str::from_utf8(v).unwrap_or(default) } impl RuntimeMetricRegisterParams { @@ -1477,7 +1475,10 @@ impl RuntimeMetricRegisterParams { impl RuntimeMetricLabels { /// Returns a labels as Vec<&str>. pub fn as_str(&self) -> Vec<&str> { - self.0.iter().map(|label_vec| vec_to_str(&label_vec.0, "invalid_label")).collect() + self.0 + .iter() + .map(|label_vec| vec_to_str(&label_vec.0, "invalid_label")) + .collect() } /// Return the inner values as vec. @@ -1488,7 +1489,9 @@ impl RuntimeMetricLabels { impl From> for RuntimeMetricLabels { fn from(v: Vec<&'static str>) -> RuntimeMetricLabels { - RuntimeMetricLabels(v.iter().map(|label| RuntimeMetricLabel(label.as_bytes().to_vec())).collect()) + RuntimeMetricLabels( + v.iter().map(|label| RuntimeMetricLabel(label.as_bytes().to_vec())).collect(), + ) } } diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index 77dc1af3be30..c2c6f1a04090 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -15,8 +15,8 @@ // along with Polkadot. If not, see . //! Runtime metric interface similar to native Prometheus metrics. -//! -//! This is intended to be used only for testing and debugging and **must never +//! +//! This is intended to be used only for testing and debugging and **must never //! be used in production**. It requires the Substrate wasm tracing support //! and command line configuration: `--tracing-targets wasm_tracing=trace`. @@ -27,7 +27,7 @@ use primitives::v1::{RuntimeMetricLabelValues, RuntimeMetricLabels}; use parity_scale_codec::Encode; #[cfg(not(feature = "std"))] -use primitives::v1::{ RuntimeMetricOp, RuntimeMetricUpdate,RuntimeMetricRegisterParams }; +use primitives::v1::{RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate}; #[cfg(not(feature = "std"))] pub struct CounterVec { @@ -43,11 +43,18 @@ impl CounterVec { } /// Create a new counter metric with specified `labels`. - pub fn new_with_labels(name: &'static str, description: &'static str, labels: RuntimeMetricLabels) -> Self { + pub fn new_with_labels( + name: &'static str, + description: &'static str, + labels: RuntimeMetricLabels, + ) -> Self { // Send a register metric operation to node side. let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(name), - op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new(sp_std::vec::Vec::from(description),labels)), + op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new( + sp_std::vec::Vec::from(description), + labels, + )), } .encode(); @@ -105,7 +112,11 @@ impl CounterVec { pub fn new(_: &'static str) -> Self { CounterVec } - pub fn new_with_labels(_name: &'static str, _description: &'static str, _labels: RuntimeMetricLabels) -> Self { + pub fn new_with_labels( + _name: &'static str, + _description: &'static str, + _labels: RuntimeMetricLabels, + ) -> Self { CounterVec } diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index b38ae6400028..4134a1135f97 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -270,13 +270,17 @@ impl Pallet { CounterVec::new("polkadot_create_inherent_candidates_processed"); let mut total_weight_metric = CounterVec::new("create_inherent_total_weight"); let mut disputes_processed = CounterVec::new_with_labels( - "polkadot_create_inherent_disputes_processed", + "polkadot_create_inherent_disputes_processed", "Counts the how many dispute signatures have been checked", - sp_std::vec!["validity".into()].into() + sp_std::vec!["validity".into()].into(), ); - disputes_processed.with_label_values(sp_std::vec!["valid".into()].into()).inc_by(100); - disputes_processed.with_label_values(sp_std::vec!["invalid".into()].into()).inc_by(200); + disputes_processed + .with_label_values(sp_std::vec!["valid".into()].into()) + .inc_by(100); + disputes_processed + .with_label_values(sp_std::vec!["invalid".into()].into()) + .inc_by(200); log::debug!( target: LOG_TARGET, From c446960dba0c439979653067f0e14fac03e72bfb Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 15:38:29 +0000 Subject: [PATCH 31/63] please compile Signed-off-by: Andrei Sandu --- primitives/src/v1/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index 82d35e73801b..cf2c12350025 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -1452,14 +1452,17 @@ pub struct RuntimeMetricUpdate { pub op: RuntimeMetricOp, } +#[cfg(feature = "std")] fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { - #[cfg(feature = "std")] return std::str::from_utf8(v).unwrap_or(default) +} - #[cfg(not(feature = "std"))] +#[cfg(not(feature = "std"))] +fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { return sp_std::str::from_utf8(v).unwrap_or(default) } + impl RuntimeMetricRegisterParams { /// Returns the metric description. pub fn description(&self) -> &str { From 470b976df7b9b7db166f663f2f39157b68322c92 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 15:38:56 +0000 Subject: [PATCH 32/63] add feature gate Signed-off-by: Andrei Sandu --- cli/Cargo.toml | 2 +- cli/src/command.rs | 1 - node/metrics/Cargo.toml | 1 + node/metrics/src/lib.rs | 10 ++++++++++ node/metrics/src/runtime.rs | 2 ++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index abde4f0dc933..99dc99e2e5ed 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -64,4 +64,4 @@ rococo-native = [ "service/rococo-native" ] malus = [ "full-node", "service/malus" ] disputes = [ "service/disputes" ] -with-tracing = ["service/with-tracing"] +with-tracing = ["service/with-tracing", "polkadot-node-metrics/with-tracing"] diff --git a/cli/src/command.rs b/cli/src/command.rs index 701d216904fb..271a18b5ccb6 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -284,7 +284,6 @@ pub fn run() -> Result<()> { let cli: Cli = Cli::from_args(); match &cli.subcommand { - // TODO: gate by feature `runtime_metrics`. None => run_node_inner(cli, service::RealOverseerGen, polkadot_node_metrics::logger_hook()), Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index dffe11b534ec..072ca1d5bfb2 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -23,3 +23,4 @@ log = "0.4.13" [features] default = [] +with-tracing = [] diff --git a/node/metrics/src/lib.rs b/node/metrics/src/lib.rs index 05313b1e7100..baf85440e136 100644 --- a/node/metrics/src/lib.rs +++ b/node/metrics/src/lib.rs @@ -29,9 +29,19 @@ pub use metered_channel as metered; /// Cyclic metric collection support. pub mod metronome; pub use self::metronome::Metronome; + +#[cfg(feature = "with-tracing")] pub mod runtime; +#[cfg(feature = "with-tracing")] pub use self::runtime::logger_hook; +/// Export a dummy logger hook when `wasm tracing` is not enabled. +#[cfg(not(feature = "with-tracing"))] +pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () { + |_logger_builder, _config| {} +} + + /// This module reexports Prometheus types and defines the [`Metrics`] trait. pub mod metrics { /// Reexport Substrate Prometheus types. diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index d1f714849f25..d8eaa4800811 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -17,6 +17,7 @@ //! Runtime Metrics helpers. //! //! Builds on top of Substrate wasm tracing support. +#![cfg(feature = "with-tracing")] use codec::Decode; use primitives::v1::{ @@ -128,6 +129,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { } impl RuntimeMetricsProvider { + // Parse end execute the update operation. fn parse_metric_update(&self, update: RuntimeMetricUpdate) { match update.op { RuntimeMetricOp::Register(ref params) => { From 1342382e1fdf9de8b26aa7ddd5169133b2eb1d2a Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 15:39:24 +0000 Subject: [PATCH 33/63] fmt Signed-off-by: Andrei Sandu --- node/metrics/src/lib.rs | 1 - primitives/src/v1/mod.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/node/metrics/src/lib.rs b/node/metrics/src/lib.rs index baf85440e136..34436d7f8167 100644 --- a/node/metrics/src/lib.rs +++ b/node/metrics/src/lib.rs @@ -41,7 +41,6 @@ pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Con |_logger_builder, _config| {} } - /// This module reexports Prometheus types and defines the [`Metrics`] trait. pub mod metrics { /// Reexport Substrate Prometheus types. diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index cf2c12350025..f521adaec163 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -1462,7 +1462,6 @@ fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { return sp_std::str::from_utf8(v).unwrap_or(default) } - impl RuntimeMetricRegisterParams { /// Returns the metric description. pub fn description(&self) -> &str { From fe95d3d9e960e26bbe3bbd1d643029f73d9869b3 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 15:42:03 +0000 Subject: [PATCH 34/63] Comment cargo toml Signed-off-by: Andrei Sandu --- node/metrics/Cargo.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index 072ca1d5bfb2..3f63a7ab4e1f 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -12,11 +12,13 @@ tracing = "0.1.29" metered-channel = { path = "../metered-channel" } +# Both `sc-service` and `sc-cli` are required by runtime metrics `logger_hook()`. +sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } +sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } + substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" } -sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } codec = { package = "parity-scale-codec", version = "2.2.0" } -sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } primitives = { package = "polkadot-primitives", path = "../../primitives/" } bs58 = { version = "0.4.0", features = ["alloc"] } log = "0.4.13" From 1c6636584f376b8a7660246e2b1e569f313dc9d6 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 10 Dec 2021 15:58:05 +0000 Subject: [PATCH 35/63] Fix cargo toml description Signed-off-by: Andrei Sandu --- node/metrics/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index 3f63a7ab4e1f..c9e20e88506d 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -3,7 +3,7 @@ name = "polkadot-node-metrics" version = "0.9.13" authors = ["Parity Technologies "] edition = "2018" -description = "Subsystem traits and message definitions" +description = "Subsystem metric helpers" [dependencies] futures = "0.3.17" From cff26913e83bb9d897ca0aae6dca0cb3c8a6a1f9 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 10:34:29 +0000 Subject: [PATCH 36/63] Update doc. Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index d8eaa4800811..be00378df0a2 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -16,8 +16,12 @@ //! Runtime Metrics helpers. //! -//! Builds on top of Substrate wasm tracing support. -#![cfg(feature = "with-tracing")] +//! A runtime metric provider implementation that builds on top of Substrate wasm +//! tracing support. This requires that the custom profiler (`TraceHandler`) to be +//! registered in substrate via a `logger_hook()`. Events emitted from runtime are +//! then captured/processed by the `TraceHandler` implementation. +//! +#![cfg(feature = "runtime-metrics")] use codec::Decode; use primitives::v1::{ From a97a742837b8576ffbfd42dcd285777db85a61e6 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 10:34:56 +0000 Subject: [PATCH 37/63] switch to `runtime-metrics` feature Signed-off-by: Andrei Sandu --- cli/Cargo.toml | 2 +- node/client/Cargo.toml | 10 +++++----- node/metrics/Cargo.toml | 2 +- node/metrics/src/lib.rs | 6 +++--- node/service/Cargo.toml | 14 +++++++------- runtime/kusama/Cargo.toml | 2 +- runtime/metrics/Cargo.toml | 2 +- runtime/parachains/Cargo.toml | 2 +- runtime/polkadot/Cargo.toml | 2 +- runtime/rococo/Cargo.toml | 2 +- runtime/westend/Cargo.toml | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index cbce203b018f..11848c8e0051 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -67,4 +67,4 @@ rococo-native = [ "service/rococo-native" ] malus = [ "full-node", "service/malus" ] disputes = [ "service/disputes" ] -with-tracing = ["service/with-tracing", "polkadot-node-metrics/with-tracing"] +runtime-metrics = ["service/runtime-metrics", "polkadot-node-metrics/runtime-metrics"] diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index 59b6e8af928c..265a0a81c030 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -45,9 +45,9 @@ polkadot = ["polkadot-runtime"] kusama = ["kusama-runtime"] rococo = ["rococo-runtime"] westend = ["westend-runtime"] -with-tracing = [ - "rococo-runtime/with-tracing", - "kusama-runtime/with-tracing", - "westend-runtime/with-tracing", - "polkadot-runtime/with-tracing", +runtime-metrics = [ + "rococo-runtime/runtime-metrics", + "kusama-runtime/runtime-metrics", + "westend-runtime/runtime-metrics", + "polkadot-runtime/runtime-metrics", ] diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index c9e20e88506d..e28ea6d51910 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -25,4 +25,4 @@ log = "0.4.13" [features] default = [] -with-tracing = [] +runtime-metrics = [] diff --git a/node/metrics/src/lib.rs b/node/metrics/src/lib.rs index 34436d7f8167..b13eeca0ca07 100644 --- a/node/metrics/src/lib.rs +++ b/node/metrics/src/lib.rs @@ -30,13 +30,13 @@ pub use metered_channel as metered; pub mod metronome; pub use self::metronome::Metronome; -#[cfg(feature = "with-tracing")] +#[cfg(feature = "runtime-metrics")] pub mod runtime; -#[cfg(feature = "with-tracing")] +#[cfg(feature = "runtime-metrics")] pub use self::runtime::logger_hook; /// Export a dummy logger hook when `wasm tracing` is not enabled. -#[cfg(not(feature = "with-tracing"))] +#[cfg(not(feature = "runtime-metrics"))] pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () { |_logger_builder, _config| {} } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 5095310fe2fc..257c1bbe740e 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -179,11 +179,11 @@ try-runtime = [ ] malus = ["full-node"] disputes = ["polkadot-node-core-dispute-coordinator/disputes"] -with-tracing = [ - "polkadot-client/with-tracing", - "rococo-runtime/with-tracing", - "westend-runtime/with-tracing", - "kusama-runtime/with-tracing", - "polkadot-runtime/with-tracing", - "polkadot-runtime-parachains/with-tracing" +runtime-metrics = [ + "polkadot-client/runtime-metrics", + "rococo-runtime/runtime-metrics", + "westend-runtime/runtime-metrics", + "kusama-runtime/runtime-metrics", + "polkadot-runtime/runtime-metrics", + "polkadot-runtime-parachains/runtime-metrics" ] \ No newline at end of file diff --git a/runtime/kusama/Cargo.toml b/runtime/kusama/Cargo.toml index 18d066ecc3c1..d9c82714b7a2 100644 --- a/runtime/kusama/Cargo.toml +++ b/runtime/kusama/Cargo.toml @@ -270,4 +270,4 @@ disable-runtime-api = [] on-chain-release-build = [ "sp-api/disable-logging", ] -with-tracing = ["frame-executive/with-tracing", "sp-io/with-tracing"] +runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] \ No newline at end of file diff --git a/runtime/metrics/Cargo.toml b/runtime/metrics/Cargo.toml index 4d9b06fb1103..edd1d8ae28e7 100644 --- a/runtime/metrics/Cargo.toml +++ b/runtime/metrics/Cargo.toml @@ -22,4 +22,4 @@ std = [ "primitives/std", "bs58/std" ] -with-tracing = ["sp-tracing/with-tracing"] +runtime-metrics = ["sp-tracing/with-tracing"] diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index c2bb8a9c8b8f..d365f1af87bf 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -101,4 +101,4 @@ try-runtime = [ "pallet-timestamp/try-runtime", "pallet-vesting/try-runtime", ] -with-tracing = ["sp-tracing/with-tracing", "polkadot-runtime-metrics/with-tracing"] +runtime-metrics = ["sp-tracing/with-tracing", "polkadot-runtime-metrics/runtime-metrics"] diff --git a/runtime/polkadot/Cargo.toml b/runtime/polkadot/Cargo.toml index 73d09e9eb824..0a4b74c6a160 100644 --- a/runtime/polkadot/Cargo.toml +++ b/runtime/polkadot/Cargo.toml @@ -257,4 +257,4 @@ disable-runtime-api = [] on-chain-release-build = [ "sp-api/disable-logging", ] -with-tracing = ["frame-executive/with-tracing", "sp-io/with-tracing"] +runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] \ No newline at end of file diff --git a/runtime/rococo/Cargo.toml b/runtime/rococo/Cargo.toml index 5dec85d100e9..73814d820fe8 100644 --- a/runtime/rococo/Cargo.toml +++ b/runtime/rococo/Cargo.toml @@ -205,4 +205,4 @@ try-runtime = [ "pallet-multisig/try-runtime", ] -with-tracing = ["runtime-parachains/with-tracing", "frame-executive/with-tracing", "sp-io/with-tracing"] \ No newline at end of file +runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] \ No newline at end of file diff --git a/runtime/westend/Cargo.toml b/runtime/westend/Cargo.toml index afc82717cfdb..ddf03aac41cf 100644 --- a/runtime/westend/Cargo.toml +++ b/runtime/westend/Cargo.toml @@ -254,4 +254,4 @@ try-runtime = [ # runtime without clashing with the runtime API exported functions # in WASM. disable-runtime-api = [] -with-tracing = ["frame-executive/with-tracing", "sp-io/with-tracing"] +runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] \ No newline at end of file From eab86b2575a3993fa2a874fd64cf626d52fdd8f4 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 10:35:56 +0000 Subject: [PATCH 38/63] fmt Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index be00378df0a2..6b75c53c4552 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -16,11 +16,11 @@ //! Runtime Metrics helpers. //! -//! A runtime metric provider implementation that builds on top of Substrate wasm +//! A runtime metric provider implementation that builds on top of Substrate wasm //! tracing support. This requires that the custom profiler (`TraceHandler`) to be //! registered in substrate via a `logger_hook()`. Events emitted from runtime are //! then captured/processed by the `TraceHandler` implementation. -//! +//! #![cfg(feature = "runtime-metrics")] use codec::Decode; From 9d64fd0df02dc8c8f5e76dbb3bcfdf02e7fd7a8e Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 10:48:10 +0000 Subject: [PATCH 39/63] cargo toml Signed-off-by: Andrei Sandu --- Cargo.lock | 11 +++++++++++ Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0924d352f443..e1b4949b8e6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6828,6 +6828,17 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "polkadot-runtime-metrics" +version = "0.9.13" +dependencies = [ + "bs58", + "parity-scale-codec", + "polkadot-primitives", + "sp-std", + "sp-tracing", +] + [[package]] name = "polkadot-runtime-parachains" version = "0.9.13" diff --git a/Cargo.toml b/Cargo.toml index dabb92cc6e10..4e2b00f205c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,7 +118,7 @@ panic = "unwind" runtime-benchmarks= [ "polkadot-cli/runtime-benchmarks" ] try-runtime = [ "polkadot-cli/try-runtime" ] disputes = [ "polkadot-cli/disputes" ] -with-tracing = [ "polkadot-cli/with-tracing" ] +runtime-metrics = [ "polkadot-cli/runtime-metrics" ] # Configuration for building a .deb package - for use with `cargo-deb` [package.metadata.deb] From 27037298ffd693bc86bd4e19ff52365800da5824 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 11:08:40 +0000 Subject: [PATCH 40/63] fix tests Signed-off-by: Andrei Sandu --- cli/src/command.rs | 2 +- node/metrics/src/runtime.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 77441c5100b5..1b024d7df9cb 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -222,7 +222,7 @@ fn host_perf_check() -> Result<()> { /// for integration tests as needed. #[cfg(feature = "malus")] pub fn run_node(run: Cli, overseer_gen: impl service::OverseerGen) -> Result<()> { - run_node_inner(run, overseer_gen) + run_node_inner(run, overseer_gen, |_, _| {}) } fn run_node_inner( diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 6b75c53c4552..6fe2b3867b31 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -120,12 +120,10 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { .as_slice(), ) { Ok(update_op) => { - println!("Received metric: {:?}", update_op); self.parse_metric_update(update_op); }, Err(e) => { - println!("Failed to decode metric: {:?}", e); - tracing::error!("TraceEvent decode failed: {:?}", e); + tracing::error!(target: LOG_TARGET, "TraceEvent decode failed: {:?}", e); }, } } From fdc99dc2f79475ea59335da2489953548fd15714 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 11:25:31 +0000 Subject: [PATCH 41/63] fixes Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 7 ++++--- primitives/src/v1/mod.rs | 6 +++--- runtime/parachains/src/paras_inherent/mod.rs | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 6fe2b3867b31..78845eff2755 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -34,8 +34,9 @@ use std::{ use substrate_prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64}; const LOG_TARGET: &'static str = "metrics::runtime"; +const METRIC_PREFIX: &'static str = "polkadot"; -/// Support only CounterVec for now. +/// Support only `CounterVec` for now. /// TODO: add more when needed. #[derive(Clone, Default)] pub struct Metrics { @@ -67,7 +68,7 @@ impl RuntimeMetricsProvider { metric_name.to_owned(), register( CounterVec::new( - Opts::new(metric_name, params.description()), + Opts::new(format!("{}_{}", METRIC_PREFIX, metric_name), params.description()), ¶ms.labels(), )?, &self.0, @@ -161,7 +162,7 @@ impl RuntimeMetricsProvider { } } -/// Returns the custom profiling closure that we'll apply to the LoggerBuilder. +/// Returns the custom profiling closure that we'll apply to the `LoggerBuilder`. pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () { |logger_builder, config| { if config.prometheus_registry().is_none() { diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index b561bd94c354..70708f8be73b 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -1467,14 +1467,14 @@ impl RuntimeMetricRegisterParams { vec_to_str(&self.description, "No description provided.") } - /// Returns a labels as Vec<&str>. + /// Returns a labels as `Vec<&str>`. pub fn labels(&self) -> Vec<&str> { self.labels.as_str() } } impl RuntimeMetricLabels { - /// Returns a labels as Vec<&str>. + /// Returns a labels as `Vec<&str>`. pub fn as_str(&self) -> Vec<&str> { self.0 .iter() @@ -1519,7 +1519,7 @@ pub type RuntimeMetricLabelValue = RuntimeMetricLabel; /// A set of metric label values. pub type RuntimeMetricLabelValues = RuntimeMetricLabels; -/// Trait for converting Vec to &str. +/// Trait for converting Vec to `&str`. pub trait AsStr { /// Return a str reference. fn as_str(&self) -> Option<&str>; diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 4134a1135f97..9acdc18206bf 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -263,14 +263,14 @@ impl Pallet { } = data; sp_io::init_tracing(); let mut prefilter_weight_metric = - CounterVec::new("polkadot_create_inherent_prefilter_weight"); + CounterVec::new("create_inherent_prefilter_weight"); let mut bitfields_processed_metric = - CounterVec::new("polkadot_create_inherent_bitfields_processed"); + CounterVec::new("create_inherent_bitfields_processed"); let mut candidates_processed_metric = - CounterVec::new("polkadot_create_inherent_candidates_processed"); + CounterVec::new("create_inherent_candidates_processed"); let mut total_weight_metric = CounterVec::new("create_inherent_total_weight"); let mut disputes_processed = CounterVec::new_with_labels( - "polkadot_create_inherent_disputes_processed", + "create_inherent_disputes_processed", "Counts the how many dispute signatures have been checked", sp_std::vec!["validity".into()].into(), ); From 2eb038dac606165535bcbdecc2a94ea6b68e4d4f Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 19:37:56 +0000 Subject: [PATCH 42/63] better ux Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 23 ++++- primitives/src/v1/mod.rs | 22 ++--- runtime/metrics/src/lib.rs | 31 +++---- runtime/parachains/src/paras_inherent/mod.rs | 98 +++++++++++++++----- 4 files changed, 116 insertions(+), 58 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 78845eff2755..361d4972aecb 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -64,12 +64,16 @@ impl RuntimeMetricsProvider { return Ok(()) } + let metric_name = format!("{}_{}", METRIC_PREFIX, metric_name); unlocked_hashtable.insert( metric_name.to_owned(), register( CounterVec::new( - Opts::new(format!("{}_{}", METRIC_PREFIX, metric_name), params.description()), - ¶ms.labels(), + Opts::new( + metric_name, + params.description(), + ), + ¶ms.labels().unwrap_or_default(), )?, &self.0, )?, @@ -85,10 +89,19 @@ impl RuntimeMetricsProvider { } /// Increment a counter vec by a value. - pub fn inc_counter_by(&self, name: &str, value: u64, labels: &RuntimeMetricLabelValues) { + pub fn inc_counter_by( + &self, + name: &str, + value: u64, + labels: Option<&RuntimeMetricLabelValues>, + ) { let _ = self.1.counter_vecs.lock().map(|mut unlocked_hashtable| { if let Some(counter_vec) = unlocked_hashtable.get_mut(name) { - counter_vec.with_label_values(&labels.as_str()).inc_by(value); + + match labels { + Some(labels) => counter_vec.with_label_values(&labels.as_str()).inc_by(value), + None => counter_vec.with_label_values(&vec![""]).inc_by(value), + } } else { tracing::error!( target: LOG_TARGET, @@ -139,7 +152,7 @@ impl RuntimeMetricsProvider { let _ = self.register_countervec(update.metric_name(), ¶ms); }, RuntimeMetricOp::Increment(value, ref labels) => - self.inc_counter_by(update.metric_name(), value, labels), + self.inc_counter_by(update.metric_name(), value, labels.as_ref()), } } diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index 70708f8be73b..9b4ba3cc4a45 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -1423,7 +1423,7 @@ pub enum RuntimeMetricOp { /// Register a new metric. Register(RuntimeMetricRegisterParams), /// Increment metric by value. - Increment(u64, RuntimeMetricLabelValues), + Increment(u64, Option), } /// Metric registration parameters. @@ -1431,12 +1431,12 @@ pub enum RuntimeMetricOp { #[cfg_attr(feature = "std", derive(Debug))] pub struct RuntimeMetricRegisterParams { description: Vec, - labels: RuntimeMetricLabels, + labels: Option, } impl RuntimeMetricRegisterParams { /// Create new metric registration params. - pub fn new(description: Vec, labels: RuntimeMetricLabels) -> Self { + pub fn new(description: Vec, labels: Option) -> Self { Self { description, labels } } } @@ -1451,12 +1451,6 @@ pub struct RuntimeMetricUpdate { pub op: RuntimeMetricOp, } -#[cfg(feature = "std")] -fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { - return std::str::from_utf8(v).unwrap_or(default) -} - -#[cfg(not(feature = "std"))] fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { return sp_std::str::from_utf8(v).unwrap_or(default) } @@ -1467,9 +1461,9 @@ impl RuntimeMetricRegisterParams { vec_to_str(&self.description, "No description provided.") } - /// Returns a labels as `Vec<&str>`. - pub fn labels(&self) -> Vec<&str> { - self.labels.as_str() + /// Returns a label names as an `Option` of `Vec<&str>`. + pub fn labels(&self) -> Option> { + self.labels.as_ref().map(|labels| labels.as_str()) } } @@ -1488,8 +1482,8 @@ impl RuntimeMetricLabels { } } -impl From> for RuntimeMetricLabels { - fn from(v: Vec<&'static str>) -> RuntimeMetricLabels { +impl From<&[&'static str]> for RuntimeMetricLabels { + fn from(v: &[&'static str]) -> RuntimeMetricLabels { RuntimeMetricLabels( v.iter().map(|label| RuntimeMetricLabel(label.as_bytes().to_vec())).collect(), ) diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index c2c6f1a04090..c917ddb91ae8 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -21,39 +21,40 @@ //! and command line configuration: `--tracing-targets wasm_tracing=trace`. #![cfg_attr(not(feature = "std"), no_std)] -use primitives::v1::{RuntimeMetricLabelValues, RuntimeMetricLabels}; #[cfg(not(feature = "std"))] use parity_scale_codec::Encode; #[cfg(not(feature = "std"))] -use primitives::v1::{RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate}; +use primitives::v1::{ + RuntimeMetricLabelValues, RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate, +}; #[cfg(not(feature = "std"))] pub struct CounterVec { name: &'static str, - label_values: RuntimeMetricLabelValues, + label_values: Option, } #[cfg(not(feature = "std"))] impl CounterVec { /// Create a new counter metric. - pub fn new(name: &'static str) -> Self { - Self::new_with_labels(name, "No description provided", RuntimeMetricLabels::default()) + pub fn new(name: &'static str, description: &'static str) -> Self { + Self::new_with_labels(name, description, &sp_std::vec::Vec::new()) } /// Create a new counter metric with specified `labels`. pub fn new_with_labels( name: &'static str, description: &'static str, - labels: RuntimeMetricLabels, + labels: &[&'static str], ) -> Self { // Send a register metric operation to node side. let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(name), op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new( sp_std::vec::Vec::from(description), - labels, + Some(labels.into()), )), } .encode(); @@ -70,12 +71,12 @@ impl CounterVec { ); } - CounterVec { name, label_values: RuntimeMetricLabelValues::default() } + CounterVec { name, label_values: None } } /// Set label values. - pub fn with_label_values(&mut self, label_values: RuntimeMetricLabelValues) -> &mut Self { - self.label_values = label_values; + pub fn with_label_values(&mut self, label_values: &[&'static str]) -> &mut Self { + self.label_values = Some(label_values.into()); self } @@ -83,7 +84,7 @@ impl CounterVec { pub fn inc_by(&mut self, value: u64) { let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(self.name), - op: RuntimeMetricOp::Increment(value, self.label_values.clone()), + op: RuntimeMetricOp::Increment(value, self.label_values.take()), } .encode(); @@ -98,8 +99,6 @@ impl CounterVec { update_op = update_op.as_str() ); } - - self.label_values.clear(); } } @@ -109,18 +108,18 @@ pub struct CounterVec; /// Dummy implementation. #[cfg(feature = "std")] impl CounterVec { - pub fn new(_: &'static str) -> Self { + pub fn new(_name: &'static str, _description: &'static str) -> Self { CounterVec } pub fn new_with_labels( _name: &'static str, _description: &'static str, - _labels: RuntimeMetricLabels, + _labels: &[&'static str], ) -> Self { CounterVec } - pub fn with_label_values(&mut self, _: RuntimeMetricLabelValues) -> &mut Self { + pub fn with_label_values(&mut self, _label_values: &[&'static str]) -> &mut Self { self } diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 9acdc18206bf..c45472a6fc4b 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -262,25 +262,34 @@ impl Pallet { mut disputes, } = data; sp_io::init_tracing(); - let mut prefilter_weight_metric = - CounterVec::new("create_inherent_prefilter_weight"); - let mut bitfields_processed_metric = - CounterVec::new("create_inherent_bitfields_processed"); - let mut candidates_processed_metric = - CounterVec::new("create_inherent_candidates_processed"); - let mut total_weight_metric = CounterVec::new("create_inherent_total_weight"); - let mut disputes_processed = CounterVec::new_with_labels( - "create_inherent_disputes_processed", - "Counts the how many dispute signatures have been checked", - sp_std::vec!["validity".into()].into(), + let mut weight_metric = CounterVec::new_with_labels( + "parachain_inherent_data_weight", + "Inherent data weight before and after filtering", + &vec!["when"] ); - disputes_processed - .with_label_values(sp_std::vec!["valid".into()].into()) - .inc_by(100); - disputes_processed - .with_label_values(sp_std::vec!["invalid".into()].into()) - .inc_by(200); + // let mut bitfields_processed_metric = CounterVec::new( + // "parachain_inherent_data_bitfields_processed", + // "Counts the number of bitfields processed in `enter_inner`.", + // ); + + let mut candidates_processed_metric = CounterVec::new_with_labels( + "parachain_inherent_data_candidates_processed", + "Counts the number of parachain block candidates processed in `enter_inner`.", + &vec!["category"], + ); + + let mut dispute_sets_processed_metric = CounterVec::new_with_labels( + "parachain_inherent_data_dispute_sets_processed", + "Counts the number of dispute statements sets processed in `enter_inner`.", + &vec!["category"] + ); + + // let mut disputes_included_metric = CounterVec::new( + // "parachain_inherent_data_disputes_included", + // "Counts the number of dispute statements sets included in a block in `enter_inner`.", + // ); + log::debug!( target: LOG_TARGET, @@ -290,6 +299,10 @@ impl Pallet { disputes.len() ); + dispute_sets_processed_metric + .with_label_values(&vec!["total"]) + .inc_by(disputes.len() as u64); + // Check that the submitted parent header indeed corresponds to the previous block hash. let parent_hash = >::parent_hash(); ensure!( @@ -305,7 +318,7 @@ impl Pallet { let max_block_weight = ::BlockWeights::get().max_block; - prefilter_weight_metric.inc_by(candidate_weight + bitfields_weight + disputes_weight); + weight_metric.with_label_values(&vec!["before-filter"]).inc_by(candidate_weight + bitfields_weight + disputes_weight); // Potentially trim inherent data to ensure processing will be within weight limits let total_weight = { @@ -353,11 +366,21 @@ impl Pallet { // Note that `provide_multi_dispute_data` will iterate, verify, and import each // dispute; so the input here must be reasonably bounded. let _ = T::DisputesHandler::provide_multi_dispute_data(disputes.clone())?; + dispute_sets_processed_metric.with_label_values(&vec!["imported)"]).inc_by(disputes.len() as u64); + if T::DisputesHandler::is_frozen() { + // Relay chain freeze, at this point we will not include any parachain blocks. + dispute_sets_processed_metric.with_label_values(&vec!["frozen)"]).inc_by(1); + // The relay chain we are currently on is invalid. Proceed no further on parachains. return Ok(Some(dispute_statements_weight::(&disputes)).into()) } + // Process the dispute sets of the current session. + dispute_sets_processed_metric + .with_label_values(&vec!["current_session)"]) + .inc_by(new_current_dispute_sets.len() as u64); + let mut freed_disputed = if !new_current_dispute_sets.is_empty() { let concluded_invalid_disputes = new_current_dispute_sets .iter() @@ -367,11 +390,22 @@ impl Pallet { .map(|(_, candidate)| *candidate) .collect::>(); - let freed_disputed = + // Count invalid dispute sets. + dispute_sets_processed_metric + .with_label_values(&vec!["concluded_invalid)"]) + .inc_by(concluded_invalid_disputes.len() as u64); + + let freed_disputed: Vec<_> = >::collect_disputed(&concluded_invalid_disputes) .into_iter() .map(|core| (core, FreedReason::Concluded)) .collect(); + + // Count concluded disputes. + dispute_sets_processed_metric + .with_label_values(&vec!["concluded_valid)"]) + .inc_by(freed_disputed.len() as u64); + freed_disputed } else { Vec::new() @@ -394,7 +428,7 @@ impl Pallet { disputed_bitfield }; - bitfields_processed_metric.inc_by(signed_bitfields.len().try_into().unwrap_or_default()); + // bitfields_processed_metric.inc_by(signed_bitfields.len() as u64); // Process new availability bitfields, yielding any availability cores whose // work has now concluded. let freed_concluded = >::process_bitfields( @@ -409,11 +443,17 @@ impl Pallet { T::DisputesHandler::note_included(current_session, *candidate_hash, now); } + candidates_processed_metric + .with_label_values(&vec!["included"]) + .inc_by(freed_concluded.len() as u64); let freed = collect_all_freed_cores::(freed_concluded.iter().cloned()); >::clear(); >::schedule(freed, now); + candidates_processed_metric + .with_label_values(&vec!["total"]) + .inc_by(backed_candidates.len() as u64); let scheduled = >::scheduled(); let backed_candidates = sanitize_backed_candidates::( parent_hash, @@ -424,8 +464,9 @@ impl Pallet { }, &scheduled[..], ); - - candidates_processed_metric.inc_by(backed_candidates.len().try_into().unwrap_or_default()); + candidates_processed_metric + .with_label_values(&vec!["sanitized"]) + .inc_by(backed_candidates.len() as u64); // Process backed candidates according to scheduled cores. let parent_storage_root = parent_header.state_root().clone(); @@ -440,6 +481,8 @@ impl Pallet { full_check, )?; + // disputes_included_metric.inc_by(disputes.len() as u64); + // The number of disputes included in a block is // limited by the weight as well as the number of candidate blocks. OnChainVotes::::put(ScrapedOnChainVotes::<::Hash> { @@ -455,7 +498,7 @@ impl Pallet { // this is max config.ump_service_total_weight let _ump_weight = >::process_pending_upward_messages(); - total_weight_metric.inc_by(total_weight); + weight_metric.with_label_values(&vec!["after-filter"]).inc_by(total_weight); Ok(Some(total_weight).into()) } @@ -825,6 +868,12 @@ pub(crate) fn sanitize_bitfields( validators: &[ValidatorId], full_check: FullCheck, ) -> UncheckedSignedAvailabilityBitfields { + let mut bitfields_signature_checks_metric = CounterVec::new_with_labels( + "create_inherent_bitfields_signature_checks", + "Counts the number of bitfields signature checked in `enter_inner`.", + &vec!["validity"], + ); + let mut bitfields = Vec::with_capacity(unchecked_bitfields.len()); let mut last_index: Option = None; @@ -890,12 +939,15 @@ pub(crate) fn sanitize_bitfields( let validator_public = &validators[validator_index.0 as usize]; if let FullCheck::Yes = full_check { + // Validate bitfield signature. if let Ok(signed_bitfield) = unchecked_bitfield.try_into_checked(&signing_context, validator_public) { bitfields.push(signed_bitfield.into_unchecked()); + bitfields_signature_checks_metric.with_label_values(&vec!["valid"]).inc_by(1); } else { log::warn!(target: LOG_TARGET, "Invalid bitfield signature"); + bitfields_signature_checks_metric.with_label_values(&vec!["invalid"]).inc_by(1); }; } else { bitfields.push(unchecked_bitfield); From ca4dd9fafe370b401e6e501763c4fa64f3949f72 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 19:46:42 +0000 Subject: [PATCH 43/63] from_utf8_unchecked is safe Signed-off-by: Andrei Sandu --- runtime/metrics/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index c917ddb91ae8..878216472e46 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -59,7 +59,10 @@ impl CounterVec { } .encode(); - // `from_utf8_unchecked` is safe, we only care about the `metric_name` which is static str. + // `from_utf8_unchecked` is safe in this context: + // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding + // provides that guarantee forward. We just need to `transmute` as the layout of `&str` + // and `&[u8]` is the same. unsafe { let register_metric_op = bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); @@ -88,7 +91,10 @@ impl CounterVec { } .encode(); - // `from_utf8_unchecked` is safe, we only care about the `metric_name` which is static str. + // `from_utf8_unchecked` is safe in this context: + // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding + // provides that guarantee forward. We just need to `transmute` as the layout of `&str` + // and `&[u8]` is the same. unsafe { let update_op = bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); From 977f84dcc72209e4fc0fe1e997bc798e7b0be379 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 19:47:02 +0000 Subject: [PATCH 44/63] fmt Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 6 +----- runtime/metrics/src/lib.rs | 4 ++-- runtime/parachains/src/paras_inherent/mod.rs | 13 ++++++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 361d4972aecb..87ca0a734134 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -69,10 +69,7 @@ impl RuntimeMetricsProvider { metric_name.to_owned(), register( CounterVec::new( - Opts::new( - metric_name, - params.description(), - ), + Opts::new(metric_name, params.description()), ¶ms.labels().unwrap_or_default(), )?, &self.0, @@ -97,7 +94,6 @@ impl RuntimeMetricsProvider { ) { let _ = self.1.counter_vecs.lock().map(|mut unlocked_hashtable| { if let Some(counter_vec) = unlocked_hashtable.get_mut(name) { - match labels { Some(labels) => counter_vec.with_label_values(&labels.as_str()).inc_by(value), None => counter_vec.with_label_values(&vec![""]).inc_by(value), diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index 878216472e46..1e3b35690f7a 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -62,7 +62,7 @@ impl CounterVec { // `from_utf8_unchecked` is safe in this context: // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding // provides that guarantee forward. We just need to `transmute` as the layout of `&str` - // and `&[u8]` is the same. + // and `&[u8]` is the same. unsafe { let register_metric_op = bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); @@ -94,7 +94,7 @@ impl CounterVec { // `from_utf8_unchecked` is safe in this context: // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding // provides that guarantee forward. We just need to `transmute` as the layout of `&str` - // and `&[u8]` is the same. + // and `&[u8]` is the same. unsafe { let update_op = bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index c45472a6fc4b..15710a91dcc7 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -265,7 +265,7 @@ impl Pallet { let mut weight_metric = CounterVec::new_with_labels( "parachain_inherent_data_weight", "Inherent data weight before and after filtering", - &vec!["when"] + &vec!["when"], ); // let mut bitfields_processed_metric = CounterVec::new( @@ -282,7 +282,7 @@ impl Pallet { let mut dispute_sets_processed_metric = CounterVec::new_with_labels( "parachain_inherent_data_dispute_sets_processed", "Counts the number of dispute statements sets processed in `enter_inner`.", - &vec!["category"] + &vec!["category"], ); // let mut disputes_included_metric = CounterVec::new( @@ -290,7 +290,6 @@ impl Pallet { // "Counts the number of dispute statements sets included in a block in `enter_inner`.", // ); - log::debug!( target: LOG_TARGET, "[enter] bitfields.len(): {}, backed_candidates.len(): {}, disputes.len() {}", @@ -318,7 +317,9 @@ impl Pallet { let max_block_weight = ::BlockWeights::get().max_block; - weight_metric.with_label_values(&vec!["before-filter"]).inc_by(candidate_weight + bitfields_weight + disputes_weight); + weight_metric + .with_label_values(&vec!["before-filter"]) + .inc_by(candidate_weight + bitfields_weight + disputes_weight); // Potentially trim inherent data to ensure processing will be within weight limits let total_weight = { @@ -366,7 +367,9 @@ impl Pallet { // Note that `provide_multi_dispute_data` will iterate, verify, and import each // dispute; so the input here must be reasonably bounded. let _ = T::DisputesHandler::provide_multi_dispute_data(disputes.clone())?; - dispute_sets_processed_metric.with_label_values(&vec!["imported)"]).inc_by(disputes.len() as u64); + dispute_sets_processed_metric + .with_label_values(&vec!["imported)"]) + .inc_by(disputes.len() as u64); if T::DisputesHandler::is_frozen() { // Relay chain freeze, at this point we will not include any parachain blocks. From e7c563632a974b9fdac1f098c9eff66e3bae8f53 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 21:00:45 +0000 Subject: [PATCH 45/63] Add Counter and refactor Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 129 +++++++++++++------ primitives/src/v1/metrics.rs | 121 +++++++++++++++++ primitives/src/v1/mod.rs | 122 +----------------- runtime/metrics/src/lib.rs | 112 +--------------- runtime/metrics/src/nostd.rs | 113 ++++++++++++++++ runtime/metrics/src/std.rs | 50 +++++++ runtime/parachains/src/paras_inherent/mod.rs | 34 ++--- 7 files changed, 401 insertions(+), 280 deletions(-) create mode 100644 primitives/src/v1/metrics.rs create mode 100644 runtime/metrics/src/nostd.rs create mode 100644 runtime/metrics/src/std.rs diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 87ca0a734134..9186abdda1ab 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -29,9 +29,11 @@ use primitives::v1::{ }; use std::{ collections::hash_map::HashMap, - sync::{Arc, Mutex}, + sync::{Arc, Mutex, MutexGuard}, +}; +use substrate_prometheus_endpoint::{ + register, Counter, CounterVec, Opts, PrometheusError, Registry, U64, }; -use substrate_prometheus_endpoint::{register, CounterVec, Opts, PrometheusError, Registry, U64}; const LOG_TARGET: &'static str = "metrics::runtime"; const METRIC_PREFIX: &'static str = "polkadot"; @@ -41,7 +43,9 @@ const METRIC_PREFIX: &'static str = "polkadot"; #[derive(Clone, Default)] pub struct Metrics { counter_vecs: Arc>>>, + counters: Arc>>>, } + /// Runtime metrics wrapper. #[derive(Clone)] pub struct RuntimeMetricsProvider(Registry, Metrics); @@ -53,19 +57,11 @@ impl RuntimeMetricsProvider { } /// Register a counter vec metric. - pub fn register_countervec( - &self, - metric_name: &str, - params: &RuntimeMetricRegisterParams, - ) -> Result<(), PrometheusError> { - match self.1.counter_vecs.lock() { - Ok(mut unlocked_hashtable) => { - if unlocked_hashtable.contains_key(metric_name) { - return Ok(()) - } - + pub fn register_countervec(&self, metric_name: &str, params: &RuntimeMetricRegisterParams) { + self.with_counter_vecs_lock_held(|mut hashmap| { + if !hashmap.contains_key(metric_name) { let metric_name = format!("{}_{}", METRIC_PREFIX, metric_name); - unlocked_hashtable.insert( + hashmap.insert( metric_name.to_owned(), register( CounterVec::new( @@ -75,36 +71,82 @@ impl RuntimeMetricsProvider { &self.0, )?, ); - }, - Err(e) => tracing::error!( - target: LOG_TARGET, - "Failed to acquire the `counter_vecs` lock: {:?}", - e - ), - } - Ok(()) + } + return Ok(()) + }) } - /// Increment a counter vec by a value. - pub fn inc_counter_by( - &self, - name: &str, - value: u64, - labels: Option<&RuntimeMetricLabelValues>, - ) { - let _ = self.1.counter_vecs.lock().map(|mut unlocked_hashtable| { - if let Some(counter_vec) = unlocked_hashtable.get_mut(name) { - match labels { - Some(labels) => counter_vec.with_label_values(&labels.as_str()).inc_by(value), - None => counter_vec.with_label_values(&vec![""]).inc_by(value), - } + /// Register a counter metric. + pub fn register_counter(&self, metric_name: &str, params: &RuntimeMetricRegisterParams) { + self.with_counters_lock_held(|mut hashmap| { + if !hashmap.contains_key(metric_name) { + let metric_name = format!("{}_{}", METRIC_PREFIX, metric_name); + hashmap.insert( + metric_name.to_owned(), + register(Counter::new(metric_name, params.description())?, &self.0)?, + ); + } + return Ok(()) + }) + } + + /// Increment a counter with labels by a value. + pub fn inc_counter_vec_by(&self, name: &str, value: u64, labels: &RuntimeMetricLabelValues) { + self.with_counter_vecs_lock_held(|mut hashmap| { + if let Some(counter_vec) = hashmap.get_mut(name) { + counter_vec.with_label_values(&labels.as_str()).inc_by(value); } else { tracing::error!( target: LOG_TARGET, - "Cannot increment counter `{}`, metric not in registered or present in hashtable", + "Cannot increment counter `{}`, metric not in registered or present in hashmap", name ); } + Ok(()) + }); + } + + /// Increment a counter by a value. + pub fn inc_counter_by(&self, name: &str, value: u64) { + self.with_counters_lock_held(|mut hashmap| { + if let Some(counter) = hashmap.get_mut(name) { + counter.inc_by(value); + } else { + tracing::error!( + target: LOG_TARGET, + "Cannot increment counter `{}`, metric not in registered or present in hashmap", + name + ); + } + Ok(()) + }) + } + + fn with_counters_lock_held(&self, do_something: F) + where + F: FnOnce(MutexGuard<'_, HashMap>>) -> Result<(), PrometheusError>, + { + let _ = self.1.counters.lock().map(do_something).or_else(|error| { + tracing::error!( + target: LOG_TARGET, + "Cannot acquire the counter hashmap lock: {:?}", + error + ); + Err(error) + }); + } + + fn with_counter_vecs_lock_held(&self, do_something: F) + where + F: FnOnce(MutexGuard<'_, HashMap>>) -> Result<(), PrometheusError>, + { + let _ = self.1.counter_vecs.lock().map(do_something).or_else(|error| { + tracing::error!( + target: LOG_TARGET, + "Cannot acquire the countervec hashmap lock: {:?}", + error + ); + Err(error) }); } } @@ -144,11 +186,16 @@ impl RuntimeMetricsProvider { // Parse end execute the update operation. fn parse_metric_update(&self, update: RuntimeMetricUpdate) { match update.op { - RuntimeMetricOp::Register(ref params) => { - let _ = self.register_countervec(update.metric_name(), ¶ms); - }, - RuntimeMetricOp::Increment(value, ref labels) => - self.inc_counter_by(update.metric_name(), value, labels.as_ref()), + RuntimeMetricOp::Register(ref params) => + if params.labels.is_none() { + self.register_counter(update.metric_name(), ¶ms); + } else { + self.register_countervec(update.metric_name(), ¶ms); + }, + RuntimeMetricOp::IncrementCounterVec(value, ref labels) => + self.inc_counter_vec_by(update.metric_name(), value, labels), + RuntimeMetricOp::IncrementCounter(value) => + self.inc_counter_by(update.metric_name(), value), } } diff --git a/primitives/src/v1/metrics.rs b/primitives/src/v1/metrics.rs new file mode 100644 index 000000000000..e8d83709ac5c --- /dev/null +++ b/primitives/src/v1/metrics.rs @@ -0,0 +1,121 @@ +use parity_scale_codec::{Decode, Encode}; +use sp_std::prelude::*; + +/// Metric registration parameters. +#[derive(Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RuntimeMetricRegisterParams { + /// Metric description. + description: Vec, + /// Only for counter vec. + pub labels: Option, +} + +/// Runtime metric operations. +#[derive(Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub enum RuntimeMetricOp { + /// Register a new metric. + Register(RuntimeMetricRegisterParams), + /// Increment a counter metric with labels by value. + IncrementCounterVec(u64, RuntimeMetricLabelValues), + /// Increment a counter metric with labels by value. + IncrementCounter(u64), +} + +impl RuntimeMetricRegisterParams { + /// Create new metric registration params. + pub fn new(description: Vec, labels: Option) -> Self { + Self { description, labels } + } +} + +/// Runtime metric update event. +#[derive(Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RuntimeMetricUpdate { + /// The name of the metric. + pub metric_name: Vec, + /// The operation applied to the metric. + pub op: RuntimeMetricOp, +} + +fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { + return sp_std::str::from_utf8(v).unwrap_or(default) +} + +impl RuntimeMetricRegisterParams { + /// Returns the metric description. + pub fn description(&self) -> &str { + vec_to_str(&self.description, "No description provided.") + } + + /// Returns a label names as an `Option` of `Vec<&str>`. + pub fn labels(&self) -> Option> { + self.labels.as_ref().map(|labels| labels.as_str()) + } +} + +impl RuntimeMetricLabels { + /// Returns a labels as `Vec<&str>`. + pub fn as_str(&self) -> Vec<&str> { + self.0 + .iter() + .map(|label_vec| vec_to_str(&label_vec.0, "invalid_label")) + .collect() + } + + /// Return the inner values as vec. + pub fn clear(&mut self) { + self.0.clear(); + } +} + +impl From<&[&'static str]> for RuntimeMetricLabels { + fn from(v: &[&'static str]) -> RuntimeMetricLabels { + RuntimeMetricLabels( + v.iter().map(|label| RuntimeMetricLabel(label.as_bytes().to_vec())).collect(), + ) + } +} + +impl RuntimeMetricUpdate { + /// Returns the metric name. + pub fn metric_name(&self) -> &str { + vec_to_str(&self.metric_name, "invalid_metric_name") + } +} + +/// A set of metric labels. +#[derive(Clone, Default, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RuntimeMetricLabels(Vec); + +/// A metric label. +#[derive(Clone, Default, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RuntimeMetricLabel(Vec); + +/// A metric label value. +pub type RuntimeMetricLabelValue = RuntimeMetricLabel; + +/// A set of metric label values. +pub type RuntimeMetricLabelValues = RuntimeMetricLabels; + +/// Trait for converting Vec to `&str`. +pub trait AsStr { + /// Return a str reference. + fn as_str(&self) -> Option<&str>; +} + +impl AsStr for RuntimeMetricLabel { + fn as_str(&self) -> Option<&str> { + sp_std::str::from_utf8(&self.0).ok() + } +} + +impl From<&'static str> for RuntimeMetricLabel { + fn from(s: &'static str) -> Self { + Self(s.as_bytes().to_vec()) + } +} diff --git a/primitives/src/v1/mod.rs b/primitives/src/v1/mod.rs index 9b4ba3cc4a45..c27d4be7ba31 100644 --- a/primitives/src/v1/mod.rs +++ b/primitives/src/v1/mod.rs @@ -63,6 +63,12 @@ pub use sp_staking::SessionIndex; mod signed; pub use signed::{EncodeAs, Signed, UncheckedSigned}; +mod metrics; +pub use metrics::{ + RuntimeMetricLabel, RuntimeMetricLabelValue, RuntimeMetricLabelValues, RuntimeMetricLabels, + RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate, +}; + /// A declarations of storage keys where an external observer can find some interesting data. pub mod well_known_keys { use super::{HrmpChannelId, Id}; @@ -1415,122 +1421,6 @@ pub fn supermajority_threshold(n: usize) -> usize { n - byzantine_threshold(n) } -// TODO: add feature gate. -/// Runtime metric operations. -#[derive(Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug))] -pub enum RuntimeMetricOp { - /// Register a new metric. - Register(RuntimeMetricRegisterParams), - /// Increment metric by value. - Increment(u64, Option), -} - -/// Metric registration parameters. -#[derive(Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug))] -pub struct RuntimeMetricRegisterParams { - description: Vec, - labels: Option, -} - -impl RuntimeMetricRegisterParams { - /// Create new metric registration params. - pub fn new(description: Vec, labels: Option) -> Self { - Self { description, labels } - } -} - -/// Runtime metric update event. -#[derive(Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug))] -pub struct RuntimeMetricUpdate { - /// The name of the metric. - pub metric_name: Vec, - /// The operation applied to the metric. - pub op: RuntimeMetricOp, -} - -fn vec_to_str<'a>(v: &'a Vec, default: &'static str) -> &'a str { - return sp_std::str::from_utf8(v).unwrap_or(default) -} - -impl RuntimeMetricRegisterParams { - /// Returns the metric description. - pub fn description(&self) -> &str { - vec_to_str(&self.description, "No description provided.") - } - - /// Returns a label names as an `Option` of `Vec<&str>`. - pub fn labels(&self) -> Option> { - self.labels.as_ref().map(|labels| labels.as_str()) - } -} - -impl RuntimeMetricLabels { - /// Returns a labels as `Vec<&str>`. - pub fn as_str(&self) -> Vec<&str> { - self.0 - .iter() - .map(|label_vec| vec_to_str(&label_vec.0, "invalid_label")) - .collect() - } - - /// Return the inner values as vec. - pub fn clear(&mut self) { - self.0.clear(); - } -} - -impl From<&[&'static str]> for RuntimeMetricLabels { - fn from(v: &[&'static str]) -> RuntimeMetricLabels { - RuntimeMetricLabels( - v.iter().map(|label| RuntimeMetricLabel(label.as_bytes().to_vec())).collect(), - ) - } -} - -impl RuntimeMetricUpdate { - /// Returns the metric name. - pub fn metric_name(&self) -> &str { - vec_to_str(&self.metric_name, "invalid_metric_name") - } -} - -/// A set of metric labels. -#[derive(Clone, Default, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug))] -pub struct RuntimeMetricLabels(Vec); - -/// A metric label. -#[derive(Clone, Default, Encode, Decode)] -#[cfg_attr(feature = "std", derive(Debug))] -pub struct RuntimeMetricLabel(Vec); - -/// A metric label value. -pub type RuntimeMetricLabelValue = RuntimeMetricLabel; - -/// A set of metric label values. -pub type RuntimeMetricLabelValues = RuntimeMetricLabels; - -/// Trait for converting Vec to `&str`. -pub trait AsStr { - /// Return a str reference. - fn as_str(&self) -> Option<&str>; -} - -impl AsStr for RuntimeMetricLabel { - fn as_str(&self) -> Option<&str> { - sp_std::str::from_utf8(&self.0).ok() - } -} - -impl From<&'static str> for RuntimeMetricLabel { - fn from(s: &'static str) -> Self { - Self(s.as_bytes().to_vec()) - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index 1e3b35690f7a..c4544df22ff1 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -22,112 +22,12 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] -use parity_scale_codec::Encode; - -#[cfg(not(feature = "std"))] -use primitives::v1::{ - RuntimeMetricLabelValues, RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate, -}; - -#[cfg(not(feature = "std"))] -pub struct CounterVec { - name: &'static str, - label_values: Option, -} - -#[cfg(not(feature = "std"))] -impl CounterVec { - /// Create a new counter metric. - pub fn new(name: &'static str, description: &'static str) -> Self { - Self::new_with_labels(name, description, &sp_std::vec::Vec::new()) - } - - /// Create a new counter metric with specified `labels`. - pub fn new_with_labels( - name: &'static str, - description: &'static str, - labels: &[&'static str], - ) -> Self { - // Send a register metric operation to node side. - let metric_update = RuntimeMetricUpdate { - metric_name: sp_std::vec::Vec::from(name), - op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new( - sp_std::vec::Vec::from(description), - Some(labels.into()), - )), - } - .encode(); - - // `from_utf8_unchecked` is safe in this context: - // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding - // provides that guarantee forward. We just need to `transmute` as the layout of `&str` - // and `&[u8]` is the same. - unsafe { - let register_metric_op = - bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); - - sp_tracing::event!( - target: "metrics", - sp_tracing::Level::TRACE, - update_op = register_metric_op.as_str() - ); - } - - CounterVec { name, label_values: None } - } - - /// Set label values. - pub fn with_label_values(&mut self, label_values: &[&'static str]) -> &mut Self { - self.label_values = Some(label_values.into()); - self - } - - /// Increment by `value`. - pub fn inc_by(&mut self, value: u64) { - let metric_update = RuntimeMetricUpdate { - metric_name: sp_std::vec::Vec::from(self.name), - op: RuntimeMetricOp::Increment(value, self.label_values.take()), - } - .encode(); - - // `from_utf8_unchecked` is safe in this context: - // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding - // provides that guarantee forward. We just need to `transmute` as the layout of `&str` - // and `&[u8]` is the same. - unsafe { - let update_op = - bs58::encode(sp_std::str::from_utf8_unchecked(&metric_update)).into_string(); - - sp_tracing::event!( - target: "metrics", - sp_tracing::Level::TRACE, - update_op = update_op.as_str() - ); - } - } -} - #[cfg(feature = "std")] -pub struct CounterVec; - -/// Dummy implementation. +mod std; #[cfg(feature = "std")] -impl CounterVec { - pub fn new(_name: &'static str, _description: &'static str) -> Self { - CounterVec - } - pub fn new_with_labels( - _name: &'static str, - _description: &'static str, - _labels: &[&'static str], - ) -> Self { - CounterVec - } - - pub fn with_label_values(&mut self, _label_values: &[&'static str]) -> &mut Self { - self - } +pub use crate::std::*; - pub fn inc_by(&mut self, _: u64) {} -} +#[cfg(not(feature = "std"))] +mod nostd; +#[cfg(not(feature = "std"))] +pub use crate::nostd::*; diff --git a/runtime/metrics/src/nostd.rs b/runtime/metrics/src/nostd.rs new file mode 100644 index 000000000000..1f428565af42 --- /dev/null +++ b/runtime/metrics/src/nostd.rs @@ -0,0 +1,113 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +const TRACING_TARGET: &'static str = "metrics"; + +use parity_scale_codec::Encode; +use primitives::v1::{ + RuntimeMetricLabelValues, RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate, +}; + +pub struct CounterVec { + name: &'static str, + label_values: Option, +} + +pub struct Counter { + name: &'static str, +} + +fn emit_metric(metric_op: &[u8]) { + // `from_utf8_unchecked` is safe in this context: + // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding + // provides that guarantee forward. We just need to `transmute` as the layout of `&str` + // and `&[u8]` is the same. + + unsafe { + let metric_op = bs58::encode(sp_std::str::from_utf8_unchecked(&metric_op)).into_string(); + + sp_tracing::event!( + target: TRACING_TARGET, + sp_tracing::Level::TRACE, + update_op = metric_op.as_str() + ); + } +} + +impl CounterVec { + /// Create a new counter metric with specified `labels`. + pub fn new(name: &'static str, description: &'static str, labels: &[&'static str]) -> Self { + // Send a register metric operation to node side. + let metric_update = RuntimeMetricUpdate { + metric_name: sp_std::vec::Vec::from(name), + op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new( + sp_std::vec::Vec::from(description), + Some(labels.into()), + )), + } + .encode(); + + emit_metric(&metric_update); + + CounterVec { name, label_values: None } + } + + /// Set label values. + pub fn with_label_values(&mut self, label_values: &[&'static str]) -> &mut Self { + self.label_values = Some(label_values.into()); + self + } + + /// Increment by `value`. + pub fn inc_by(&mut self, value: u64) { + // Ensure label values are set. + if let Some(label_values) = self.label_values.take() { + let metric_update = RuntimeMetricUpdate { + metric_name: sp_std::vec::Vec::from(self.name), + op: RuntimeMetricOp::IncrementCounterVec(value, label_values), + } + .encode(); + + emit_metric(&metric_update); + } + } + + /// Increment by 1. + pub fn inc(&mut self) { + self.inc_by(1); + } +} + +impl Counter { + /// Create a new counter metric with specified `labels`. + pub fn new(name: &'static str, description: &'static str) -> Self { + // Send a register metric operation to node side. + let metric_update = RuntimeMetricUpdate { + metric_name: sp_std::vec::Vec::from(name), + op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new( + sp_std::vec::Vec::from(description), + None, + )), + } + .encode(); + + emit_metric(&metric_update); + + Counter { name } + } + + /// Increment by `value`. + pub fn inc_by(&mut self, value: u64) { + let metric_update = RuntimeMetricUpdate { + metric_name: sp_std::vec::Vec::from(self.name), + op: RuntimeMetricOp::IncrementCounter(value), + } + .encode(); + + emit_metric(&metric_update); + } + + /// Increment by 1. + pub fn inc(&mut self) { + self.inc_by(1); + } +} diff --git a/runtime/metrics/src/std.rs b/runtime/metrics/src/std.rs new file mode 100644 index 000000000000..10c416278304 --- /dev/null +++ b/runtime/metrics/src/std.rs @@ -0,0 +1,50 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Runtime metric interface similar to native Prometheus metrics. +//! +//! This is intended to be used only for testing and debugging and **must never +//! be used in production**. It requires the Substrate wasm tracing support +//! and command line configuration: `--tracing-targets wasm_tracing=trace`. + +#[cfg(feature = "std")] +pub struct Counter; + +#[cfg(feature = "std")] +pub struct CounterVec; + +/// Dummy implementation. +#[cfg(feature = "std")] +impl CounterVec { + pub fn new(_name: &'static str, _description: &'static str, _labels: &[&'static str]) -> Self { + CounterVec + } + pub fn with_label_values(&mut self, _label_values: &[&'static str]) -> &mut Self { + self + } + pub fn inc_by(&mut self, _: u64) {} + pub fn inc(&mut self) {} +} + +/// Dummy implementation. +#[cfg(feature = "std")] +impl Counter { + pub fn new(_name: &'static str, _description: &'static str) -> Self { + Counter + } + pub fn inc_by(&mut self, _: u64) {} + pub fn inc(&mut self) {} +} diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 15710a91dcc7..378a34330880 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -55,7 +55,7 @@ use sp_std::{ vec::Vec, }; -use polkadot_runtime_metrics::CounterVec; +use polkadot_runtime_metrics::{Counter, CounterVec}; mod misc; mod weights; @@ -262,33 +262,33 @@ impl Pallet { mut disputes, } = data; sp_io::init_tracing(); - let mut weight_metric = CounterVec::new_with_labels( + let mut weight_metric = CounterVec::new( "parachain_inherent_data_weight", "Inherent data weight before and after filtering", &vec!["when"], ); - // let mut bitfields_processed_metric = CounterVec::new( - // "parachain_inherent_data_bitfields_processed", - // "Counts the number of bitfields processed in `enter_inner`.", - // ); + let mut bitfields_processed_metric = Counter::new( + "parachain_inherent_data_bitfields_processed", + "Counts the number of bitfields processed in `enter_inner`.", + ); - let mut candidates_processed_metric = CounterVec::new_with_labels( + let mut candidates_processed_metric = CounterVec::new( "parachain_inherent_data_candidates_processed", "Counts the number of parachain block candidates processed in `enter_inner`.", &vec!["category"], ); - let mut dispute_sets_processed_metric = CounterVec::new_with_labels( + let mut dispute_sets_processed_metric = CounterVec::new( "parachain_inherent_data_dispute_sets_processed", "Counts the number of dispute statements sets processed in `enter_inner`.", &vec!["category"], ); - // let mut disputes_included_metric = CounterVec::new( - // "parachain_inherent_data_disputes_included", - // "Counts the number of dispute statements sets included in a block in `enter_inner`.", - // ); + let mut disputes_included_metric = Counter::new( + "parachain_inherent_data_disputes_included", + "Counts the number of dispute statements sets included in a block in `enter_inner`.", + ); log::debug!( target: LOG_TARGET, @@ -431,7 +431,7 @@ impl Pallet { disputed_bitfield }; - // bitfields_processed_metric.inc_by(signed_bitfields.len() as u64); + bitfields_processed_metric.inc_by(signed_bitfields.len() as u64); // Process new availability bitfields, yielding any availability cores whose // work has now concluded. let freed_concluded = >::process_bitfields( @@ -484,7 +484,7 @@ impl Pallet { full_check, )?; - // disputes_included_metric.inc_by(disputes.len() as u64); + disputes_included_metric.inc_by(disputes.len() as u64); // The number of disputes included in a block is // limited by the weight as well as the number of candidate blocks. @@ -871,7 +871,7 @@ pub(crate) fn sanitize_bitfields( validators: &[ValidatorId], full_check: FullCheck, ) -> UncheckedSignedAvailabilityBitfields { - let mut bitfields_signature_checks_metric = CounterVec::new_with_labels( + let mut bitfields_signature_checks_metric = CounterVec::new( "create_inherent_bitfields_signature_checks", "Counts the number of bitfields signature checked in `enter_inner`.", &vec!["validity"], @@ -947,10 +947,10 @@ pub(crate) fn sanitize_bitfields( unchecked_bitfield.try_into_checked(&signing_context, validator_public) { bitfields.push(signed_bitfield.into_unchecked()); - bitfields_signature_checks_metric.with_label_values(&vec!["valid"]).inc_by(1); + bitfields_signature_checks_metric.with_label_values(&vec!["valid"]).inc(); } else { log::warn!(target: LOG_TARGET, "Invalid bitfield signature"); - bitfields_signature_checks_metric.with_label_values(&vec!["invalid"]).inc_by(1); + bitfields_signature_checks_metric.with_label_values(&vec!["invalid"]).inc(); }; } else { bitfields.push(unchecked_bitfield); From 9ed04c6be2688168aade6f235977970143884f77 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Mon, 13 Dec 2021 21:37:34 +0000 Subject: [PATCH 46/63] Fixes Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 15 +++++++-------- runtime/metrics/src/nostd.rs | 5 ++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 9186abdda1ab..525960df3055 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -60,7 +60,6 @@ impl RuntimeMetricsProvider { pub fn register_countervec(&self, metric_name: &str, params: &RuntimeMetricRegisterParams) { self.with_counter_vecs_lock_held(|mut hashmap| { if !hashmap.contains_key(metric_name) { - let metric_name = format!("{}_{}", METRIC_PREFIX, metric_name); hashmap.insert( metric_name.to_owned(), register( @@ -72,7 +71,7 @@ impl RuntimeMetricsProvider { )?, ); } - return Ok(()) + Ok(()) }) } @@ -80,7 +79,6 @@ impl RuntimeMetricsProvider { pub fn register_counter(&self, metric_name: &str, params: &RuntimeMetricRegisterParams) { self.with_counters_lock_held(|mut hashmap| { if !hashmap.contains_key(metric_name) { - let metric_name = format!("{}_{}", METRIC_PREFIX, metric_name); hashmap.insert( metric_name.to_owned(), register(Counter::new(metric_name, params.description())?, &self.0)?, @@ -185,17 +183,18 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { impl RuntimeMetricsProvider { // Parse end execute the update operation. fn parse_metric_update(&self, update: RuntimeMetricUpdate) { + let metric_name = &format!("{}_{}", METRIC_PREFIX, update.metric_name()); + match update.op { RuntimeMetricOp::Register(ref params) => if params.labels.is_none() { - self.register_counter(update.metric_name(), ¶ms); + self.register_counter(metric_name, ¶ms); } else { - self.register_countervec(update.metric_name(), ¶ms); + self.register_countervec(metric_name, ¶ms); }, RuntimeMetricOp::IncrementCounterVec(value, ref labels) => - self.inc_counter_vec_by(update.metric_name(), value, labels), - RuntimeMetricOp::IncrementCounter(value) => - self.inc_counter_by(update.metric_name(), value), + self.inc_counter_vec_by(metric_name, value, labels), + RuntimeMetricOp::IncrementCounter(value) => self.inc_counter_by(metric_name, value), } } diff --git a/runtime/metrics/src/nostd.rs b/runtime/metrics/src/nostd.rs index 1f428565af42..946fe54e0340 100644 --- a/runtime/metrics/src/nostd.rs +++ b/runtime/metrics/src/nostd.rs @@ -59,8 +59,7 @@ impl CounterVec { /// Increment by `value`. pub fn inc_by(&mut self, value: u64) { - // Ensure label values are set. - if let Some(label_values) = self.label_values.take() { + self.label_values.take().map(|label_values| { let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(self.name), op: RuntimeMetricOp::IncrementCounterVec(value, label_values), @@ -68,7 +67,7 @@ impl CounterVec { .encode(); emit_metric(&metric_update); - } + }); } /// Increment by 1. From 09e097869603b68ff52da27b14fa032123f66fe4 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 14 Dec 2021 15:31:09 +0000 Subject: [PATCH 47/63] review fixes Signed-off-by: Andrei Sandu --- cli/src/command.rs | 5 -- runtime/metrics/src/nostd.rs | 53 +++++++++++--------- runtime/metrics/src/std.rs | 11 ---- runtime/parachains/src/paras_inherent/mod.rs | 32 ++++++------ 4 files changed, 45 insertions(+), 56 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 1b024d7df9cb..aeb69fa850e6 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -276,11 +276,6 @@ where }) } -/// TODO: Start the node with support for publishing runtime metrics. -pub fn run_with_wasm_metrics() -> Result<()> { - Ok(()) -} - /// Parses polkadot specific CLI arguments and run the service. pub fn run() -> Result<()> { let cli: Cli = Cli::from_args(); diff --git a/runtime/metrics/src/nostd.rs b/runtime/metrics/src/nostd.rs index 946fe54e0340..014d628362af 100644 --- a/runtime/metrics/src/nostd.rs +++ b/runtime/metrics/src/nostd.rs @@ -1,4 +1,18 @@ -#![cfg_attr(not(feature = "std"), no_std)] +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . const TRACING_TARGET: &'static str = "metrics"; @@ -16,23 +30,19 @@ pub struct Counter { name: &'static str, } -fn emit_metric(metric_op: &[u8]) { - // `from_utf8_unchecked` is safe in this context: - // We cannot guarantee that the input slice is a valid UTF-8, but the `bs58` encoding - // provides that guarantee forward. We just need to `transmute` as the layout of `&str` - // and `&[u8]` is the same. - - unsafe { - let metric_op = bs58::encode(sp_std::str::from_utf8_unchecked(&metric_op)).into_string(); - +trait MetricEmitter { + fn emit(metric_op: &RuntimeMetricUpdate) { sp_tracing::event!( target: TRACING_TARGET, sp_tracing::Level::TRACE, - update_op = metric_op.as_str() + update_op = bs58::encode(&metric_op.encode()).into_string().as_str() ); } } +impl MetricEmitter for CounterVec {} +impl MetricEmitter for Counter {} + impl CounterVec { /// Create a new counter metric with specified `labels`. pub fn new(name: &'static str, description: &'static str, labels: &[&'static str]) -> Self { @@ -43,10 +53,9 @@ impl CounterVec { sp_std::vec::Vec::from(description), Some(labels.into()), )), - } - .encode(); + }; - emit_metric(&metric_update); + Self::emit(&metric_update); CounterVec { name, label_values: None } } @@ -63,10 +72,9 @@ impl CounterVec { let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(self.name), op: RuntimeMetricOp::IncrementCounterVec(value, label_values), - } - .encode(); + }; - emit_metric(&metric_update); + Self::emit(&metric_update); }); } @@ -86,11 +94,9 @@ impl Counter { sp_std::vec::Vec::from(description), None, )), - } - .encode(); - - emit_metric(&metric_update); + }; + Self::emit(&metric_update); Counter { name } } @@ -99,10 +105,9 @@ impl Counter { let metric_update = RuntimeMetricUpdate { metric_name: sp_std::vec::Vec::from(self.name), op: RuntimeMetricOp::IncrementCounter(value), - } - .encode(); + }; - emit_metric(&metric_update); + Self::emit(&metric_update); } /// Increment by 1. diff --git a/runtime/metrics/src/std.rs b/runtime/metrics/src/std.rs index 10c416278304..e0f8e907176e 100644 --- a/runtime/metrics/src/std.rs +++ b/runtime/metrics/src/std.rs @@ -14,20 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Runtime metric interface similar to native Prometheus metrics. -//! -//! This is intended to be used only for testing and debugging and **must never -//! be used in production**. It requires the Substrate wasm tracing support -//! and command line configuration: `--tracing-targets wasm_tracing=trace`. - -#[cfg(feature = "std")] pub struct Counter; - -#[cfg(feature = "std")] pub struct CounterVec; /// Dummy implementation. -#[cfg(feature = "std")] impl CounterVec { pub fn new(_name: &'static str, _description: &'static str, _labels: &[&'static str]) -> Self { CounterVec @@ -40,7 +30,6 @@ impl CounterVec { } /// Dummy implementation. -#[cfg(feature = "std")] impl Counter { pub fn new(_name: &'static str, _description: &'static str) -> Self { Counter diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 378a34330880..c5d8702a4de4 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -265,7 +265,7 @@ impl Pallet { let mut weight_metric = CounterVec::new( "parachain_inherent_data_weight", "Inherent data weight before and after filtering", - &vec!["when"], + &["when"], ); let mut bitfields_processed_metric = Counter::new( @@ -276,13 +276,13 @@ impl Pallet { let mut candidates_processed_metric = CounterVec::new( "parachain_inherent_data_candidates_processed", "Counts the number of parachain block candidates processed in `enter_inner`.", - &vec!["category"], + &["category"], ); let mut dispute_sets_processed_metric = CounterVec::new( "parachain_inherent_data_dispute_sets_processed", "Counts the number of dispute statements sets processed in `enter_inner`.", - &vec!["category"], + &["category"], ); let mut disputes_included_metric = Counter::new( @@ -299,7 +299,7 @@ impl Pallet { ); dispute_sets_processed_metric - .with_label_values(&vec!["total"]) + .with_label_values(&["total"]) .inc_by(disputes.len() as u64); // Check that the submitted parent header indeed corresponds to the previous block hash. @@ -318,7 +318,7 @@ impl Pallet { let max_block_weight = ::BlockWeights::get().max_block; weight_metric - .with_label_values(&vec!["before-filter"]) + .with_label_values(&["before-filter"]) .inc_by(candidate_weight + bitfields_weight + disputes_weight); // Potentially trim inherent data to ensure processing will be within weight limits @@ -368,12 +368,12 @@ impl Pallet { // dispute; so the input here must be reasonably bounded. let _ = T::DisputesHandler::provide_multi_dispute_data(disputes.clone())?; dispute_sets_processed_metric - .with_label_values(&vec!["imported)"]) + .with_label_values(&["imported"]) .inc_by(disputes.len() as u64); if T::DisputesHandler::is_frozen() { // Relay chain freeze, at this point we will not include any parachain blocks. - dispute_sets_processed_metric.with_label_values(&vec!["frozen)"]).inc_by(1); + dispute_sets_processed_metric.with_label_values(&["frozen)"]).inc_by(1); // The relay chain we are currently on is invalid. Proceed no further on parachains. return Ok(Some(dispute_statements_weight::(&disputes)).into()) @@ -381,7 +381,7 @@ impl Pallet { // Process the dispute sets of the current session. dispute_sets_processed_metric - .with_label_values(&vec!["current_session)"]) + .with_label_values(&["current_session)"]) .inc_by(new_current_dispute_sets.len() as u64); let mut freed_disputed = if !new_current_dispute_sets.is_empty() { @@ -395,7 +395,7 @@ impl Pallet { // Count invalid dispute sets. dispute_sets_processed_metric - .with_label_values(&vec!["concluded_invalid)"]) + .with_label_values(&["concluded_invalid)"]) .inc_by(concluded_invalid_disputes.len() as u64); let freed_disputed: Vec<_> = @@ -406,7 +406,7 @@ impl Pallet { // Count concluded disputes. dispute_sets_processed_metric - .with_label_values(&vec!["concluded_valid)"]) + .with_label_values(&["concluded_valid)"]) .inc_by(freed_disputed.len() as u64); freed_disputed @@ -447,7 +447,7 @@ impl Pallet { } candidates_processed_metric - .with_label_values(&vec!["included"]) + .with_label_values(&["included"]) .inc_by(freed_concluded.len() as u64); let freed = collect_all_freed_cores::(freed_concluded.iter().cloned()); @@ -455,7 +455,7 @@ impl Pallet { >::schedule(freed, now); candidates_processed_metric - .with_label_values(&vec!["total"]) + .with_label_values(&["total"]) .inc_by(backed_candidates.len() as u64); let scheduled = >::scheduled(); let backed_candidates = sanitize_backed_candidates::( @@ -468,7 +468,7 @@ impl Pallet { &scheduled[..], ); candidates_processed_metric - .with_label_values(&vec!["sanitized"]) + .with_label_values(&["sanitized"]) .inc_by(backed_candidates.len() as u64); // Process backed candidates according to scheduled cores. @@ -874,7 +874,7 @@ pub(crate) fn sanitize_bitfields( let mut bitfields_signature_checks_metric = CounterVec::new( "create_inherent_bitfields_signature_checks", "Counts the number of bitfields signature checked in `enter_inner`.", - &vec!["validity"], + &["validity"], ); let mut bitfields = Vec::with_capacity(unchecked_bitfields.len()); @@ -947,10 +947,10 @@ pub(crate) fn sanitize_bitfields( unchecked_bitfield.try_into_checked(&signing_context, validator_public) { bitfields.push(signed_bitfield.into_unchecked()); - bitfields_signature_checks_metric.with_label_values(&vec!["valid"]).inc(); + bitfields_signature_checks_metric.with_label_values(&["valid"]).inc(); } else { log::warn!(target: LOG_TARGET, "Invalid bitfield signature"); - bitfields_signature_checks_metric.with_label_values(&vec!["invalid"]).inc(); + bitfields_signature_checks_metric.with_label_values(&["invalid"]).inc(); }; } else { bitfields.push(unchecked_bitfield); From a6442af6a263b387f5cff46008b1ac535bf28a79 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 14 Dec 2021 15:41:47 +0000 Subject: [PATCH 48/63] more fixes Signed-off-by: Andrei Sandu --- node/metrics/src/runtime.rs | 4 ++-- runtime/metrics/Cargo.toml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 525960df3055..66b5c00d5798 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -162,7 +162,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider { return } - if let Some(update_op_bs58) = event.values.string_values.get("params").cloned() { + if let Some(update_op_bs58) = event.values.string_values.get("params") { // Deserialize the metric update struct. match RuntimeMetricUpdate::decode( &mut RuntimeMetricsProvider::parse_event_params(&update_op_bs58) @@ -199,7 +199,7 @@ impl RuntimeMetricsProvider { } // Returns the `bs58` encoded metric update operation. - fn parse_event_params(event_params: &String) -> Option> { + fn parse_event_params(event_params: &str) -> Option> { // Shave " }" suffix. let new_len = event_params.len().saturating_sub(2); let event_params = &event_params[..new_len]; diff --git a/runtime/metrics/Cargo.toml b/runtime/metrics/Cargo.toml index edd1d8ae28e7..9c7431d779ba 100644 --- a/runtime/metrics/Cargo.toml +++ b/runtime/metrics/Cargo.toml @@ -14,7 +14,6 @@ bs58 = { version = "0.4.0", default-features = false, features = ["alloc"] } [features] default = ["std"] -no_std = [] std = [ "sp-std/std", "sp-tracing/std", From 04f517c023ee80852a063f77e41a59e9ef8cb67c Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 14 Dec 2021 16:53:29 +0000 Subject: [PATCH 49/63] add integration test Signed-off-by: Andrei Sandu --- node/metrics/src/lib.rs | 3 ++ node/metrics/src/tests.rs | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 node/metrics/src/tests.rs diff --git a/node/metrics/src/lib.rs b/node/metrics/src/lib.rs index b13eeca0ca07..cf8dc92b38c8 100644 --- a/node/metrics/src/lib.rs +++ b/node/metrics/src/lib.rs @@ -80,3 +80,6 @@ pub mod metrics { } } } + +#[cfg(test)] +mod tests; diff --git a/node/metrics/src/tests.rs b/node/metrics/src/tests.rs new file mode 100644 index 000000000000..d0e632182470 --- /dev/null +++ b/node/metrics/src/tests.rs @@ -0,0 +1,70 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . +#![cfg(feature = "runtime-metrics")] +use assert_cmd::cargo::cargo_bin; +use std::{convert::TryInto, process::Command, thread, time::Duration}; +use tempfile::tempdir; + +#[test] +#[cfg(unix)] +fn runtime_can_publish_metrics() { + use hyper::{Client, Uri}; + use nix::{ + sys::signal::{kill, Signal::SIGINT}, + unistd::Pid, + }; + use std::convert::TryFrom; + + const RUNTIME_METRIC_NAME: &str = "polkadot_parachain_inherent_data_bitfields_processed"; + const DEFAULT_PROMETHEUS_PORT: u16 = 9615; + let metrics_uri = format!("http://localhost:{}/metrics", DEFAULT_PROMETHEUS_PORT); + + // Start the node with tracing enabled and forced wasm runtime execution. + let cmd = Command::new(cargo_bin("polkadot")) + // Runtime metrics require this trace target. + .args(&["--tracing-targets", "wasm_tracing=trace"]) + .args(&["--execution", "wasm"]) + .args(&["--dev", "-d"]) + .arg(tempdir().expect("failed to create temp dir.").path()) + .spawn() + .expect("failed to start the node process"); + + // Enough time to author one block. + thread::sleep(Duration::from_secs(10)); + + let runtime = tokio::runtime::Runtime::new().expect("failed to create tokio runtime"); + + runtime.block_on(async { + let client = Client::new(); + + let res = client + .get(Uri::try_from(&metrics_uri).expect("bad URI")) + .await + .expect("get request failed"); + + let body = String::from_utf8( + hyper::body::to_bytes(res).await.expect("can't get body as bytes").to_vec(), + ) + .expect("body is not an UTF8 string"); + + // Time to die. + kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT) + .expect("failed to kill the node process"); + + // If the node has authored at least 1 block this should pass. + assert!(body.contains(&RUNTIME_METRIC_NAME)); + }); +} From 1c44ffec92a04a0e32e57ab9b714a192811b3839 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 14 Dec 2021 16:53:43 +0000 Subject: [PATCH 50/63] dev deps Signed-off-by: Andrei Sandu --- node/metrics/Cargo.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index e28ea6d51910..a4cc215afeed 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -23,6 +23,13 @@ primitives = { package = "polkadot-primitives", path = "../../primitives/" } bs58 = { version = "0.4.0", features = ["alloc"] } log = "0.4.13" +[dev-dependencies] +assert_cmd = "2.0.2" +nix = "0.23.0" +tempfile = "3.2.0" +hyper = { version = "0.14.14", default-features = false, features = ["http1", "tcp"] } +tokio = "1.13" + [features] default = [] runtime-metrics = [] From 90dd6fbe6944601f686d5f82b6aa1690d7345c59 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 14 Dec 2021 16:54:08 +0000 Subject: [PATCH 51/63] gitlab script update Signed-off-by: Andrei Sandu --- scripts/gitlab/test_linux_stable.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gitlab/test_linux_stable.sh b/scripts/gitlab/test_linux_stable.sh index f7b36141af3a..1648da879f97 100755 --- a/scripts/gitlab/test_linux_stable.sh +++ b/scripts/gitlab/test_linux_stable.sh @@ -5,4 +5,4 @@ set -e source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" time cargo test --release --locked -p polkadot-node-core-dispute-coordinator --features disputes -time cargo test --workspace --release --verbose --locked --features=runtime-benchmarks +time cargo test --workspace --release --verbose --locked --features=runtime-benchmarks,runtime-metrics From 7303a4aca6c66c3f39a3658fdedb21a49ded19bc Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 12:21:40 +0000 Subject: [PATCH 52/63] review fixes Signed-off-by: Andrei Sandu --- cli/src/command.rs | 2 +- node/metrics/src/runtime.rs | 58 +++++++------------- primitives/src/v1/metrics.rs | 6 +- runtime/metrics/src/nostd.rs | 13 +++-- runtime/metrics/src/std.rs | 3 + runtime/parachains/src/paras_inherent/mod.rs | 15 +---- 6 files changed, 36 insertions(+), 61 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index aeb69fa850e6..673c0ee21bc2 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -222,7 +222,7 @@ fn host_perf_check() -> Result<()> { /// for integration tests as needed. #[cfg(feature = "malus")] pub fn run_node(run: Cli, overseer_gen: impl service::OverseerGen) -> Result<()> { - run_node_inner(run, overseer_gen, |_, _| {}) + run_node_inner(run, overseer_gen, |_logger_builder, _config| {}) } fn run_node_inner( diff --git a/node/metrics/src/runtime.rs b/node/metrics/src/runtime.rs index 66b5c00d5798..f39abc910f7e 100644 --- a/node/metrics/src/runtime.rs +++ b/node/metrics/src/runtime.rs @@ -20,7 +20,6 @@ //! tracing support. This requires that the custom profiler (`TraceHandler`) to be //! registered in substrate via a `logger_hook()`. Events emitted from runtime are //! then captured/processed by the `TraceHandler` implementation. -//! #![cfg(feature = "runtime-metrics")] use codec::Decode; @@ -38,8 +37,7 @@ use substrate_prometheus_endpoint::{ const LOG_TARGET: &'static str = "metrics::runtime"; const METRIC_PREFIX: &'static str = "polkadot"; -/// Support only `CounterVec` for now. -/// TODO: add more when needed. +/// Holds the registered Prometheus metric collections. #[derive(Clone, Default)] pub struct Metrics { counter_vecs: Arc>>>, @@ -59,18 +57,13 @@ impl RuntimeMetricsProvider { /// Register a counter vec metric. pub fn register_countervec(&self, metric_name: &str, params: &RuntimeMetricRegisterParams) { self.with_counter_vecs_lock_held(|mut hashmap| { - if !hashmap.contains_key(metric_name) { - hashmap.insert( - metric_name.to_owned(), - register( - CounterVec::new( - Opts::new(metric_name, params.description()), - ¶ms.labels().unwrap_or_default(), - )?, - &self.0, - )?, - ); - } + hashmap.entry(metric_name.to_owned()).or_insert(register( + CounterVec::new( + Opts::new(metric_name, params.description()), + ¶ms.labels().unwrap_or_default(), + )?, + &self.0, + )?); Ok(()) }) } @@ -78,12 +71,9 @@ impl RuntimeMetricsProvider { /// Register a counter metric. pub fn register_counter(&self, metric_name: &str, params: &RuntimeMetricRegisterParams) { self.with_counters_lock_held(|mut hashmap| { - if !hashmap.contains_key(metric_name) { - hashmap.insert( - metric_name.to_owned(), - register(Counter::new(metric_name, params.description())?, &self.0)?, - ); - } + hashmap + .entry(metric_name.to_owned()) + .or_insert(register(Counter::new(metric_name, params.description())?, &self.0)?); return Ok(()) }) } @@ -91,15 +81,10 @@ impl RuntimeMetricsProvider { /// Increment a counter with labels by a value. pub fn inc_counter_vec_by(&self, name: &str, value: u64, labels: &RuntimeMetricLabelValues) { self.with_counter_vecs_lock_held(|mut hashmap| { - if let Some(counter_vec) = hashmap.get_mut(name) { - counter_vec.with_label_values(&labels.as_str()).inc_by(value); - } else { - tracing::error!( - target: LOG_TARGET, - "Cannot increment counter `{}`, metric not in registered or present in hashmap", - name - ); - } + hashmap.entry(name.to_owned()).and_modify(|counter_vec| { + counter_vec.with_label_values(&labels.as_str_vec()).inc_by(value) + }); + Ok(()) }); } @@ -107,15 +92,9 @@ impl RuntimeMetricsProvider { /// Increment a counter by a value. pub fn inc_counter_by(&self, name: &str, value: u64) { self.with_counters_lock_held(|mut hashmap| { - if let Some(counter) = hashmap.get_mut(name) { - counter.inc_by(value); - } else { - tracing::error!( - target: LOG_TARGET, - "Cannot increment counter `{}`, metric not in registered or present in hashmap", - name - ); - } + hashmap + .entry(name.to_owned()) + .and_modify(|counter_vec| counter_vec.inc_by(value)); Ok(()) }) } @@ -221,6 +200,7 @@ impl RuntimeMetricsProvider { pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () { |logger_builder, config| { if config.prometheus_registry().is_none() { + tracing::debug!(target: LOG_TARGET, "Prometheus registry is not configured.",); return } let registry = config.prometheus_registry().cloned().unwrap(); diff --git a/primitives/src/v1/metrics.rs b/primitives/src/v1/metrics.rs index e8d83709ac5c..90890388f51b 100644 --- a/primitives/src/v1/metrics.rs +++ b/primitives/src/v1/metrics.rs @@ -19,7 +19,7 @@ pub enum RuntimeMetricOp { Register(RuntimeMetricRegisterParams), /// Increment a counter metric with labels by value. IncrementCounterVec(u64, RuntimeMetricLabelValues), - /// Increment a counter metric with labels by value. + /// Increment a counter metric by value. IncrementCounter(u64), } @@ -52,13 +52,13 @@ impl RuntimeMetricRegisterParams { /// Returns a label names as an `Option` of `Vec<&str>`. pub fn labels(&self) -> Option> { - self.labels.as_ref().map(|labels| labels.as_str()) + self.labels.as_ref().map(|labels| labels.as_str_vec()) } } impl RuntimeMetricLabels { /// Returns a labels as `Vec<&str>`. - pub fn as_str(&self) -> Vec<&str> { + pub fn as_str_vec(&self) -> Vec<&str> { self.0 .iter() .map(|label_vec| vec_to_str(&label_vec.0, "invalid_label")) diff --git a/runtime/metrics/src/nostd.rs b/runtime/metrics/src/nostd.rs index 014d628362af..94fbbd3054bd 100644 --- a/runtime/metrics/src/nostd.rs +++ b/runtime/metrics/src/nostd.rs @@ -20,6 +20,7 @@ use parity_scale_codec::Encode; use primitives::v1::{ RuntimeMetricLabelValues, RuntimeMetricOp, RuntimeMetricRegisterParams, RuntimeMetricUpdate, }; +use sp_std::prelude::*; pub struct CounterVec { name: &'static str, @@ -48,9 +49,9 @@ impl CounterVec { pub fn new(name: &'static str, description: &'static str, labels: &[&'static str]) -> Self { // Send a register metric operation to node side. let metric_update = RuntimeMetricUpdate { - metric_name: sp_std::vec::Vec::from(name), + metric_name: Vec::from(name), op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new( - sp_std::vec::Vec::from(description), + Vec::from(description), Some(labels.into()), )), }; @@ -70,7 +71,7 @@ impl CounterVec { pub fn inc_by(&mut self, value: u64) { self.label_values.take().map(|label_values| { let metric_update = RuntimeMetricUpdate { - metric_name: sp_std::vec::Vec::from(self.name), + metric_name: Vec::from(self.name), op: RuntimeMetricOp::IncrementCounterVec(value, label_values), }; @@ -89,9 +90,9 @@ impl Counter { pub fn new(name: &'static str, description: &'static str) -> Self { // Send a register metric operation to node side. let metric_update = RuntimeMetricUpdate { - metric_name: sp_std::vec::Vec::from(name), + metric_name: Vec::from(name), op: RuntimeMetricOp::Register(RuntimeMetricRegisterParams::new( - sp_std::vec::Vec::from(description), + Vec::from(description), None, )), }; @@ -103,7 +104,7 @@ impl Counter { /// Increment by `value`. pub fn inc_by(&mut self, value: u64) { let metric_update = RuntimeMetricUpdate { - metric_name: sp_std::vec::Vec::from(self.name), + metric_name: Vec::from(self.name), op: RuntimeMetricOp::IncrementCounter(value), }; diff --git a/runtime/metrics/src/std.rs b/runtime/metrics/src/std.rs index e0f8e907176e..af4bb36f7fd2 100644 --- a/runtime/metrics/src/std.rs +++ b/runtime/metrics/src/std.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . +//! Runtime metrics are wasm only so we also need to provide a dummy metric +//! implementation for the native runtime. These are required to avoid cluttering +//! the code with `#[cfg(not(feature = "std"))]` for updating metrics. pub struct Counter; pub struct CounterVec; diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index c5d8702a4de4..5e5d41e798e8 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -298,10 +298,6 @@ impl Pallet { disputes.len() ); - dispute_sets_processed_metric - .with_label_values(&["total"]) - .inc_by(disputes.len() as u64); - // Check that the submitted parent header indeed corresponds to the previous block hash. let parent_hash = >::parent_hash(); ensure!( @@ -373,7 +369,7 @@ impl Pallet { if T::DisputesHandler::is_frozen() { // Relay chain freeze, at this point we will not include any parachain blocks. - dispute_sets_processed_metric.with_label_values(&["frozen)"]).inc_by(1); + dispute_sets_processed_metric.with_label_values(&["frozen"]).inc(); // The relay chain we are currently on is invalid. Proceed no further on parachains. return Ok(Some(dispute_statements_weight::(&disputes)).into()) @@ -381,7 +377,7 @@ impl Pallet { // Process the dispute sets of the current session. dispute_sets_processed_metric - .with_label_values(&["current_session)"]) + .with_label_values(&["current)"]) .inc_by(new_current_dispute_sets.len() as u64); let mut freed_disputed = if !new_current_dispute_sets.is_empty() { @@ -395,7 +391,7 @@ impl Pallet { // Count invalid dispute sets. dispute_sets_processed_metric - .with_label_values(&["concluded_invalid)"]) + .with_label_values(&["concluded_invalid"]) .inc_by(concluded_invalid_disputes.len() as u64); let freed_disputed: Vec<_> = @@ -404,11 +400,6 @@ impl Pallet { .map(|core| (core, FreedReason::Concluded)) .collect(); - // Count concluded disputes. - dispute_sets_processed_metric - .with_label_values(&["concluded_valid)"]) - .inc_by(freed_disputed.len() as u64); - freed_disputed } else { Vec::new() From 796338f4d14e96326f86b9669c9c94f11be81cc9 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 13:11:13 +0000 Subject: [PATCH 53/63] fix merge damage Signed-off-by: Andrei Sandu --- runtime/parachains/src/paras_inherent/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 5e5d41e798e8..b59559e755d4 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -292,7 +292,8 @@ impl Pallet { log::debug!( target: LOG_TARGET, - "[enter] bitfields.len(): {}, backed_candidates.len(): {}, disputes.len() {}", + "[enter_inner] parent_header={:?} bitfields.len(): {}, backed_candidates.len(): {}, disputes.len(): {}", + parent_header, signed_bitfields.len(), backed_candidates.len(), disputes.len() From 0b6f0f276abb1e7f9bbee0c6c36239b1e7235584 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 13:13:21 +0000 Subject: [PATCH 54/63] Run tests twice Signed-off-by: Andrei Sandu --- scripts/gitlab/test_linux_stable.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/gitlab/test_linux_stable.sh b/scripts/gitlab/test_linux_stable.sh index 1648da879f97..808b1fb768d6 100755 --- a/scripts/gitlab/test_linux_stable.sh +++ b/scripts/gitlab/test_linux_stable.sh @@ -5,4 +5,6 @@ set -e source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" time cargo test --release --locked -p polkadot-node-core-dispute-coordinator --features disputes -time cargo test --workspace --release --verbose --locked --features=runtime-benchmarks,runtime-metrics +time cargo test --workspace --release --verbose --locked --features=runtime-benchmarks +# Builds with the runtime metrics feature are only to be used for testing. +time cargo test --workspace --release --verbose --locked --features=runtime-metrics From bc010687e1341b9b3ca5981456456953f0881db1 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 15:02:15 +0000 Subject: [PATCH 55/63] small fix Signed-off-by: Andrei Sandu --- runtime/parachains/src/paras_inherent/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index b59559e755d4..9231e1b7ed8b 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -293,7 +293,7 @@ impl Pallet { log::debug!( target: LOG_TARGET, "[enter_inner] parent_header={:?} bitfields.len(): {}, backed_candidates.len(): {}, disputes.len(): {}", - parent_header, + parent_header.hash(), signed_bitfields.len(), backed_candidates.len(), disputes.len() From e818617e00eb111927a4504d6cf13ab73fe13499 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 15:07:17 +0000 Subject: [PATCH 56/63] typo Signed-off-by: Andrei Sandu --- runtime/parachains/src/paras_inherent/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 9231e1b7ed8b..9d3f42d7e60e 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -378,7 +378,7 @@ impl Pallet { // Process the dispute sets of the current session. dispute_sets_processed_metric - .with_label_values(&["current)"]) + .with_label_values(&["current"]) .inc_by(new_current_dispute_sets.len() as u64); let mut freed_disputed = if !new_current_dispute_sets.is_empty() { From 5a1050d82a5ef4d98cf25b46534935db6d103525 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 16:40:58 +0000 Subject: [PATCH 57/63] cargo lock Signed-off-by: Andrei Sandu --- Cargo.lock | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e1b4949b8e6a..3c14d8dc04c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6394,17 +6394,22 @@ dependencies = [ name = "polkadot-node-metrics" version = "0.9.13" dependencies = [ + "assert_cmd", "bs58", "futures 0.3.18", "futures-timer 3.0.2", + "hyper", "log", "metered-channel", + "nix", "parity-scale-codec", "polkadot-primitives", "sc-cli", "sc-service", "sc-tracing", "substrate-prometheus-endpoint", + "tempfile", + "tokio", "tracing", ] From 2febc4cee285fef5d416a56bd3e47ea9ea982f4d Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 16:57:43 +0000 Subject: [PATCH 58/63] tests Signed-off-by: Andrei Sandu --- scripts/gitlab/test_linux_stable.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/gitlab/test_linux_stable.sh b/scripts/gitlab/test_linux_stable.sh index 808b1fb768d6..6234cdbf6e88 100755 --- a/scripts/gitlab/test_linux_stable.sh +++ b/scripts/gitlab/test_linux_stable.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash -set -e +set -eux #shellcheck source=../common/lib.sh source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh" time cargo test --release --locked -p polkadot-node-core-dispute-coordinator --features disputes -time cargo test --workspace --release --verbose --locked --features=runtime-benchmarks -# Builds with the runtime metrics feature are only to be used for testing. -time cargo test --workspace --release --verbose --locked --features=runtime-metrics +# Builds with the runtime benchmarks/metrics features are only to be used for testing. +time cargo test --workspace --release --verbose --locked --features=runtime-benchmarks,runtime-metrics From fecd12b520f7fed42728afdb81ba2b92a9a3c2e6 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 15 Dec 2021 17:09:08 +0000 Subject: [PATCH 59/63] spellcheck happy ? Signed-off-by: Andrei Sandu --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4e2b00f205c1..4db5d6e544ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ path = "src/main.rs" [package] name = "polkadot" -description = "Implementation of a https://polkadot.network node in Rust based on the Substrate framework." +description = "Implementation of a `https://polkadot.network` node in Rust based on the Substrate framework." license = "GPL-3.0-only" version = "0.9.13" authors = ["Parity Technologies "] From 0b405e01d73e20758450320bce3f94a33e52e966 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 16 Dec 2021 10:57:22 +0000 Subject: [PATCH 60/63] more fixes Signed-off-by: Andrei Sandu --- runtime/metrics/src/lib.rs | 16 +++++++------- .../src/{nostd.rs => with_runtime_metrics.rs} | 22 +++++++++++++------ .../{std.rs => without_runtime_metrics.rs} | 16 +++++++++++--- 3 files changed, 36 insertions(+), 18 deletions(-) rename runtime/metrics/src/{nostd.rs => with_runtime_metrics.rs} (78%) rename runtime/metrics/src/{std.rs => without_runtime_metrics.rs} (67%) diff --git a/runtime/metrics/src/lib.rs b/runtime/metrics/src/lib.rs index c4544df22ff1..a56b94404fa2 100644 --- a/runtime/metrics/src/lib.rs +++ b/runtime/metrics/src/lib.rs @@ -22,12 +22,12 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(feature = "std")] -mod std; -#[cfg(feature = "std")] -pub use crate::std::*; +#[cfg(feature = "runtime-metrics")] +mod with_runtime_metrics; +#[cfg(feature = "runtime-metrics")] +pub use crate::with_runtime_metrics::*; -#[cfg(not(feature = "std"))] -mod nostd; -#[cfg(not(feature = "std"))] -pub use crate::nostd::*; +#[cfg(not(feature = "runtime-metrics"))] +mod without_runtime_metrics; +#[cfg(not(feature = "runtime-metrics"))] +pub use crate::without_runtime_metrics::*; diff --git a/runtime/metrics/src/nostd.rs b/runtime/metrics/src/with_runtime_metrics.rs similarity index 78% rename from runtime/metrics/src/nostd.rs rename to runtime/metrics/src/with_runtime_metrics.rs index 94fbbd3054bd..003d228ab34b 100644 --- a/runtime/metrics/src/nostd.rs +++ b/runtime/metrics/src/with_runtime_metrics.rs @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . +//! This module provides an implementation for the runtime metrics types: `Counter` +//! and `CounterVec`. These types expose a Prometheus like interface and same functionality. +//! Each instance of a runtime metric is mapped to a Prometheus metric on the node side. + const TRACING_TARGET: &'static str = "metrics"; use parity_scale_codec::Encode; @@ -22,15 +26,19 @@ use primitives::v1::{ }; use sp_std::prelude::*; +/// Holds a set of counters that have different values for their labels, +/// like Prometheus CounterVec. pub struct CounterVec { name: &'static str, label_values: Option, } +/// A counter metric. pub struct Counter { name: &'static str, } +/// Convenience trait implemented for all metric types. trait MetricEmitter { fn emit(metric_op: &RuntimeMetricUpdate) { sp_tracing::event!( @@ -45,7 +53,7 @@ impl MetricEmitter for CounterVec {} impl MetricEmitter for Counter {} impl CounterVec { - /// Create a new counter metric with specified `labels`. + /// Create a new metric with specified `name`, `description` and `labels`. pub fn new(name: &'static str, description: &'static str, labels: &[&'static str]) -> Self { // Send a register metric operation to node side. let metric_update = RuntimeMetricUpdate { @@ -61,13 +69,13 @@ impl CounterVec { CounterVec { name, label_values: None } } - /// Set label values. + /// Set the label values. Must be called before each increment operation. pub fn with_label_values(&mut self, label_values: &[&'static str]) -> &mut Self { self.label_values = Some(label_values.into()); self } - /// Increment by `value`. + /// Increment the counter by `value`. pub fn inc_by(&mut self, value: u64) { self.label_values.take().map(|label_values| { let metric_update = RuntimeMetricUpdate { @@ -79,14 +87,14 @@ impl CounterVec { }); } - /// Increment by 1. + /// Increment the counter value. pub fn inc(&mut self) { self.inc_by(1); } } impl Counter { - /// Create a new counter metric with specified `labels`. + /// Create a new counter metric with specified `name`, `description`. pub fn new(name: &'static str, description: &'static str) -> Self { // Send a register metric operation to node side. let metric_update = RuntimeMetricUpdate { @@ -101,7 +109,7 @@ impl Counter { Counter { name } } - /// Increment by `value`. + /// Increment counter by `value`. pub fn inc_by(&mut self, value: u64) { let metric_update = RuntimeMetricUpdate { metric_name: Vec::from(self.name), @@ -111,7 +119,7 @@ impl Counter { Self::emit(&metric_update); } - /// Increment by 1. + /// Increment counter. pub fn inc(&mut self) { self.inc_by(1); } diff --git a/runtime/metrics/src/std.rs b/runtime/metrics/src/without_runtime_metrics.rs similarity index 67% rename from runtime/metrics/src/std.rs rename to runtime/metrics/src/without_runtime_metrics.rs index af4bb36f7fd2..345d7039343a 100644 --- a/runtime/metrics/src/std.rs +++ b/runtime/metrics/src/without_runtime_metrics.rs @@ -14,29 +14,39 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Runtime metrics are wasm only so we also need to provide a dummy metric -//! implementation for the native runtime. These are required to avoid cluttering -//! the code with `#[cfg(not(feature = "std"))]` for updating metrics. +//! Runtime metrics are usable from the wasm runtime only. The purpose of this module is to +//! provide a dummy implementation for the native runtime to avoid cluttering the runtime code +//! with `#[cfg(feature = "runtime-metrics")]`. + +/// A dummy Counter. pub struct Counter; +/// A dummy CounterVec. pub struct CounterVec; /// Dummy implementation. impl CounterVec { + /// Constructor. pub fn new(_name: &'static str, _description: &'static str, _labels: &[&'static str]) -> Self { CounterVec } + /// Sets label values, implementation is a `no op`. pub fn with_label_values(&mut self, _label_values: &[&'static str]) -> &mut Self { self } + /// Increment counter by value, implementation is a `no op`. pub fn inc_by(&mut self, _: u64) {} + /// Increment counter, implementation is a `no op`. pub fn inc(&mut self) {} } /// Dummy implementation. impl Counter { + /// Constructor. pub fn new(_name: &'static str, _description: &'static str) -> Self { Counter } + /// Increment counter by value, implementation is a `no op`. pub fn inc_by(&mut self, _: u64) {} + /// Increment counter, implementation is a `no op`. pub fn inc(&mut self) {} } From 78620f6f7475ff869b6ab909b982c56bd373d241 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 16 Dec 2021 11:08:01 +0000 Subject: [PATCH 61/63] Guard tracing init Signed-off-by: Andrei Sandu --- runtime/parachains/src/paras_inherent/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 9d3f42d7e60e..ad420b07830c 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -261,7 +261,9 @@ impl Pallet { parent_header, mut disputes, } = data; + #[cfg(feature = "runtime-metrics")] sp_io::init_tracing(); + let mut weight_metric = CounterVec::new( "parachain_inherent_data_weight", "Inherent data weight before and after filtering", From 061efe275e2ade6d623e4b37fb1ffd7d85fcc282 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 16 Dec 2021 11:11:42 +0000 Subject: [PATCH 62/63] missing copyright Signed-off-by: Andrei Sandu --- primitives/src/v1/metrics.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/primitives/src/v1/metrics.rs b/primitives/src/v1/metrics.rs index 90890388f51b..c4464a004ead 100644 --- a/primitives/src/v1/metrics.rs +++ b/primitives/src/v1/metrics.rs @@ -1,3 +1,21 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Runtime metric primitives. + use parity_scale_codec::{Decode, Encode}; use sp_std::prelude::*; From f1d515e66e958ac648d486358c5bfee0cba8bfd8 Mon Sep 17 00:00:00 2001 From: parity-processbot <> Date: Thu, 16 Dec 2021 11:22:27 +0000 Subject: [PATCH 63/63] update lockfile for substrate --- Cargo.lock | 344 ++++++++++++++++++++++++++--------------------------- 1 file changed, 172 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ceb418d8aa18..b9f8eb0db8a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -448,7 +448,7 @@ dependencies = [ [[package]] name = "beefy-gadget" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "beefy-primitives", "fnv", @@ -476,7 +476,7 @@ dependencies = [ [[package]] name = "beefy-gadget-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "beefy-gadget", "beefy-primitives", @@ -496,12 +496,12 @@ dependencies = [ [[package]] name = "beefy-merkle-tree" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" [[package]] name = "beefy-primitives" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "scale-info", @@ -1845,7 +1845,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", ] @@ -1863,7 +1863,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -1884,7 +1884,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "Inflector", "chrono", @@ -1910,7 +1910,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -1924,7 +1924,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -1952,7 +1952,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "bitflags", "frame-metadata", @@ -1981,7 +1981,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "Inflector", "frame-support-procedural-tools", @@ -1993,7 +1993,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate 1.1.0", @@ -2005,7 +2005,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro2", "quote", @@ -2015,7 +2015,7 @@ dependencies = [ [[package]] name = "frame-support-test" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-support-test-pallet", @@ -2038,7 +2038,7 @@ dependencies = [ [[package]] name = "frame-support-test-pallet" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -2049,7 +2049,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "log", @@ -2066,7 +2066,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -2081,7 +2081,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "sp-api", @@ -2090,7 +2090,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "sp-api", @@ -2292,7 +2292,7 @@ dependencies = [ [[package]] name = "generate-bags" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "chrono", "frame-election-provider-support", @@ -4563,7 +4563,7 @@ checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" [[package]] name = "pallet-assets" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4577,7 +4577,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -4593,7 +4593,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -4608,7 +4608,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4632,7 +4632,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4652,7 +4652,7 @@ dependencies = [ [[package]] name = "pallet-bags-list-remote-tests" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "clap", "frame-election-provider-support", @@ -4674,7 +4674,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4689,7 +4689,7 @@ dependencies = [ [[package]] name = "pallet-beefy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "beefy-primitives", "frame-support", @@ -4705,7 +4705,7 @@ dependencies = [ [[package]] name = "pallet-beefy-mmr" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "beefy-merkle-tree", "beefy-primitives", @@ -4730,7 +4730,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4814,7 +4814,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4831,7 +4831,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4847,7 +4847,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4871,7 +4871,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4889,7 +4889,7 @@ dependencies = [ [[package]] name = "pallet-gilt" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4904,7 +4904,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4927,7 +4927,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "enumflags2", "frame-benchmarking", @@ -4943,7 +4943,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4963,7 +4963,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4980,7 +4980,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -4997,7 +4997,7 @@ dependencies = [ [[package]] name = "pallet-mmr" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "ckb-merkle-mountain-range", "frame-benchmarking", @@ -5015,7 +5015,7 @@ dependencies = [ [[package]] name = "pallet-mmr-primitives" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5031,7 +5031,7 @@ dependencies = [ [[package]] name = "pallet-mmr-rpc" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "jsonrpc-core", "jsonrpc-core-client", @@ -5048,7 +5048,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5063,7 +5063,7 @@ dependencies = [ [[package]] name = "pallet-nicks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5077,7 +5077,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5094,7 +5094,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5117,7 +5117,7 @@ dependencies = [ [[package]] name = "pallet-preimage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#b9cafba3d0e7a5950ac78d81e4ab7f2074938666" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5133,7 +5133,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5148,7 +5148,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5162,7 +5162,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5178,7 +5178,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5199,7 +5199,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5215,7 +5215,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5229,7 +5229,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5252,7 +5252,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", @@ -5263,7 +5263,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-fn" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "log", "sp-arithmetic", @@ -5272,7 +5272,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5286,7 +5286,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5304,7 +5304,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5323,7 +5323,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-support", "frame-system", @@ -5340,7 +5340,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "jsonrpc-core", "jsonrpc-core-client", @@ -5357,7 +5357,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5368,7 +5368,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5385,7 +5385,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -5401,7 +5401,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-benchmarking", "frame-support", @@ -7808,7 +7808,7 @@ dependencies = [ [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "env_logger 0.9.0", "jsonrpsee", @@ -8099,7 +8099,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "log", "sp-core", @@ -8110,7 +8110,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "derive_more", @@ -8137,7 +8137,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "futures-timer 3.0.2", @@ -8160,7 +8160,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -8176,7 +8176,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "impl-trait-for-tuples", "memmap2 0.5.0", @@ -8193,7 +8193,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", @@ -8204,7 +8204,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "chrono", "fdlimit", @@ -8242,7 +8242,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "fnv", "futures 0.3.18", @@ -8270,7 +8270,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "hash-db", "kvdb", @@ -8295,7 +8295,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "futures 0.3.18", @@ -8319,7 +8319,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "derive_more", @@ -8362,7 +8362,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "derive_more", "futures 0.3.18", @@ -8386,7 +8386,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "fork-tree", "parity-scale-codec", @@ -8399,7 +8399,7 @@ dependencies = [ [[package]] name = "sc-consensus-manual-seal" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "assert_matches", "async-trait", @@ -8433,7 +8433,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "futures 0.3.18", @@ -8459,7 +8459,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "sc-client-api", "sp-authorship", @@ -8470,7 +8470,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "lazy_static", "libsecp256k1", @@ -8498,7 +8498,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "derive_more", "environmental", @@ -8516,7 +8516,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "log", "parity-scale-codec", @@ -8532,7 +8532,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "cfg-if 1.0.0", "libc", @@ -8550,7 +8550,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "derive_more", @@ -8587,7 +8587,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "derive_more", "finality-grandpa", @@ -8611,7 +8611,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "ansi_term", "futures 0.3.18", @@ -8628,7 +8628,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "derive_more", @@ -8643,7 +8643,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-std", "async-trait", @@ -8694,7 +8694,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "futures-timer 3.0.2", @@ -8710,7 +8710,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "bytes 1.1.0", "fnv", @@ -8738,7 +8738,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "libp2p", @@ -8751,7 +8751,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -8760,7 +8760,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "hash-db", @@ -8791,7 +8791,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "jsonrpc-core", @@ -8816,7 +8816,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "jsonrpc-core", @@ -8833,7 +8833,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "directories", @@ -8897,7 +8897,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "log", "parity-scale-codec", @@ -8911,7 +8911,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "jsonrpc-core", "jsonrpc-core-client", @@ -8933,7 +8933,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "chrono", "futures 0.3.18", @@ -8951,7 +8951,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "ansi_term", "atty", @@ -8982,7 +8982,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", @@ -8993,7 +8993,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "intervalier", @@ -9020,7 +9020,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "derive_more", "futures 0.3.18", @@ -9034,7 +9034,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "futures-timer 3.0.2", @@ -9439,7 +9439,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "hash-db", "log", @@ -9456,7 +9456,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "blake2-rfc", "proc-macro-crate 1.1.0", @@ -9467,8 +9467,8 @@ dependencies = [ [[package]] name = "sp-application-crypto" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "scale-info", @@ -9480,8 +9480,8 @@ dependencies = [ [[package]] name = "sp-arithmetic" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "integer-sqrt", "num-traits", @@ -9496,7 +9496,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "scale-info", @@ -9509,7 +9509,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "parity-scale-codec", @@ -9521,7 +9521,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "sp-api", @@ -9533,7 +9533,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "log", @@ -9551,7 +9551,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "futures 0.3.18", @@ -9570,7 +9570,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "merlin", @@ -9593,7 +9593,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "scale-info", @@ -9605,7 +9605,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "schnorrkel", @@ -9617,7 +9617,7 @@ dependencies = [ [[package]] name = "sp-core" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "base58", "bitflags", @@ -9665,7 +9665,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "blake2-rfc", "byteorder", @@ -9678,7 +9678,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro2", "quote", @@ -9689,7 +9689,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "kvdb", "parking_lot", @@ -9698,7 +9698,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro2", "quote", @@ -9708,7 +9708,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.10.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "environmental", "parity-scale-codec", @@ -9719,7 +9719,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "finality-grandpa", "log", @@ -9737,7 +9737,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -9750,8 +9750,8 @@ dependencies = [ [[package]] name = "sp-io" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "hash-db", @@ -9775,7 +9775,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "lazy_static", "sp-core", @@ -9785,8 +9785,8 @@ dependencies = [ [[package]] name = "sp-keystore" -version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "0.10.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "derive_more", @@ -9803,7 +9803,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "zstd", ] @@ -9811,7 +9811,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "scale-info", @@ -9826,7 +9826,7 @@ dependencies = [ [[package]] name = "sp-npos-elections-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", @@ -9837,7 +9837,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "sp-api", "sp-core", @@ -9846,8 +9846,8 @@ dependencies = [ [[package]] name = "sp-panic-handler" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "backtrace", "lazy_static", @@ -9857,7 +9857,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "rustc-hash", "serde", @@ -9866,8 +9866,8 @@ dependencies = [ [[package]] name = "sp-runtime" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "either", "hash256-std-hasher", @@ -9889,7 +9889,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -9906,7 +9906,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "Inflector", "proc-macro-crate 1.1.0", @@ -9918,7 +9918,7 @@ dependencies = [ [[package]] name = "sp-serializer" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "serde", "serde_json", @@ -9927,7 +9927,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "scale-info", @@ -9941,7 +9941,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "scale-info", @@ -9951,8 +9951,8 @@ dependencies = [ [[package]] name = "sp-state-machine" -version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "0.10.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "hash-db", "log", @@ -9975,12 +9975,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" [[package]] name = "sp-storage" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "impl-serde", "parity-scale-codec", @@ -9993,7 +9993,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "log", "sp-core", @@ -10006,7 +10006,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "futures-timer 3.0.2", @@ -10022,7 +10022,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "sp-std", @@ -10034,7 +10034,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "sp-api", "sp-runtime", @@ -10043,7 +10043,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "log", @@ -10058,8 +10058,8 @@ dependencies = [ [[package]] name = "sp-trie" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "hash-db", "memory-db", @@ -10074,7 +10074,7 @@ dependencies = [ [[package]] name = "sp-version" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "impl-serde", "parity-scale-codec", @@ -10090,7 +10090,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -10101,7 +10101,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "impl-trait-for-tuples", "log", @@ -10314,7 +10314,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "platforms", ] @@ -10322,7 +10322,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-system-rpc-runtime-api", "futures 0.3.18", @@ -10344,7 +10344,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-std", "derive_more", @@ -10358,7 +10358,7 @@ dependencies = [ [[package]] name = "substrate-test-client" version = "2.0.1" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "async-trait", "futures 0.3.18", @@ -10384,7 +10384,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "futures 0.3.18", "substrate-test-utils-derive", @@ -10394,7 +10394,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", @@ -10405,7 +10405,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "ansi_term", "build-helper", @@ -10547,7 +10547,7 @@ dependencies = [ [[package]] name = "test-runner" version = "0.9.0" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "frame-system", "futures 0.3.18", @@ -10988,7 +10988,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#49a4b1822e19e5b82c59ba5b36a1d7997f0a3929" +source = "git+https://github.com/paritytech/substrate?branch=master#fb08d15bcbea68415dd4ee90d11556b653096f10" dependencies = [ "jsonrpsee", "log",