Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Meter block import results via prometheus (#6025)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunicorn authored May 15, 2020
1 parent 61a7248 commit 3f71d1e
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ macro_rules! new_full_start {
let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());
Ok(sc_transaction_pool::BasicPool::new(config, std::sync::Arc::new(pool_api), prometheus_registry))
})?
.with_import_queue(|_config, client, mut select_chain, _transaction_pool, spawn_task_handle| {
.with_import_queue(|
_config,
client,
mut select_chain,
_transaction_pool,
spawn_task_handle,
registry,
| {
let select_chain = select_chain.take()
.ok_or_else(|| sc_service::Error::SelectChainRequired)?;

Expand All @@ -65,6 +72,7 @@ macro_rules! new_full_start {
client,
inherent_data_providers.clone(),
spawn_task_handle,
registry,
)?;

import_setup = Some((grandpa_block_import, grandpa_link));
Expand Down Expand Up @@ -198,7 +206,16 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
);
Ok(pool)
})?
.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool, spawn_task_handle| {
.with_import_queue_and_fprb(|
_config,
client,
backend,
fetcher,
_select_chain,
_tx_pool,
spawn_task_handle,
prometheus_registry,
| {
let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
Expand All @@ -220,6 +237,7 @@ pub fn new_light(config: Configuration) -> Result<impl AbstractService, ServiceE
client,
inherent_data_providers.clone(),
spawn_task_handle,
prometheus_registry,
)?;

Ok((import_queue, finality_proof_request_builder))
Expand Down
22 changes: 20 additions & 2 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ macro_rules! new_full_start {
prometheus_registry,
))
})?
.with_import_queue(|_config, client, mut select_chain, _transaction_pool, spawn_task_handle| {
.with_import_queue(|
_config,
client,
mut select_chain,
_transaction_pool,
spawn_task_handle,
prometheus_registry,
| {
let select_chain = select_chain.take()
.ok_or_else(|| sc_service::Error::SelectChainRequired)?;
let (grandpa_block_import, grandpa_link) = grandpa::block_import(
Expand All @@ -86,6 +93,7 @@ macro_rules! new_full_start {
client,
inherent_data_providers.clone(),
spawn_task_handle,
prometheus_registry,
)?;

import_setup = Some((block_import, grandpa_link, babe_link));
Expand Down Expand Up @@ -309,7 +317,16 @@ pub fn new_light(config: Configuration)
);
Ok(pool)
})?
.with_import_queue_and_fprb(|_config, client, backend, fetcher, _select_chain, _tx_pool, spawn_task_handle| {
.with_import_queue_and_fprb(|
_config,
client,
backend,
fetcher,
_select_chain,
_tx_pool,
spawn_task_handle,
registry,
| {
let fetch_checker = fetcher
.map(|fetcher| fetcher.checker().clone())
.ok_or_else(|| "Trying to start light import queue without active fetch checker")?;
Expand Down Expand Up @@ -338,6 +355,7 @@ pub fn new_light(config: Configuration)
client.clone(),
inherent_data_providers.clone(),
spawn_task_handle,
registry,
)?;

Ok((import_queue, finality_proof_request_builder))
Expand Down
1 change: 1 addition & 0 deletions client/consensus/aura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ sp-api = { version = "2.0.0-dev", path = "../../../primitives/api" }
sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" }
sp-timestamp = { version = "2.0.0-dev", path = "../../../primitives/timestamp" }
sc-telemetry = { version = "2.0.0-dev", path = "../../telemetry" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-dev"}

[dev-dependencies]
sp-keyring = { version = "2.0.0-dev", path = "../../../primitives/keyring" }
Expand Down
3 changes: 3 additions & 0 deletions client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use std::{
use futures::prelude::*;
use parking_lot::Mutex;
use log::{debug, info, trace};
use prometheus_endpoint::Registry;

use codec::{Encode, Decode, Codec};

Expand Down Expand Up @@ -816,6 +817,7 @@ pub fn import_queue<B, I, C, P, S>(
client: Arc<C>,
inherent_data_providers: InherentDataProviders,
spawner: &S,
registry: Option<&Registry>,
) -> Result<AuraImportQueue<B, sp_api::TransactionFor<C, B>>, sp_consensus::Error> where
B: BlockT,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>> + ApiExt<B, Error = sp_blockchain::Error>,
Expand All @@ -842,6 +844,7 @@ pub fn import_queue<B, I, C, P, S>(
justification_import,
finality_proof_import,
spawner,
registry,
))
}

Expand Down
1 change: 1 addition & 0 deletions client/consensus/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sc-consensus-uncles = { version = "0.8.0-dev", path = "../uncles" }
sc-consensus-slots = { version = "0.8.0-dev", path = "../slots" }
sp-runtime = { version = "2.0.0-dev", path = "../../../primitives/runtime" }
fork-tree = { version = "2.0.0-dev", path = "../../../utils/fork-tree" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-dev"}
futures = "0.3.4"
futures-timer = "3.0.1"
parking_lot = "0.10.0"
Expand Down
3 changes: 3 additions & 0 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ use sp_block_builder::BlockBuilder as BlockBuilderApi;

use futures::prelude::*;
use log::{debug, info, log, trace, warn};
use prometheus_endpoint::Registry;
use sc_consensus_slots::{
SlotWorker, SlotInfo, SlotCompatible, StorageChanges, CheckedHeader, check_equivocation,
};
Expand Down Expand Up @@ -1291,6 +1292,7 @@ pub fn import_queue<Block: BlockT, Client, Inner>(
client: Arc<Client>,
inherent_data_providers: InherentDataProviders,
spawner: &impl sp_core::traits::SpawnBlocking,
registry: Option<&Registry>,
) -> ClientResult<BabeImportQueue<Block, sp_api::TransactionFor<Client, Block>>> where
Inner: BlockImport<Block, Error = ConsensusError, Transaction = sp_api::TransactionFor<Client, Block>>
+ Send + Sync + 'static,
Expand All @@ -1314,6 +1316,7 @@ pub fn import_queue<Block: BlockT, Client, Inner>(
justification_import,
finality_proof_import,
spawner,
registry,
))
}

Expand Down
23 changes: 12 additions & 11 deletions client/consensus/manual-seal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ parking_lot = "0.10.0"
serde = { version = "1.0", features=["derive"] }
assert_matches = "1.3.0"

sc-client-api = { path = "../../../client/api" , version = "2.0.0-dev"}
sc-transaction-pool = { path = "../../transaction-pool" , version = "2.0.0-dev"}
sp-blockchain = { path = "../../../primitives/blockchain" , version = "2.0.0-dev"}
sp-consensus = { package = "sp-consensus", path = "../../../primitives/consensus/common" , version = "0.8.0-dev"}
sp-inherents = { path = "../../../primitives/inherents" , version = "2.0.0-dev"}
sp-runtime = { path = "../../../primitives/runtime" , version = "2.0.0-dev"}
sp-core = { path = "../../../primitives/core" , version = "2.0.0-dev"}
sp-transaction-pool = { path = "../../../primitives/transaction-pool" , version = "2.0.0-dev"}
sc-client-api = { path = "../../../client/api", version = "2.0.0-dev" }
sc-transaction-pool = { path = "../../transaction-pool", version = "2.0.0-dev" }
sp-blockchain = { path = "../../../primitives/blockchain", version = "2.0.0-dev" }
sp-consensus = { package = "sp-consensus", path = "../../../primitives/consensus/common", version = "0.8.0-dev" }
sp-inherents = { path = "../../../primitives/inherents", version = "2.0.0-dev" }
sp-runtime = { path = "../../../primitives/runtime", version = "2.0.0-dev" }
sp-core = { path = "../../../primitives/core", version = "2.0.0-dev" }
sp-transaction-pool = { path = "../../../primitives/transaction-pool", version = "2.0.0-dev" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-dev" }

[dev-dependencies]
sc-basic-authorship = { path = "../../basic-authorship" , version = "0.8.0-dev"}
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client" , version = "2.0.0-dev"}
substrate-test-runtime-transaction-pool = { path = "../../../test-utils/runtime/transaction-pool" , version = "2.0.0-dev"}
sc-basic-authorship = { path = "../../basic-authorship", version = "0.8.0-dev" }
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client", version = "2.0.0-dev" }
substrate-test-runtime-transaction-pool = { path = "../../../test-utils/runtime/transaction-pool", version = "2.0.0-dev" }
tokio = { version = "0.2", features = ["rt-core", "macros"] }
env_logger = "0.7.0"
tempfile = "3.1.0"
3 changes: 3 additions & 0 deletions client/consensus/manual-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use sp_runtime::{traits::Block as BlockT, Justification};
use sc_client_api::backend::{Backend as ClientBackend, Finalizer};
use sc_transaction_pool::txpool;
use std::{sync::Arc, marker::PhantomData};
use prometheus_endpoint::Registry;

mod error;
mod finalize_block;
Expand Down Expand Up @@ -69,6 +70,7 @@ impl<B: BlockT> Verifier<B> for ManualSealVerifier {
pub fn import_queue<Block, Transaction>(
block_import: BoxBlockImport<Block, Transaction>,
spawner: &impl sp_core::traits::SpawnBlocking,
registry: Option<&Registry>,
) -> BasicQueue<Block, Transaction>
where
Block: BlockT,
Expand All @@ -80,6 +82,7 @@ pub fn import_queue<Block, Transaction>(
None,
None,
spawner,
registry,
)
}

Expand Down
1 change: 1 addition & 0 deletions client/consensus/pow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ log = "0.4.8"
futures = { version = "0.3.1", features = ["compat"] }
sp-timestamp = { version = "2.0.0-dev", path = "../../../primitives/timestamp" }
derive_more = "0.99.2"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-dev"}
3 changes: 3 additions & 0 deletions client/consensus/pow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use sp_consensus::import_queue::{
BoxBlockImport, BasicQueue, Verifier, BoxJustificationImport, BoxFinalityProofImport,
};
use codec::{Encode, Decode};
use prometheus_endpoint::Registry;
use sc_client_api;
use log::*;
use sp_timestamp::{InherentError as TIError, TimestampInherentData};
Expand Down Expand Up @@ -465,6 +466,7 @@ pub fn import_queue<B, Transaction, Algorithm>(
algorithm: Algorithm,
inherent_data_providers: InherentDataProviders,
spawner: &impl sp_core::traits::SpawnBlocking,
registry: Option<&Registry>,
) -> Result<
PowImportQueue<B, Transaction>,
sp_consensus::Error
Expand All @@ -483,6 +485,7 @@ pub fn import_queue<B, Transaction, Algorithm>(
justification_import,
finality_proof_import,
spawner,
registry,
))
}

Expand Down
1 change: 1 addition & 0 deletions client/network/src/service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn build_test_full_node(config: config::NetworkConfiguration)
None,
None,
&sp_core::testing::SpawnBlockingExecutor::new(),
None,
));

let worker = NetworkWorker::new(config::Params {
Expand Down
1 change: 1 addition & 0 deletions client/network/test/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn async_import_queue_drops() {
None,
None,
&executor,
None,
);
drop(queue);
}
Expand Down
2 changes: 2 additions & 0 deletions client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ pub trait TestNetFactory: Sized {
justification_import,
finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(),
None,
));

let listen_addr = build_multiaddr![Memory(rand::random::<u64>())];
Expand Down Expand Up @@ -691,6 +692,7 @@ pub trait TestNetFactory: Sized {
justification_import,
finality_proof_import,
&sp_core::testing::SpawnBlockingExecutor::new(),
None,
));

