From 8145df768ae5c0270f752d19078ff0b2fa80a5c4 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 6 Jan 2020 16:08:11 +0100 Subject: [PATCH 1/5] Spaces to tabs. --- primitives/consensus/babe/src/inherents.rs | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/primitives/consensus/babe/src/inherents.rs b/primitives/consensus/babe/src/inherents.rs index 5a4e042352dcb..4fe71dbb8a7c4 100644 --- a/primitives/consensus/babe/src/inherents.rs +++ b/primitives/consensus/babe/src/inherents.rs @@ -32,59 +32,59 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"babeslot"; pub type InherentType = u64; /// Auxiliary trait to extract BABE inherent data. pub trait BabeInherentData { - /// Get BABE inherent data. - fn babe_inherent_data(&self) -> Result; - /// Replace BABE inherent data. - fn babe_replace_inherent_data(&mut self, new: InherentType); + /// Get BABE inherent data. + fn babe_inherent_data(&self) -> Result; + /// Replace BABE inherent data. + fn babe_replace_inherent_data(&mut self, new: InherentType); } impl BabeInherentData for InherentData { - fn babe_inherent_data(&self) -> Result { - self.get_data(&INHERENT_IDENTIFIER) - .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) - } + fn babe_inherent_data(&self) -> Result { + self.get_data(&INHERENT_IDENTIFIER) + .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) + } - fn babe_replace_inherent_data(&mut self, new: InherentType) { - self.replace_data(INHERENT_IDENTIFIER, &new); - } + fn babe_replace_inherent_data(&mut self, new: InherentType) { + self.replace_data(INHERENT_IDENTIFIER, &new); + } } /// Provides the slot duration inherent data for BABE. #[cfg(feature = "std")] pub struct InherentDataProvider { - slot_duration: u64, + slot_duration: u64, } #[cfg(feature = "std")] impl InherentDataProvider { - /// Constructs `Self` - pub fn new(slot_duration: u64) -> Self { - Self { slot_duration } - } + /// Constructs `Self` + pub fn new(slot_duration: u64) -> Self { + Self { slot_duration } + } } #[cfg(feature = "std")] impl ProvideInherentData for InherentDataProvider { - fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { - if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { - // Add the timestamp inherent data provider, as we require it. - providers.register_provider(sp_timestamp::InherentDataProvider) - } else { - Ok(()) - } - } + fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { + if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { + // Add the timestamp inherent data provider, as we require it. + providers.register_provider(sp_timestamp::InherentDataProvider) + } else { + Ok(()) + } + } - fn inherent_identifier(&self) -> &'static InherentIdentifier { - &INHERENT_IDENTIFIER - } + fn inherent_identifier(&self) -> &'static InherentIdentifier { + &INHERENT_IDENTIFIER + } - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { - let timestamp = inherent_data.timestamp_inherent_data()?; - let slot_number = timestamp / self.slot_duration; - inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) - } + fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { + let timestamp = inherent_data.timestamp_inherent_data()?; + let slot_number = timestamp / self.slot_duration; + inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) + } - fn error_to_string(&self, error: &[u8]) -> Option { - Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() - } + fn error_to_string(&self, error: &[u8]) -> Option { + Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() + } } From fca71bef05c4550cc0973de7a4868f5d5540cd76 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 10 Jan 2020 12:26:33 +0100 Subject: [PATCH 2/5] Replace grafana and tidy --- Cargo.lock | 66 +++--------- Cargo.toml | 2 - client/cli/Cargo.toml | 2 +- client/cli/src/informant/display.rs | 16 ++- client/cli/src/lib.rs | 12 +-- client/cli/src/params.rs | 22 ++-- client/service/Cargo.toml | 3 +- client/service/src/builder.rs | 95 ++++++++++------- client/service/src/config.rs | 5 +- client/service/test/src/lib.rs | 1 - client/tracing/Cargo.toml | 1 - client/tracing/src/lib.rs | 16 ++- utils/grafana-data-source/Cargo.toml | 23 ---- utils/grafana-data-source/test/Cargo.toml | 13 --- utils/prometheus/Cargo.toml | 10 +- .../prometheus/photo_2019-12-13_16-32-53.jpg | Bin 27726 -> 0 bytes utils/prometheus/src/lib.rs | 86 ++++++--------- utils/prometheus/src/metrics.rs | 100 ------------------ .../src/networking.rs | 0 19 files changed, 145 insertions(+), 328 deletions(-) delete mode 100644 utils/grafana-data-source/Cargo.toml delete mode 100644 utils/grafana-data-source/test/Cargo.toml delete mode 100644 utils/prometheus/photo_2019-12-13_16-32-53.jpg delete mode 100644 utils/prometheus/src/metrics.rs rename utils/{grafana-data-source => prometheus}/src/networking.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 194716611f7f2..4367a7fc8ae60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -500,7 +500,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1676,34 +1675,6 @@ dependencies = [ "scroll 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "grafana-data-source" -version = "2.0.0" -dependencies = [ - "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "grafana-data-source-test" -version = "2.0.0" -dependencies = [ - "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", - "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "h2" version = "0.1.26" @@ -4451,6 +4422,21 @@ dependencies = [ "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "prometheus-endpoint" +version = "2.0.0" +dependencies = [ + "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sp-runtime 2.0.0", + "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "prost" version = "0.5.0" @@ -5063,11 +5049,11 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "prometheus-endpoint 2.0.0", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client-api 2.0.0", "sc-network 0.8.0", - "sc-prometheus 2.0.0", "sc-service 2.0.0", "sc-telemetry 2.0.0", "sc-tracing 2.0.0", @@ -5595,22 +5581,6 @@ dependencies = [ "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sc-prometheus" -version = "2.0.0" -dependencies = [ - "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", - "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime 2.0.0", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sc-rpc" version = "2.0.0" @@ -5702,12 +5672,12 @@ dependencies = [ "exit-future 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "prometheus-endpoint 2.0.0", "sc-chain-spec 2.0.0", "sc-client 2.0.0", "sc-client-api 2.0.0", @@ -5717,7 +5687,6 @@ dependencies = [ "sc-keystore 2.0.0", "sc-network 0.8.0", "sc-offchain 2.0.0", - "sc-prometheus 2.0.0", "sc-rpc 2.0.0", "sc-rpc-server 2.0.0", "sc-telemetry 2.0.0", @@ -5803,7 +5772,6 @@ name = "sc-tracing" version = "2.0.0" dependencies = [ "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-telemetry 2.0.0", diff --git a/Cargo.toml b/Cargo.toml index e5940e5b7cdf1..219b1588f9618 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,8 +50,6 @@ members = [ "client/transaction-pool/graph", "utils/prometheus", "utils/wasm-builder-runner", - "utils/grafana-data-source", - "utils/grafana-data-source/test", "frame/assets", "frame/aura", "frame/authority-discovery", diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 5c7ac86904164..05fc019d0a9d9 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -29,7 +29,7 @@ sp-core = { version = "2.0.0", path = "../../primitives/core" } sc-service = { version = "2.0.0", default-features = false, path = "../service" } sp-state-machine = { version = "2.0.0", path = "../../primitives/state-machine" } sc-telemetry = { version = "2.0.0", path = "../telemetry" } -sc-prometheus = { path = "../../utils/prometheus" } +prometheus-endpoint = { path = "../../utils/prometheus" } sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" } names = "0.11.0" structopt = "=0.3.7" diff --git a/client/cli/src/informant/display.rs b/client/cli/src/informant/display.rs index f0b6e61176de7..b39cb2ddd1766 100644 --- a/client/cli/src/informant/display.rs +++ b/client/cli/src/informant/display.rs @@ -18,10 +18,20 @@ use ansi_term::Colour; use sc_client_api::ClientInfo; use log::info; use sc_network::SyncState; -use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating}; +use sp_runtime::traits::{ + Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating, UniqueSaturatedInto +}; use sc_service::NetworkStatus; use std::{convert::{TryFrom, TryInto}, fmt, time}; -use sc_prometheus::prometheus_gauge; +use prometheus_endpoint::{create_gauge, Gauge}; + +prometheus_endpoint::lazy_static! { + pub static ref SYNC_TARGET: Gauge = create_gauge( + "sync_target_number", + "block sync target number" + ); +} + /// State of the informant display system. /// /// This is the system that handles the line that gets regularly printed and that looks something @@ -64,7 +74,7 @@ impl InformantDisplay { (SyncState::Idle, _) => ("Idle".into(), "".into()), (SyncState::Downloading, None) => (format!("Syncing{}", speed), "".into()), (SyncState::Downloading, Some(n)) => { - prometheus_gauge!(TARGET_NUM => n.saturated_into().try_into().unwrap()); + SYNC_TARGET.set(n.unique_saturated_into() as i64); (format!("Syncing{}", speed), format!(", target=#{}", n)) } }; diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 36bf19eedd0ec..c92b764b247ca 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -909,13 +909,12 @@ where let rpc_interface: &str = interface_str(cli.rpc_external, cli.unsafe_rpc_external, cli.validator)?; let ws_interface: &str = interface_str(cli.ws_external, cli.unsafe_ws_external, cli.validator)?; - let grafana_interface: &str = if cli.grafana_external { "0.0.0.0" } else { "127.0.0.1" }; let prometheus_interface: &str = if cli.prometheus_external { "0.0.0.0" } else { "127.0.0.1" }; config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9933), cli.rpc_port)?); config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9944), cli.ws_port)?); - config.grafana_port = Some( - parse_address(&format!("{}:{}", grafana_interface, 9955), cli.grafana_port)? + config.prometheus_port = Some( + parse_address(&format!("{}:{}", prometheus_interface, 9955), cli.prometheus_port)? ); config.rpc_ws_max_connections = cli.ws_max_connections; @@ -942,12 +941,7 @@ where config.tracing_targets = cli.tracing_targets.into(); config.tracing_receiver = cli.tracing_receiver.into(); - - // Override prometheus - if cli.prometheus_external { - config.prometheus_port = Some( - parse_address(&format!("{}:{}", prometheus_interface, 33333), cli.prometheus_port)? - )} + // Imply forced authoring on --dev config.force_authoring = cli.shared_params.dev || cli.force_authoring; diff --git a/client/cli/src/params.rs b/client/cli/src/params.rs index 3fd521b1334b9..377e2c1dc0def 100644 --- a/client/cli/src/params.rs +++ b/client/cli/src/params.rs @@ -298,7 +298,7 @@ arg_enum! { pub enum TracingReceiver { Log, Telemetry, - Grafana, + Prometheus, } } @@ -307,7 +307,7 @@ impl Into for TracingReceiver { match self { TracingReceiver::Log => sc_tracing::TracingReceiver::Log, TracingReceiver::Telemetry => sc_tracing::TracingReceiver::Telemetry, - TracingReceiver::Grafana => sc_tracing::TracingReceiver::Grafana, + TracingReceiver::Prometheus => sc_tracing::TracingReceiver::Prometheus, } } } @@ -440,12 +440,6 @@ pub struct RunCmd { /// Use `--unsafe-ws-external` to suppress the warning if you understand the risks. #[structopt(long = "ws-external")] pub ws_external: bool, - /// Prometheus exporter TCP port. - #[structopt(long = "prometheus-port", value_name = "PORT")] - pub prometheus_port: Option, - /// Prometheus exporter on/off external". - #[structopt(long = "prometheus-external")] - pub prometheus_external: bool, /// Listen to all Websocket interfaces. /// @@ -453,11 +447,11 @@ pub struct RunCmd { #[structopt(long = "unsafe-ws-external")] pub unsafe_ws_external: bool, - /// Listen to all Grafana data source interfaces. + /// Listen to all Prometheus endpoint interfaces. /// /// Default is local. - #[structopt(long = "grafana-external")] - pub grafana_external: bool, + #[structopt(long = "prometheus-external")] + pub prometheus_external: bool, /// Specify HTTP RPC server TCP port. #[structopt(long = "rpc-port", value_name = "PORT")] @@ -481,9 +475,9 @@ pub struct RunCmd { #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))] pub rpc_cors: Option, - /// Specify Grafana data source server TCP Port. - #[structopt(long = "grafana-port", value_name = "PORT")] - pub grafana_port: Option, + /// Specify Prometheus endpoint TCP Port. + #[structopt(long = "prometheus-port", value_name = "PORT")] + pub prometheus_port: Option, /// The human-readable name for this node. /// diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 887e8415f39b7..42f0a73dfbfa2 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -51,10 +51,9 @@ sc-rpc = { version = "2.0.0", path = "../rpc" } sc-telemetry = { version = "2.0.0", path = "../telemetry" } sc-offchain = { version = "2.0.0", path = "../offchain" } parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" } -grafana-data-source = { version = "2.0.0", path = "../../utils/grafana-data-source" } +prometheus-endpoint = { path = "../../utils/prometheus" } sc-tracing = { version = "2.0.0", path = "../tracing" } tracing = "0.1.10" -sc-prometheus = { package = "sc-prometheus", path="../../utils/prometheus"} [dev-dependencies] substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" } diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 424f47d57a614..3a447cd06f877 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -53,11 +53,51 @@ use std::{ use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_transaction_pool::{TransactionPool, TransactionPoolMaintainer}; -use sc_prometheus::prometheus_gauge; - use sp_blockchain; -use grafana_data_source::{self, record_metrics}; - +use prometheus_endpoint::{create_gauge, Gauge}; + +prometheus_endpoint::lazy_static! { + pub static ref FINALITY_HEIGHT: Gauge = create_gauge( + "consensus_finality_block_height_number", + "block is finality HEIGHT" + ); + pub static ref BEST_HEIGHT: Gauge = create_gauge( + "consensus_best_block_height_number", + "block is best HEIGHT" + ); + pub static ref BLOCK_INTERVAL_SECONDS: Gauge = create_gauge( + "consensus_block_interval_seconds", + "Time between this and last block(Block.Header.Time) in seconds" + ); + pub static ref P2P_PEERS_NUM: Gauge = create_gauge( + "p2p_peers_number", + "network gosip peers number" + ); + pub static ref TX_COUNT: Gauge = create_gauge( + "consensus_num_txs", + "Number of transactions" + ); + pub static ref NODE_MEMORY: Gauge = create_gauge( + "consensus_node_memory", + "node memory" + ); + pub static ref NODE_CPU: Gauge = create_gauge( + "consensus_node_cpu", + "node cpu" + ); + pub static ref STATE_CACHE_SIZE: Gauge = create_gauge( + "consensus_state_cache_size", + "used state cache size" + ); + pub static ref P2P_NODE_DOWNLOAD: Gauge = create_gauge( + "p2p_peers_receive_byte_per_sec", + "p2p_node_download_per_sec_byte" + ); + pub static ref P2P_NODE_UPLOAD: Gauge = create_gauge( + "p2p_peers_send_byte_per_sec", + "p2p_node_upload_per_sec_byte" + ); +} /// Aggregator for the components required to build a service. /// /// # Usage @@ -956,28 +996,14 @@ ServiceBuilder< "bandwidth_upload" => bandwidth_upload, "used_state_cache_size" => used_state_cache_size, ); - prometheus_gauge!( - STATE_CACHE_SIZE => used_state_cache_size as u64, - NODE_MEMORY => memory as u64, - NODE_CPU => cpu_usage as u64, - TX_COUNT => txpool_status.ready as u64, - FINALITY_HEIGHT => finalized_number as u64, - BEST_HEIGHT => best_number as u64, - P2P_PEERS_NUM => num_peers as u64, - P2P_NODE_DOWNLOAD => net_status.average_download_per_sec as u64, - P2P_NODE_UPLOAD => net_status.average_upload_per_sec as u64 - ); - let _ = record_metrics!( - "peers" => num_peers, - "height" => best_number, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "bandwidth_download" => bandwidth_download, - "bandwidth_upload" => bandwidth_upload, - "used_state_cache_size" => used_state_cache_size, - ); + NODE_MEMORY.set(memory as i64); + NODE_CPU.set(cpu_usage as i64); + TX_COUNT.set(txpool_status.ready as i64); + FINALITY_HEIGHT.set(finalized_number as i64); + BEST_HEIGHT.set(best_number as i64); + P2P_PEERS_NUM.set(num_peers as i64); + P2P_NODE_DOWNLOAD.set(net_status.average_download_per_sec as i64); + P2P_NODE_UPLOAD.set(net_status.average_upload_per_sec as i64); Ok(()) }).select(exit.clone().map(Ok).compat()).then(|_| Ok(())); let _ = to_spawn_tx.unbounded_send(Box::new(tel_task)); @@ -1115,21 +1141,10 @@ ServiceBuilder< .then(|_| Ok(())))); telemetry }); - // prometheus init + // Prometheus endpoint if let Some(port) = config.prometheus_port { let future = select( - sc_prometheus::init_prometheus(port).boxed() - ,exit.clone() - ).map(|either| match either { - Either::Left((result, _)) => result.map_err(|_| ()), - Either::Right(_) => Ok(()) - }).compat(); - let _ = to_spawn_tx.unbounded_send(Box::new(future)); - } - // Grafana data source - if let Some(port) = config.grafana_port { - let future = select( - grafana_data_source::run_server(port).boxed(), + prometheus_endpoint::init_prometheus(port).boxed(), exit.clone() ).map(|either| match either { Either::Left((result, _)) => result.map_err(|_| ()), @@ -1137,7 +1152,7 @@ ServiceBuilder< }).compat(); let _ = to_spawn_tx.unbounded_send(Box::new(future)); - } + } // Instrumentation if let Some(tracing_targets) = config.tracing_targets.as_ref() { diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 2f0a2ba83a071..9f240a19affba 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -73,9 +73,7 @@ pub struct Configuration { pub rpc_ws_max_connections: Option, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option>, - /// Grafana data source http port. `None` if disabled. - pub grafana_port: Option, - /// Prometheus Port.`None` if disabled and port 33333 by default. + /// Prometheus endpoint Port. `None` if disabled. pub prometheus_port: Option, /// Telemetry service URL. `None` if disabled. pub telemetry_endpoints: Option, @@ -156,7 +154,6 @@ impl Configuration where rpc_ws_max_connections: None, rpc_cors: Some(vec![]), prometheus_port: None, - grafana_port: None, telemetry_endpoints: None, telemetry_external_transport: None, default_heap_pages: None, diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index ea3e523d4ef0a..cf1baa06db6c8 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -193,7 +193,6 @@ fn node_config ( rpc_ws_max_connections: None, rpc_cors: None, prometheus_port: None, - grafana_port: None, telemetry_endpoints: None, telemetry_external_transport: None, default_heap_pages: None, diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index 2ceee93f6a62a..ed9b52fc26e20 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -15,7 +15,6 @@ slog = { version = "2.5.2", features = ["nested-values"] } tracing-core = "0.1.7" sc-telemetry = { version = "2.0.0", path = "../telemetry" } -grafana-data-source = { version = "2.0.0", path = "../../utils/grafana-data-source" } [dev-dependencies] tracing = "0.1.10" diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 288d5e70192de..32dc27be158e0 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -34,7 +34,7 @@ //! let span = tracing::span!(tracing::Level::INFO, "my_span_name", my_number = 10, a_key = "a value"); //! let _guard = span.enter(); //! ``` -//! Currently we provide `Log` (default), `Telemetry` and `Grafana` variants for `Receiver` +//! Currently we provide `Log` (default), `Telemetry` and `Prometheus` variants for `Receiver` use std::collections::HashMap; use std::fmt; @@ -53,7 +53,6 @@ use tracing_core::{ subscriber::Subscriber }; -use grafana_data_source::{self, record_metrics}; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; /// Used to configure how to receive the metrics @@ -63,8 +62,8 @@ pub enum TracingReceiver { Log, /// Output to telemetry Telemetry, - /// Output to Grafana - Grafana, + /// Output to Prometheus endpoint + Prometheus, } impl Default for TracingReceiver { @@ -255,7 +254,7 @@ impl ProfilingSubscriber { match self.receiver { TracingReceiver::Log => print_log(span_datum), TracingReceiver::Telemetry => send_telemetry(span_datum), - TracingReceiver::Grafana => send_grafana(span_datum), + TracingReceiver::Prometheus => send_prometheus(span_datum), } } } @@ -291,9 +290,6 @@ fn send_telemetry(span_datum: SpanDatum) { ); } -fn send_grafana(span_datum: SpanDatum) { - let name = format!("{}::{}", span_datum.target, span_datum.name); - if let Err(e) = record_metrics!(&name => span_datum.overall_time.as_nanos(),) { - log::warn!("Unable to send metrics to grafana: {:?}", e); - } +fn send_prometheus(span_datum: SpanDatum) { + unimplemented!() } diff --git a/utils/grafana-data-source/Cargo.toml b/utils/grafana-data-source/Cargo.toml deleted file mode 100644 index 76bf7d5988d9a..0000000000000 --- a/utils/grafana-data-source/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -description = "Grafana data source server" -name = "grafana-data-source" -version = "2.0.0" -license = "GPL-3.0" -authors = ["Parity Technologies "] -edition = "2018" - -[dependencies] -log = "0.4.8" -hyper = { version = "0.13.1", default-features = false, features = ["stream"] } -tokio = "0.2" -futures-util = { version = "0.3.1", default-features = false, features = ["io"] } -serde_json = "1" -serde = { version = "1", features = ["derive"] } -chrono = { version = "0.4", features = ["serde"] } -lazy_static = "1.4" -parking_lot = "0.9" -futures-timer = "2.0" -derive_more = "0.99" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] -async-std = { version = "1.0.1", features = ["unstable"] } diff --git a/utils/grafana-data-source/test/Cargo.toml b/utils/grafana-data-source/test/Cargo.toml deleted file mode 100644 index 079b49dc8608a..0000000000000 --- a/utils/grafana-data-source/test/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -description = "Grafana data source server test" -name = "grafana-data-source-test" -version = "2.0.0" -license = "GPL-3.0" -authors = ["Parity Technologies "] -edition = "2018" - -[dependencies] -grafana-data-source = { version = "2.0.0", path = ".." } -futures = "0.3" -futures-timer = "2.0" -rand = "0.7" diff --git a/utils/prometheus/Cargo.toml b/utils/prometheus/Cargo.toml index 46b5c42ca3ef4..3f3b4bf408df0 100644 --- a/utils/prometheus/Cargo.toml +++ b/utils/prometheus/Cargo.toml @@ -1,20 +1,20 @@ [package] -name = "sc-prometheus" +description = "Prometheus endpoint server" +name = "prometheus-endpoint" version = "2.0.0" +license = "GPL-3.0" authors = ["Parity Technologies "] -description = "prometheus utils" edition = "2018" [dependencies] -hyper = { version = "0.13.1", default-features = false, features = ["stream"] } -lazy_static = "1.4" log = "0.4.8" +hyper = { version = "0.13.1", default-features = false, features = ["stream"] } prometheus = { version = "0.7", features = ["nightly", "process"]} tokio = "0.2" futures-util = { version = "0.3.1", default-features = false, features = ["io"] } +lazy_static = "1.4" sp-runtime = { package = "sp-runtime",path = "../../primitives/runtime" } derive_more = "0.99" -grafana-data-source = { version = "2.0.0", path = "../grafana-data-source" } [target.'cfg(not(target_os = "unknown"))'.dependencies] async-std = { version = "1.0.1", features = ["unstable"] } diff --git a/utils/prometheus/photo_2019-12-13_16-32-53.jpg b/utils/prometheus/photo_2019-12-13_16-32-53.jpg deleted file mode 100644 index cdf44f88fb623d7b5a319235c6d603463698716c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27726 zcmeFZcT`m0wkEoDJ3nV{7^+zOM;&BO;@slT%XD z(lg$@&-|44IsZ#R;n$*y%Bt$`HMMp1ZS5VMUEMvsKZi#~$Hpfnr>2*dS60{7H#WDn z(T7LJC#PqaKj(k5ivVxuzaIZ$*gx4tgSYD%At8tm{5QJ@u6g4Jh=!2p=6zyXrKjMR zu5`CVf=TEfBz-LZLCPii48>sSHblnAEw;pi{+nrkx9mS=Sjhh;%l?O9|7O=TKmj7a z-#icv00qv@`91}a{WbntgTFBF7Y6>qz+V{n3j=>);4cjPg@L~?@V^fOcdL)%D8o7m z6+NQfYu6G^gu-l2qdlj2yR+$c()IQ4cPpltf()(0YbPjhIc@YZY7eh#32s`4KgPi&q)`=tn2 zr%VSyRGwF~RE?HmFZkb;-Rd<%-+P%fYW>u+(AY?f-_xD`w)YfuQpka`QqGqk!66lT z;OYN;gMb26+S&N6`9V+qb$Kd=BSh2{V3V!YBZuQ?Hrb50MT*l<8%#)Rd363L8o-!e z0Z+#Lg$pAO1j~*us->T`epJ|2vuJB*q44)WYlT&?ohIm4u`|>z>&SnA>o{y(sy+HP zF339ZtTJSuc!#}*88VRXqxQG|(NC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qHF%i)6%zW%SbtgVli(^LdD7h*42hKbHKunKW z)>HTsLp|h-UP`(z=EMgBp@5nirF}=w)2;WIgOHc;o>C8tlQp1{kTP=~9yAPVq={9y zaMW#sX;KM)$(?IyGtxlN;4Y;gb-PLj6~i*BEMwkwD;3*xgXE~O3)<969JpBfeg}$d z`Z3os{Nc%-u|^pBICcDNodZPFGQ#=fb{bP1=3z{XxQnWIgIx8NIozxaJfUf{Wxpo) zE*Z?=E9`c6QOAuZvD-vHAhbo{lYIeArCL5%3%G@Ru+jM?n4dO1{X)>E`rAwAGdUiE0|jsIffrYU|H?-yt$9 z69568juojC@E$e9*JiwCNBR8vFfNmF))gLYp&$7?I+8@h34ale4%r+IF@b(TPsg>ZXJ;5@soz3YFR!o@h#9C_PWJsU}HlQ=an7<*T32N z7@)}Xt0cMyxe2!}lnz1g5SI#E*wxKj*3EegcTjcn$NV?bx>^!?t>Adb%1~>pKbWSe z8^Ra>4JWFK*5fROv6sYqRRmFE^$l{j)5@IJKx8zSyGL%E0~H(1;ZlF=z!%px-9w0$ z8yx{$C@&yzbg_Fn~o1f^PpdHVP2-b2=UXi1Tasg|exvf{Pyq(U0PS;ut26BQ> z;L*6vS^dbEuQWOEE4=8@js57=x+>eW z?-@c?e7s^hR}#!3c-U3gWK%;BuYqwdHV=7_3sWUkXHWV0_sCcuv@~s}h!up1(At+kaFO^=KyT&{a>MXi>v?u diff --git a/utils/prometheus/src/lib.rs b/utils/prometheus/src/lib.rs index a6d9397575db6..6883fae48fae1 100644 --- a/utils/prometheus/src/lib.rs +++ b/utils/prometheus/src/lib.rs @@ -22,13 +22,21 @@ use hyper::http::StatusCode; use hyper::Server; use hyper::{Body, Request, Response, service::{service_fn, make_service_fn}}; pub use prometheus::{Encoder, HistogramOpts, Opts, TextEncoder}; -pub use prometheus::{Histogram, IntCounter, IntGauge}; +pub use prometheus::{Histogram, IntCounter}; +pub use prometheus::IntGauge as Gauge; pub use sp_runtime::traits::SaturatedConversion; use std::net::SocketAddr; -//#[cfg(not(target_os = "unknown"))] -//mod networking; +#[cfg(not(target_os = "unknown"))] +mod networking; + +pub use lazy_static::lazy_static; -pub mod metrics; +pub fn create_gauge(name: &str, description: &str) -> Gauge { + let opts = Opts::new(name, description); + let gauge = Gauge::with_opts(opts).expect("Creating Gauge Failed"); + prometheus::register(Box::new(gauge.clone())).expect("Registering gauge failed"); + gauge +} #[derive(Debug, derive_more::Display, derive_more::From)] pub enum Error { @@ -50,23 +58,22 @@ impl std::error::Error for Error { } async fn request_metrics(req: Request) -> Result, Error> { - if req.uri().path() == "/metrics" { - let metric_families = prometheus::gather(); - let mut buffer = vec![]; - let encoder = TextEncoder::new(); - encoder.encode(&metric_families, &mut buffer).unwrap(); - Response::builder() - .status(StatusCode::OK) - .header("Content-Type", encoder.format_type()) - .body(Body::from(buffer)) - .map_err(Error::Http) - } else { - Response::builder() - .status(StatusCode::NOT_FOUND) - .body(Body::from("Not found.")) - .map_err(Error::Http) - } - + if req.uri().path() == "/metrics" { + let metric_families = prometheus::gather(); + let mut buffer = vec![]; + let encoder = TextEncoder::new(); + encoder.encode(&metric_families, &mut buffer).unwrap(); + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", encoder.format_type()) + .body(Body::from(buffer)) + .map_err(Error::Http) + } else { + Response::builder() + .status(StatusCode::NOT_FOUND) + .body(Body::from("Not found.")) + .map_err(Error::Http) + } } #[derive(Clone)] @@ -86,8 +93,8 @@ impl hyper::rt::Executor for Executor /// to serve metrics. #[cfg(not(target_os = "unknown"))] pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Error>{ - use async_std::{net, io}; - use grafana_data_source::networking::Incoming; + use async_std::{net, io}; + use networking::Incoming; let listener = loop { let listener = net::TcpListener::bind(&prometheus_addr).await; match listener { @@ -103,23 +110,21 @@ pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Err prometheus_addr.set_port(0); continue; }, - _ => return Err(err.into()) - } + _ => return Err(err.into()) + } } }; - let service = make_service_fn(|_| { + let service = make_service_fn(|_| { async { Ok::<_, Error>(service_fn(request_metrics)) } }); - let _server = Server::builder(Incoming(listener.incoming())) .executor(Executor) .serve(service) - .boxed(); - - + .boxed(); + let result = _server.await.map_err(Into::into); result @@ -129,24 +134,3 @@ pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Err pub async fn init_prometheus(_: SocketAddr) -> Result<(), Error> { Ok(()) } - - -#[macro_export] -macro_rules! prometheus_gauge( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_gauge(&$metric, $value); - )* - } -); - -#[macro_export] -macro_rules! prometheus_histogram( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_histogram(&$metric, $value); - )* - } -); diff --git a/utils/prometheus/src/metrics.rs b/utils/prometheus/src/metrics.rs deleted file mode 100644 index 61a7fcc6eb3fc..0000000000000 --- a/utils/prometheus/src/metrics.rs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2019 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 . - - -pub use crate::*; -pub use prometheus::Result; -/// Gauge type metrics generation function -pub fn try_create_int_gauge(name: &str, help: &str) -> Result { - let opts = Opts::new(name, help); - let gauge = IntGauge::with_opts(opts)?; - prometheus::register(Box::new(gauge.clone()))?; - Ok(gauge) -} -/// histogram type metrics generation function -pub fn try_create_histogram(name: &str, help: &str) -> Result { - let opts = HistogramOpts::new(name, help); - let histogram = Histogram::with_opts(opts)?; - prometheus::register(Box::new(histogram.clone()))?; - Ok(histogram) -} - -/// Gauge Metrics a value in injection. -pub fn set_gauge(gauge: &Result, value: u64) { - if let Ok(gauge) = gauge { - gauge.set(value as i64); - } -} -/// histogram Metrics a value in injection. -pub fn set_histogram(histogram: &Result, value: f64) { - if let Ok(histogram) = histogram { - histogram.observe(value) - } -} -/// All of the metrics in the prometheus are managed by the lazy_static. - -lazy_static! { - pub static ref FINALITY_HEIGHT: Result = try_create_int_gauge( - "consensus_finality_block_height_number", - "block is finality HEIGHT" - - ); - - pub static ref BEST_HEIGHT: Result = try_create_int_gauge( - "consensus_best_block_height_number", - "block is best HEIGHT" - ); - - pub static ref P2P_PEERS_NUM: Result = try_create_int_gauge( - "p2p_peers_number", - "network gosip peers number" - ); - - pub static ref TARGET_NUM: Result = try_create_int_gauge( - "consensus_target_syn_number", - "block syn target number" - ); - - pub static ref TX_COUNT: Result = try_create_int_gauge( - "consensus_num_txs", - "Number of transactions" - ); - - pub static ref NODE_MEMORY: Result = try_create_int_gauge( - "consensus_node_memory", - "node memory" - ); - - pub static ref NODE_CPU: Result = try_create_int_gauge( - "consensus_node_cpu", - "node cpu" - ); - - pub static ref STATE_CACHE_SIZE: Result = try_create_int_gauge( - "consensus_state_cache_size", - "used state cache size" - ); - - pub static ref P2P_NODE_DOWNLOAD: Result = try_create_int_gauge( - "p2p_peers_receive_byte_per_sec", - "p2p_node_download_per_sec_byte" - ); - - pub static ref P2P_NODE_UPLOAD: Result = try_create_int_gauge( - "p2p_peers_send_byte_per_sec", - "p2p_node_upload_per_sec_byte" - ); -} diff --git a/utils/grafana-data-source/src/networking.rs b/utils/prometheus/src/networking.rs similarity index 100% rename from utils/grafana-data-source/src/networking.rs rename to utils/prometheus/src/networking.rs From 855ceed68ed9c5a523fd6a7b08b4f61f48a882aa Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 10 Jan 2020 12:11:58 +0100 Subject: [PATCH 3/5] Add generics --- Cargo.lock | 1 - client/cli/src/informant/display.rs | 6 ++-- client/service/src/builder.rs | 42 +++++++++++---------------- utils/prometheus/Cargo.toml | 1 - utils/prometheus/src/lib.rs | 44 ++++++++++++----------------- 5 files changed, 38 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4367a7fc8ae60..010acdb334062 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4433,7 +4433,6 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime 2.0.0", "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/client/cli/src/informant/display.rs b/client/cli/src/informant/display.rs index b39cb2ddd1766..3f0c1b8d60604 100644 --- a/client/cli/src/informant/display.rs +++ b/client/cli/src/informant/display.rs @@ -23,10 +23,10 @@ use sp_runtime::traits::{ }; use sc_service::NetworkStatus; use std::{convert::{TryFrom, TryInto}, fmt, time}; -use prometheus_endpoint::{create_gauge, Gauge}; +use prometheus_endpoint::{create_gauge, Gauge, U64}; prometheus_endpoint::lazy_static! { - pub static ref SYNC_TARGET: Gauge = create_gauge( + pub static ref SYNC_TARGET: Gauge = create_gauge( "sync_target_number", "block sync target number" ); @@ -74,7 +74,7 @@ impl InformantDisplay { (SyncState::Idle, _) => ("Idle".into(), "".into()), (SyncState::Downloading, None) => (format!("Syncing{}", speed), "".into()), (SyncState::Downloading, Some(n)) => { - SYNC_TARGET.set(n.unique_saturated_into() as i64); + SYNC_TARGET.set(n.unique_saturated_into() as u64); (format!("Syncing{}", speed), format!(", target=#{}", n)) } }; diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 3a447cd06f877..9f17ad4a1ce28 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -54,46 +54,38 @@ use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; use sp_transaction_pool::{TransactionPool, TransactionPoolMaintainer}; use sp_blockchain; -use prometheus_endpoint::{create_gauge, Gauge}; +use prometheus_endpoint::{create_gauge, Gauge, U64, F64}; prometheus_endpoint::lazy_static! { - pub static ref FINALITY_HEIGHT: Gauge = create_gauge( + pub static ref FINALITY_HEIGHT: Gauge = create_gauge( "consensus_finality_block_height_number", "block is finality HEIGHT" ); - pub static ref BEST_HEIGHT: Gauge = create_gauge( + pub static ref BEST_HEIGHT: Gauge = create_gauge( "consensus_best_block_height_number", "block is best HEIGHT" ); - pub static ref BLOCK_INTERVAL_SECONDS: Gauge = create_gauge( - "consensus_block_interval_seconds", - "Time between this and last block(Block.Header.Time) in seconds" - ); - pub static ref P2P_PEERS_NUM: Gauge = create_gauge( + pub static ref P2P_PEERS_NUM: Gauge = create_gauge( "p2p_peers_number", "network gosip peers number" ); - pub static ref TX_COUNT: Gauge = create_gauge( + pub static ref TX_COUNT: Gauge = create_gauge( "consensus_num_txs", "Number of transactions" ); - pub static ref NODE_MEMORY: Gauge = create_gauge( + pub static ref NODE_MEMORY: Gauge = create_gauge( "consensus_node_memory", "node memory" ); - pub static ref NODE_CPU: Gauge = create_gauge( + pub static ref NODE_CPU: Gauge = create_gauge( "consensus_node_cpu", "node cpu" ); - pub static ref STATE_CACHE_SIZE: Gauge = create_gauge( - "consensus_state_cache_size", - "used state cache size" - ); - pub static ref P2P_NODE_DOWNLOAD: Gauge = create_gauge( + pub static ref P2P_NODE_DOWNLOAD: Gauge = create_gauge( "p2p_peers_receive_byte_per_sec", "p2p_node_download_per_sec_byte" ); - pub static ref P2P_NODE_UPLOAD: Gauge = create_gauge( + pub static ref P2P_NODE_UPLOAD: Gauge = create_gauge( "p2p_peers_send_byte_per_sec", "p2p_node_upload_per_sec_byte" ); @@ -996,14 +988,14 @@ ServiceBuilder< "bandwidth_upload" => bandwidth_upload, "used_state_cache_size" => used_state_cache_size, ); - NODE_MEMORY.set(memory as i64); - NODE_CPU.set(cpu_usage as i64); - TX_COUNT.set(txpool_status.ready as i64); - FINALITY_HEIGHT.set(finalized_number as i64); - BEST_HEIGHT.set(best_number as i64); - P2P_PEERS_NUM.set(num_peers as i64); - P2P_NODE_DOWNLOAD.set(net_status.average_download_per_sec as i64); - P2P_NODE_UPLOAD.set(net_status.average_upload_per_sec as i64); + NODE_MEMORY.set(memory); + NODE_CPU.set(f64::from(cpu_usage)); + TX_COUNT.set(txpool_status.ready as u64); + FINALITY_HEIGHT.set(finalized_number); + BEST_HEIGHT.set(best_number); + P2P_PEERS_NUM.set(num_peers as u64); + P2P_NODE_DOWNLOAD.set(net_status.average_download_per_sec); + P2P_NODE_UPLOAD.set(net_status.average_upload_per_sec); Ok(()) }).select(exit.clone().map(Ok).compat()).then(|_| Ok(())); let _ = to_spawn_tx.unbounded_send(Box::new(tel_task)); diff --git a/utils/prometheus/Cargo.toml b/utils/prometheus/Cargo.toml index 3f3b4bf408df0..a4bf0aa52273e 100644 --- a/utils/prometheus/Cargo.toml +++ b/utils/prometheus/Cargo.toml @@ -13,7 +13,6 @@ prometheus = { version = "0.7", features = ["nightly", "process"]} tokio = "0.2" futures-util = { version = "0.3.1", default-features = false, features = ["io"] } lazy_static = "1.4" -sp-runtime = { package = "sp-runtime",path = "../../primitives/runtime" } derive_more = "0.99" [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/utils/prometheus/src/lib.rs b/utils/prometheus/src/lib.rs index 6883fae48fae1..802a2b53b7fa5 100644 --- a/utils/prometheus/src/lib.rs +++ b/utils/prometheus/src/lib.rs @@ -14,24 +14,22 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . - -#[macro_use] extern crate lazy_static; -use futures_util::{FutureExt,future::{Future}}; + +use futures_util::{FutureExt, future::Future}; use hyper::http::StatusCode; -use hyper::Server; -use hyper::{Body, Request, Response, service::{service_fn, make_service_fn}}; -pub use prometheus::{Encoder, HistogramOpts, Opts, TextEncoder}; -pub use prometheus::{Histogram, IntCounter}; -pub use prometheus::IntGauge as Gauge; -pub use sp_runtime::traits::SaturatedConversion; +use hyper::{Server, Body, Request, Response, service::{service_fn, make_service_fn}}; +use prometheus::{Encoder, Opts, TextEncoder, core::Atomic}; use std::net::SocketAddr; #[cfg(not(target_os = "unknown"))] mod networking; +pub use prometheus::core::{ + GenericGauge as Gauge, AtomicF64 as F64, AtomicI64 as I64, AtomicU64 as U64 +}; pub use lazy_static::lazy_static; -pub fn create_gauge(name: &str, description: &str) -> Gauge { +pub fn create_gauge(name: &str, description: &str) -> Gauge { let opts = Opts::new(name, description); let gauge = Gauge::with_opts(opts).expect("Creating Gauge Failed"); prometheus::register(Box::new(gauge.clone())).expect("Registering gauge failed"); @@ -58,22 +56,16 @@ impl std::error::Error for Error { } async fn request_metrics(req: Request) -> Result, Error> { - if req.uri().path() == "/metrics" { - let metric_families = prometheus::gather(); - let mut buffer = vec![]; - let encoder = TextEncoder::new(); - encoder.encode(&metric_families, &mut buffer).unwrap(); - Response::builder() - .status(StatusCode::OK) - .header("Content-Type", encoder.format_type()) - .body(Body::from(buffer)) - .map_err(Error::Http) - } else { - Response::builder() - .status(StatusCode::NOT_FOUND) - .body(Body::from("Not found.")) - .map_err(Error::Http) - } + let metric_families = prometheus::gather(); + let mut buffer = vec![]; + let encoder = TextEncoder::new(); + encoder.encode(&metric_families, &mut buffer).unwrap(); + + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", encoder.format_type()) + .body(Body::from(buffer)) + .map_err(Error::Http) } #[derive(Clone)] From 70c6bccf6d704a60d99c3504f9d406ea3604b148 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 10 Jan 2020 12:35:54 +0100 Subject: [PATCH 4/5] Add photo back --- primitives/consensus/babe/src/inherents.rs | 70 +-- utils/prometheus/README.md | 424 ------------------ .../prometheus/photo_2019-12-13_16-32-53.jpg | Bin 0 -> 27726 bytes 3 files changed, 35 insertions(+), 459 deletions(-) create mode 100644 utils/prometheus/photo_2019-12-13_16-32-53.jpg diff --git a/primitives/consensus/babe/src/inherents.rs b/primitives/consensus/babe/src/inherents.rs index 4fe71dbb8a7c4..5a4e042352dcb 100644 --- a/primitives/consensus/babe/src/inherents.rs +++ b/primitives/consensus/babe/src/inherents.rs @@ -32,59 +32,59 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"babeslot"; pub type InherentType = u64; /// Auxiliary trait to extract BABE inherent data. pub trait BabeInherentData { - /// Get BABE inherent data. - fn babe_inherent_data(&self) -> Result; - /// Replace BABE inherent data. - fn babe_replace_inherent_data(&mut self, new: InherentType); + /// Get BABE inherent data. + fn babe_inherent_data(&self) -> Result; + /// Replace BABE inherent data. + fn babe_replace_inherent_data(&mut self, new: InherentType); } impl BabeInherentData for InherentData { - fn babe_inherent_data(&self) -> Result { - self.get_data(&INHERENT_IDENTIFIER) - .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) - } + fn babe_inherent_data(&self) -> Result { + self.get_data(&INHERENT_IDENTIFIER) + .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) + } - fn babe_replace_inherent_data(&mut self, new: InherentType) { - self.replace_data(INHERENT_IDENTIFIER, &new); - } + fn babe_replace_inherent_data(&mut self, new: InherentType) { + self.replace_data(INHERENT_IDENTIFIER, &new); + } } /// Provides the slot duration inherent data for BABE. #[cfg(feature = "std")] pub struct InherentDataProvider { - slot_duration: u64, + slot_duration: u64, } #[cfg(feature = "std")] impl InherentDataProvider { - /// Constructs `Self` - pub fn new(slot_duration: u64) -> Self { - Self { slot_duration } - } + /// Constructs `Self` + pub fn new(slot_duration: u64) -> Self { + Self { slot_duration } + } } #[cfg(feature = "std")] impl ProvideInherentData for InherentDataProvider { - fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { - if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { - // Add the timestamp inherent data provider, as we require it. - providers.register_provider(sp_timestamp::InherentDataProvider) - } else { - Ok(()) - } - } + fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { + if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { + // Add the timestamp inherent data provider, as we require it. + providers.register_provider(sp_timestamp::InherentDataProvider) + } else { + Ok(()) + } + } - fn inherent_identifier(&self) -> &'static InherentIdentifier { - &INHERENT_IDENTIFIER - } + fn inherent_identifier(&self) -> &'static InherentIdentifier { + &INHERENT_IDENTIFIER + } - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { - let timestamp = inherent_data.timestamp_inherent_data()?; - let slot_number = timestamp / self.slot_duration; - inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) - } + fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { + let timestamp = inherent_data.timestamp_inherent_data()?; + let slot_number = timestamp / self.slot_duration; + inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) + } - fn error_to_string(&self, error: &[u8]) -> Option { - Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() - } + fn error_to_string(&self, error: &[u8]) -> Option { + Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() + } } diff --git a/utils/prometheus/README.md b/utils/prometheus/README.md index e5952f1e192c4..f38cb1c8c7a15 100644 --- a/utils/prometheus/README.md +++ b/utils/prometheus/README.md @@ -22,430 +22,6 @@ Start Prometheus Start Grafana - Install Grafana -## Substrate Dev hack -### Prometheus primer - -Here is the entry point of prometheus core module in Parity Substrate. - -In existing sources, refer to the Grafana source due to the issue of the wasm. - -utils/prometheus/src/lib.rs -```rust -#[macro_use] -extern crate lazy_static; -use futures_util::{FutureExt,future::{Future}}; -use hyper::http::StatusCode; -use hyper::Server; -use hyper::{Body, Request, Response, service::{service_fn, make_service_fn}}; -pub use prometheus::{Encoder, HistogramOpts, Opts, TextEncoder}; -pub use prometheus::{Histogram, IntCounter, IntGauge}; -pub use sp_runtime::traits::SaturatedConversion; -use std::net::SocketAddr; - -pub mod metrics; - -#[derive(Debug, derive_more::Display, derive_more::From)] -pub enum Error { - /// Hyper internal error. - Hyper(hyper::Error), - /// Http request error. - Http(hyper::http::Error), - /// i/o error. - Io(std::io::Error) -} -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Error::Hyper(error) => Some(error), - Error::Http(error) => Some(error), - Error::Io(error) => Some(error) - } - } -} - -async fn request_metrics(req: Request) -> Result, Error> { - if req.uri().path() == "/metrics" { - let metric_families = prometheus::gather(); - let mut buffer = vec![]; - let encoder = TextEncoder::new(); - encoder.encode(&metric_families, &mut buffer).unwrap(); - Response::builder() - .status(StatusCode::OK) - .header("Content-Type", encoder.format_type()) - .body(Body::from(buffer)) - .map_err(Error::Http) - } else { - Response::builder() - .status(StatusCode::NOT_FOUND) - .body(Body::from("Not found.")) - .map_err(Error::Http) - } - -} - -#[derive(Clone)] -pub struct Executor; - -#[cfg(not(target_os = "unknown"))] -impl hyper::rt::Executor for Executor - where - T: Future + Send + 'static, - T::Output: Send + 'static, -{ - fn execute(&self, future: T) { - async_std::task::spawn(future); - } -} -/// Initializes the metrics context, and starts an HTTP server -/// to serve metrics. -#[cfg(not(target_os = "unknown"))] -pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Error>{ - use async_std::{net, io}; - use grafana_data_source::networking::Incoming; - - let listener = loop { - let listener = net::TcpListener::bind(&prometheus_addr).await; - match listener { - Ok(listener) => { - log::info!("Prometheus server started at {}", prometheus_addr); - break listener - }, - Err(err) => match err.kind() { - io::ErrorKind::AddrInUse | io::ErrorKind::PermissionDenied if prometheus_addr.port() != 0 => { - log::warn!( - "Prometheus server to already {} port.", prometheus_addr.port() - ); - prometheus_addr.set_port(0); - continue; - }, - _ => return Err(err.into()) - } - } - }; - let service = make_service_fn(|_| { - async { - Ok::<_, Error>(service_fn(request_metrics)) - } - }); - - - let _server = Server::builder(Incoming(listener.incoming())) - .executor(Executor) - .serve(service) - .boxed(); - - - let result = _server.await.map_err(Into::into); - - result -} - -#[cfg(target_os = "unknown")] -pub async fn init_prometheus(_: SocketAddr) -> Result<(), Error> { - Ok(()) -} - - -#[macro_export] -macro_rules! prometheus_gauge( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_gauge(&$metric, $value); - )* - } -); - -#[macro_export] -macro_rules! prometheus_histogram( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_histogram(&$metric, $value); - )* - } -); - - -``` - - - -Here is the dependancies of the module. -utils/prometheus/Cargo.toml -```toml -[package] -name = "sc-prometheus" -version = "2.0.0" -authors = ["Parity Technologies "] -description = "prometheus utils" -edition = "2018" - -[dependencies] -hyper = { version = "0.13.1", default-features = false, features = ["stream"] } -lazy_static = "1.4" -log = "0.4.8" -prometheus = { version = "0.7", features = ["nightly", "process"]} -tokio = "0.2" -futures-util = { version = "0.3.1", default-features = false, features = ["io"] } -sp-runtime = { package = "sp-runtime",path = "../../primitives/runtime" } -derive_more = "0.99" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] -async-std = { version = "1.0.1", features = ["unstable"] } -``` - -**Abbreviation of the package in service manager of parity substrate** -client/service/Cargo.toml -```toml -[dependencies] -sc-prometheus = { package = "sc-prometheus", path="../../utils/prometheus"} -``` - -**Metrics builder as same as substrate-telemetry** -client/service/src/builder.rsL1271 , L1112 -```rust -use sc_prometheus::prometheus_gauge; -... - telemetry!( - SUBSTRATE_INFO; - "system.interval"; - "peers" => num_peers, - "height" => best_number, - "best" => ?best_hash, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "finalized_hash" => ?info.chain.finalized_hash, - "bandwidth_download" => bandwidth_download, - "bandwidth_upload" => bandwidth_upload, - "used_state_cache_size" => used_state_cache_size, - ); - prometheus_gauge!( - STATE_CACHE_SIZE => used_state_cache_size as u64, - NODE_MEMORY => memory as u64, - NODE_CPU => cpu_usage as u64, - TX_COUNT => txpool_status.ready as u64, - FINALITY_HEIGHT => finalized_number as u64, - BEST_HEIGHT => best_number as u64, - P2P_PEERS_NUM => num_peers as u64, - P2P_NODE_DOWNLOAD => net_status.average_download_per_sec as u64, - P2P_NODE_UPLOAD => net_status.average_upload_per_sec as u64 - ); - let _ = record_metrics!( - "peers" => num_peers, - "height" => best_number, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "bandwidth_download" => bandwidth_download, - "bandwidth_upload" => bandwidth_upload, - "used_state_cache_size" => used_state_cache_size, - ); - Ok(()) - }).select(exit.clone().map(Ok).compat()).then(|_| Ok(())); - let _ = to_spawn_tx.unbounded_send(Box::new(tel_task)); - -... - // prometheus init - if let Some(port) = config.prometheus_port { - let future = select( - sc_prometheus::init_prometheus(port).boxed() - ,exit.clone() - ).map(|either| match either { - Either::Left((result, _)) => result.map_err(|_| ()), - Either::Right(_) => Ok(()) - }).compat(); - let _ = to_spawn_tx.unbounded_send(Box::new(future)); - } - // Grafana data source - if let Some(port) = config.grafana_port { - let future = select( - grafana_data_source::run_server(port).boxed(), - exit.clone() - ).map(|either| match either { - Either::Left((result, _)) => result.map_err(|_| ()), - Either::Right(_) => Ok(()) - }).compat(); - - let _ = to_spawn_tx.unbounded_send(Box::new(future)); - } - - // Instrumentation - if let Some(tracing_targets) = config.tracing_targets.as_ref() { - let subscriber = sc_tracing::ProfilingSubscriber::new( - config.tracing_receiver, tracing_targets - ); - match tracing::subscriber::set_global_default(subscriber) { - Ok(_) => (), - Err(e) => error!(target: "tracing", "Unable to set global default subscriber {}", e), - } - } - - -``` -substrate/Cargo.toml -```toml -[workspace] -members = [ - "utils/prometheus", -``` -### CLI Config -client/cli/src/lib.rs -```rust -fn crate_run_node_config{ -... - let prometheus_interface: &str = if cli.prometheus_external { "0.0.0.0" } -... - // Override prometheus - if cli.prometheus_external { - config.prometheus_port = Some( - parse_address(&format!("{}:{}", prometheus_interface, 33333), cli.prometheus_port)? - )} -} -``` - -client/cli/src/params.rs -```rust -pub struct RunCmd{ -... - /// Prometheus exporter TCP port. - #[structopt(long = "prometheus-port", value_name = "PORT")] - pub prometheus_port: Option, - /// Prometheus exporter on/off external". - #[structopt(long = "prometheus-external")] - pub prometheus_external: bool, -... -} -``` -client/service/src/config.rs -```rust -#[derive(Clone)] -pub struct Configuration { - ... - /// Prometheus Port.`None` if disabled and port 33333 by default. - pub prometheus_port: Option, - ... -} -impl Configuration where - C: Default, - G: RuntimeGenesis, - E: Extension, -{ - /// Create default config for given chain spec. - pub fn default_with_spec(chain_spec: ChainSpec) -> Self { - let mut configuration = Configuration { - ... - prometheus_prot: None, - ... - }; - configuration.network.boot_nodes = configuration.chain_spec.boot_nodes().to_vec(); - - configuration.telemetry_endpoints = configuration.chain_spec.telemetry_endpoints().clone(); - - configuration - } -``` - - - -### Metrics Add -ex) consensus_FINALITY_HEIGHT - -utils/prometheus/src/metrics.rs - -```rust -pub use crate::*; - -/// Gauge type metrics generation function -pub fn try_create_int_gauge(name: &str, help: &str) -> Result { - let opts = Opts::new(name, help); - let gauge = IntGauge::with_opts(opts)?; - prometheus::register(Box::new(gauge.clone()))?; - Ok(gauge) -} - -///Gauge Metrics a value in injection. -pub fn set_gauge(gauge: &Result, value: u64) { - if let Ok(gauge) = gauge { - gauge.set(value as i64); - } -} - -///All of the metrics in the prometheus are managed by the lazy_static. -lazy_static! { - pub static ref FINALITY_HEIGHT: Result = try_create_int_gauge( - "consensus_finality_block_height_number", - "block is finality HEIGHT" - ); -} -``` -client/service/Cargo.toml -```rust -... -sc-prometheus = { package = "sc-prometheus", path="../../utils/prometheus"} -... -``` -client/service/src/builder.rs -```rust -..... -use sc-prometheus::{prometheus_gauge}; -..... - let tel_task = state_rx.for_each(move |(net_status, _)| { - let info = client_.info(); - let best_number = info.chain.best_number.saturated_into::(); - let best_hash = info.chain.best_hash; - let num_peers = net_status.num_connected_peers; - let txpool_status = transaction_pool_.status(); - let finalized_number: u64 = info.chain.finalized_number.saturated_into::(); - let bandwidth_download = net_status.average_download_per_sec; - let bandwidth_upload = net_status.average_upload_per_sec; - - let used_state_cache_size = match info.used_state_cache_size { - Some(size) => size, - None => 0, - }; - - // get cpu usage and memory usage of this process - let (cpu_usage, memory) = if let Some(self_pid) = self_pid { - if sys.refresh_process(self_pid) { - let proc = sys.get_process(self_pid) - .expect("Above refresh_process succeeds, this should be Some(), qed"); - (proc.cpu_usage(), proc.memory()) - } else { (0.0, 0) } - } else { (0.0, 0) }; - - telemetry!( - SUBSTRATE_INFO; - "system.interval"; - "peers" => num_peers, - "height" => best_number, - "best" => ?best_hash, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "finalized_hash" => ?info.chain.finalized_hash, - "bandwidth_download" => bandwidth_download, - "bandwidth_upload" => bandwidth_upload, - "used_state_cache_size" => used_state_cache_size, - ); - - prometheus_gauge!( - STATE_CACHE_SIZE => used_state_cache_size as u64, - NODE_MEMORY => memory as u64, - NODE_CPU => cpu_usage as u64, - TX_COUNT => txpool_status.ready as u64, - FINALITY_HEIGHT => finalized_number as u64, - BEST_HEIGHT => best_number as u64, - P2P_PEERS_NUM => num_peers as u64, - P2P_NODE_DOWNLOAD => net_status.average_download_per_sec as u64, - P2P_NODE_UPLOAD => net_status.average_upload_per_sec as u64 - ); -..... -``` ## Metrics substrate can report and serve the Prometheus metrics, which in their turn can be consumed by Prometheus collector(s). diff --git a/utils/prometheus/photo_2019-12-13_16-32-53.jpg b/utils/prometheus/photo_2019-12-13_16-32-53.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cdf44f88fb623d7b5a319235c6d603463698716c GIT binary patch literal 27726 zcmeFZcT`m0wkEoDJ3nV{7^+zOM;&BO;@slT%XD z(lg$@&-|44IsZ#R;n$*y%Bt$`HMMp1ZS5VMUEMvsKZi#~$Hpfnr>2*dS60{7H#WDn z(T7LJC#PqaKj(k5ivVxuzaIZ$*gx4tgSYD%At8tm{5QJ@u6g4Jh=!2p=6zyXrKjMR zu5`CVf=TEfBz-LZLCPii48>sSHblnAEw;pi{+nrkx9mS=Sjhh;%l?O9|7O=TKmj7a z-#icv00qv@`91}a{WbntgTFBF7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h!up1(At+kaFO^=KyT&{a>MXi>v?u literal 0 HcmV?d00001 From 594104112db197bca7b7238fead498f49f430aab Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 10 Jan 2020 12:43:47 +0100 Subject: [PATCH 5/5] Re-fix spaces in primitives/consensus/babe/src/inherents.rs --- primitives/consensus/babe/src/inherents.rs | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/primitives/consensus/babe/src/inherents.rs b/primitives/consensus/babe/src/inherents.rs index 5a4e042352dcb..4fe71dbb8a7c4 100644 --- a/primitives/consensus/babe/src/inherents.rs +++ b/primitives/consensus/babe/src/inherents.rs @@ -32,59 +32,59 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"babeslot"; pub type InherentType = u64; /// Auxiliary trait to extract BABE inherent data. pub trait BabeInherentData { - /// Get BABE inherent data. - fn babe_inherent_data(&self) -> Result; - /// Replace BABE inherent data. - fn babe_replace_inherent_data(&mut self, new: InherentType); + /// Get BABE inherent data. + fn babe_inherent_data(&self) -> Result; + /// Replace BABE inherent data. + fn babe_replace_inherent_data(&mut self, new: InherentType); } impl BabeInherentData for InherentData { - fn babe_inherent_data(&self) -> Result { - self.get_data(&INHERENT_IDENTIFIER) - .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) - } + fn babe_inherent_data(&self) -> Result { + self.get_data(&INHERENT_IDENTIFIER) + .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) + } - fn babe_replace_inherent_data(&mut self, new: InherentType) { - self.replace_data(INHERENT_IDENTIFIER, &new); - } + fn babe_replace_inherent_data(&mut self, new: InherentType) { + self.replace_data(INHERENT_IDENTIFIER, &new); + } } /// Provides the slot duration inherent data for BABE. #[cfg(feature = "std")] pub struct InherentDataProvider { - slot_duration: u64, + slot_duration: u64, } #[cfg(feature = "std")] impl InherentDataProvider { - /// Constructs `Self` - pub fn new(slot_duration: u64) -> Self { - Self { slot_duration } - } + /// Constructs `Self` + pub fn new(slot_duration: u64) -> Self { + Self { slot_duration } + } } #[cfg(feature = "std")] impl ProvideInherentData for InherentDataProvider { - fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { - if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { - // Add the timestamp inherent data provider, as we require it. - providers.register_provider(sp_timestamp::InherentDataProvider) - } else { - Ok(()) - } - } + fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { + if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { + // Add the timestamp inherent data provider, as we require it. + providers.register_provider(sp_timestamp::InherentDataProvider) + } else { + Ok(()) + } + } - fn inherent_identifier(&self) -> &'static InherentIdentifier { - &INHERENT_IDENTIFIER - } + fn inherent_identifier(&self) -> &'static InherentIdentifier { + &INHERENT_IDENTIFIER + } - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { - let timestamp = inherent_data.timestamp_inherent_data()?; - let slot_number = timestamp / self.slot_duration; - inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) - } + fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { + let timestamp = inherent_data.timestamp_inherent_data()?; + let slot_number = timestamp / self.slot_duration; + inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) + } - fn error_to_string(&self, error: &[u8]) -> Option { - Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() - } + fn error_to_string(&self, error: &[u8]) -> Option { + Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() + } }