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

Meter block import results via prometheus #6025

Merged
merged 17 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions client/service/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use sp_runtime::traits::{NumberFor, Block, SaturatedConversion, UniqueSaturatedI
use sp_transaction_pool::PoolStatus;
use sp_utils::metrics::register_globals;
use sc_client_api::ClientInfo;
use sp_consensus::metrics::IMPORT_QUEUE_PROCESSED;

use sysinfo::{self, ProcessExt, SystemExt};

Expand Down Expand Up @@ -77,6 +78,8 @@ impl PrometheusMetrics {

register_globals(registry)?;

registry.register(Box::new(IMPORT_QUEUE_PROCESSED.clone()))?;

Ok(Self {
// system
#[cfg(all(any(unix, windows), not(target_os = "android")))]
Expand Down
2 changes: 2 additions & 0 deletions primitives/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ 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"] }
lazy_static = "1.4.0"
prometheus = "0.8.0"

[dev-dependencies]
sp-test-primitives = { version = "2.0.0-dev", path = "../../test-primitives" }
Expand Down
12 changes: 12 additions & 0 deletions primitives/consensus/common/src/import_queue/basic_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use sp_runtime::{Justification, traits::{Block as BlockT, Header as HeaderT, Num
use sp_utils::mpsc::{TracingUnboundedSender, tracing_unbounded};

use crate::block_import::BlockOrigin;
use crate::metrics::IMPORT_QUEUE_PROCESSED;
use crate::import_queue::{
BlockImportResult, BlockImportError, Verifier, BoxBlockImport, BoxFinalityProofImport,
BoxJustificationImport, ImportQueue, Link, Origin,
Expand Down Expand Up @@ -391,6 +392,17 @@ fn import_many_blocks<B: BlockT, V: Verifier<B>, Transaction>(
)
};

IMPORT_QUEUE_PROCESSED.with_label_values(&[&match import_result {
Err(BlockImportError::IncompleteHeader(_)) => "incomplete_header",
Err(BlockImportError::VerificationFailed(_,_)) => "verification_failed",
Err(BlockImportError::BadBlock(_)) => "bad_block",
Err(BlockImportError::MissingState) => "missing_state",
Err(BlockImportError::UnknownParent) => "unknown_parent",
Err(BlockImportError::Cancelled) => "cancelled",
Err(BlockImportError::Other(_)) => "failed",
Ok(_) => "success",
}]).inc();

if import_result.is_ok() {
trace!(target: "sync", "Block imported successfully {:?} ({})", block_number, block_hash);
imported += 1;
Expand Down
1 change: 1 addition & 0 deletions primitives/consensus/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod block_import;
mod select_chain;
pub mod import_queue;
pub mod evaluation;
pub mod metrics;

// block size limit.
const MAX_BLOCK_SIZE: usize = 4 * 1024 * 1024 + 512;
Expand Down
41 changes: 41 additions & 0 deletions primitives/consensus/common/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 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 <http://www.gnu.org/licenses/>.

//! Metering tools for consensus
//!
//! These are the metrics measured by consensus internals. These are
//! exposed publicly for two reasons: if you choose to not reuse the
//! existing BasicImportQueue, you can still use the same single
//! measuring component –– but you also have to do that tracking yourself.
//!
//! Secondly, this only does the general tracking using Prometheus
//! Primitives, it **does not** actually register them with the prometheus
//! process or service. This is expected to be done from the outside.
//! If you are using sc-service, this is already done for you.

use lazy_static::lazy_static;
use prometheus::{
Opts,
core::{ AtomicU64, GenericCounterVec },
};

lazy_static! {
/// Blocks processed and their result
pub static ref IMPORT_QUEUE_PROCESSED : GenericCounterVec<AtomicU64> = GenericCounterVec::new(
Opts::new("import_queue_processed", "Blocks processed by import queue"),
&["result"] // 'success or failure
).expect("Creating of statics doesn't fail. qed");
}