let listen_addr = build_multiaddr![Memory(rand::random::<u64>())];
Expand Down
10 changes: 7 additions & 3 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
/// Defines which import queue to use.
pub fn with_import_queue<UImpQu>(
self,
builder: impl FnOnce(&Configuration, Arc<TCl>, Option<TSc>, Arc<TExPool>, &SpawnTaskHandle)
builder: impl FnOnce(&Configuration, Arc<TCl>, Option<TSc>, Arc<TExPool>, &SpawnTaskHandle, Option<&Registry>)
-> Result<UImpQu, Error>
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, UImpQu, TFprb, TFpp,
TExPool, TRpc, Backend>, Error>
Expand All @@ -496,6 +496,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
self.select_chain.clone(),
self.transaction_pool.clone(),
&self.task_manager.spawn_handle(),
self.config.prometheus_config.as_ref().map(|config| &config.registry),
)?;

Ok(ServiceBuilder {
Expand Down Expand Up @@ -586,6 +587,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
Option<TSc>,
Arc<TExPool>,
&SpawnTaskHandle,
Option<&Registry>,
) -> Result<(UImpQu, Option<UFprb>), Error>
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, UImpQu, UFprb, TFpp,
TExPool, TRpc, Backend>, Error>
Expand All @@ -598,6 +600,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
self.select_chain.clone(),
self.transaction_pool.clone(),
&self.task_manager.spawn_handle(),
self.config.prometheus_config.as_ref().map(|config| &config.registry),
)?;

Ok(ServiceBuilder {
Expand Down Expand Up @@ -630,12 +633,13 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
Option<TSc>,
Arc<TExPool>,
&SpawnTaskHandle,
Option<&Registry>,
) -> Result<(UImpQu, UFprb), Error>
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, UImpQu, UFprb, TFpp,
TExPool, TRpc, Backend>, Error>
where TSc: Clone, TFchr: Clone {
self.with_import_queue_and_opt_fprb(|cfg, cl, b, f, sc, tx, tb|
builder(cfg, cl, b, f, sc, tx, tb)
self.with_import_queue_and_opt_fprb(|cfg, cl, b, f, sc, tx, tb, pr|
builder(cfg, cl, b, f, sc, tx, tb, pr)
.map(|(q, f)| (q, Some(f)))
)
}
Expand Down
1 change: 1 addition & 0 deletions primitives/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sp-utils = { version = "2.0.0-dev", path = "../../utils" }
codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] }
parking_lot = "0.10.0"
serde = { version = "1.0", features = ["derive"] }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-dev"}

[dev-dependencies]
sp-test-primitives = { version = "2.0.0-dev", path = "../../test-primitives" }
Expand Down
Loading

0 comments on commit 3f71d1e

Please sign in to comment.