Add support for wasm runtime metrics try #2 (#4483)

* Add runtime metrics provider

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Runner changes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Some sample metrics in paras_inherent

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* update cargo toml

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* bug

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* more fmt after merge

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Refactor metric prefix override

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* remove bug comment

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Add runtime metric primitives

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Impl trace event parsing

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Update metrics

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* cargo lock

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Fix target check

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Runtime metrics primitives

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Review feedback

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Runtime metrics crate

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Node side runtime metric changes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* use runtime CounterVec instead of macro

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt nice

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* remove dead code

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* base58 decoding

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* base58 encoding

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fix warn

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* typo

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Review feedback

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Finish label support

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* please compile

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* add feature gate

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Comment cargo toml

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Fix cargo toml description

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Update doc.

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* switch to `runtime-metrics` feature

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* cargo toml

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fix tests

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fixes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* better ux

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* from_utf8_unchecked is safe

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fmt

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Add Counter and refactor

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Fixes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* review fixes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* more fixes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* add integration test

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* dev deps

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* gitlab script update

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* review fixes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* fix merge damage

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Run tests twice

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* small fix

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* typo

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* cargo lock

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* tests

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* spellcheck happy ?

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* more fixes

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* Guard tracing init

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* missing copyright

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* update lockfile for substrate

Co-authored-by: parity-processbot <>
This commit is contained in:
sandreim
2021-12-16 13:56:25 +02:00
committed by GitHub
parent 6f2f9fe381
commit e75ad88ae8
23 changed files with 1014 additions and 185 deletions
+4
View File
@@ -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, 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 }
@@ -42,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"
@@ -82,6 +84,7 @@ std = [
"xcm/std",
"xcm-executor/std",
"log/std",
"polkadot-runtime-metrics/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
@@ -98,3 +101,4 @@ try-runtime = [
"pallet-timestamp/try-runtime",
"pallet-vesting/try-runtime",
]
runtime-metrics = ["sp-tracing/with-tracing", "polkadot-runtime-metrics/runtime-metrics"]
@@ -55,6 +55,7 @@ use sp_std::{
vec::Vec,
};
use polkadot_runtime_metrics::{Counter, CounterVec};
mod misc;
mod weights;
@@ -260,13 +261,41 @@ impl<T: Config> Pallet<T> {
parent_header,
mut disputes,
} = data;
#[cfg(feature = "runtime-metrics")]
sp_io::init_tracing();
let parent_header_hash = parent_header.hash();
let mut weight_metric = CounterVec::new(
"parachain_inherent_data_weight",
"Inherent data weight before and after filtering",
&["when"],
);
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(
"parachain_inherent_data_candidates_processed",
"Counts the number of parachain block candidates processed in `enter_inner`.",
&["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`.",
&["category"],
);
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,
"[enter_inner] parent_header={:?} bitfields.len(): {}, backed_candidates.len(): {}, disputes.len(): {}",
parent_header_hash,
parent_header.hash(),
signed_bitfields.len(),
backed_candidates.len(),
disputes.len()
@@ -275,7 +304,7 @@ impl<T: Config> Pallet<T> {
// Check that the submitted parent header indeed corresponds to the previous block hash.
let parent_hash = <frame_system::Pallet<T>>::parent_hash();
ensure!(
parent_header_hash.as_ref() == parent_hash.as_ref(),
parent_header.hash().as_ref() == parent_hash.as_ref(),
Error::<T>::InvalidParentHeader,
);
@@ -287,6 +316,10 @@ impl<T: Config> Pallet<T> {
let max_block_weight = <T as frame_system::Config>::BlockWeights::get().max_block;
weight_metric
.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
let total_weight = {
if candidate_weight
@@ -333,11 +366,23 @@ impl<T: Config> Pallet<T> {
// 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(&["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(&["frozen"]).inc();
// The relay chain we are currently on is invalid. Proceed no further on parachains.
return Ok(Some(dispute_statements_weight::<T>(&disputes)).into())
}
// Process the dispute sets of the current session.
dispute_sets_processed_metric
.with_label_values(&["current"])
.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()
@@ -347,11 +392,17 @@ impl<T: Config> Pallet<T> {
.map(|(_, candidate)| *candidate)
.collect::<BTreeSet<CandidateHash>>();
let freed_disputed =
// Count invalid dispute sets.
dispute_sets_processed_metric
.with_label_values(&["concluded_invalid"])
.inc_by(concluded_invalid_disputes.len() as u64);
let freed_disputed: Vec<_> =
<inclusion::Pallet<T>>::collect_disputed(&concluded_invalid_disputes)
.into_iter()
.map(|core| (core, FreedReason::Concluded))
.collect();
freed_disputed
} else {
Vec::new()
@@ -374,6 +425,7 @@ impl<T: Config> Pallet<T> {
disputed_bitfield
};
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 = <inclusion::Pallet<T>>::process_bitfields(
@@ -388,11 +440,17 @@ impl<T: Config> Pallet<T> {
T::DisputesHandler::note_included(current_session, *candidate_hash, now);
}
candidates_processed_metric
.with_label_values(&["included"])
.inc_by(freed_concluded.len() as u64);
let freed = collect_all_freed_cores::<T, _>(freed_concluded.iter().cloned());
<scheduler::Pallet<T>>::clear();
<scheduler::Pallet<T>>::schedule(freed, now);
candidates_processed_metric
.with_label_values(&["total"])
.inc_by(backed_candidates.len() as u64);
let scheduled = <scheduler::Pallet<T>>::scheduled();
let backed_candidates = sanitize_backed_candidates::<T, _>(
parent_hash,
@@ -403,6 +461,9 @@ impl<T: Config> Pallet<T> {
},
&scheduled[..],
);
candidates_processed_metric
.with_label_values(&["sanitized"])
.inc_by(backed_candidates.len() as u64);
// Process backed candidates according to scheduled cores.
let parent_storage_root = parent_header.state_root().clone();
@@ -417,6 +478,8 @@ impl<T: Config> Pallet<T> {
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::<T>::put(ScrapedOnChainVotes::<<T::Header as HeaderT>::Hash> {
@@ -432,6 +495,8 @@ impl<T: Config> Pallet<T> {
// this is max config.ump_service_total_weight
let _ump_weight = <ump::Pallet<T>>::process_pending_upward_messages();
weight_metric.with_label_values(&vec!["after-filter"]).inc_by(total_weight);
Ok(Some(total_weight).into())
}
}
@@ -800,6 +865,12 @@ pub(crate) fn sanitize_bitfields<T: crate::inclusion::Config>(
validators: &[ValidatorId],
full_check: FullCheck,
) -> UncheckedSignedAvailabilityBitfields {
let mut bitfields_signature_checks_metric = CounterVec::new(
"create_inherent_bitfields_signature_checks",
"Counts the number of bitfields signature checked in `enter_inner`.",
&["validity"],
);
let mut bitfields = Vec::with_capacity(unchecked_bitfields.len());
let mut last_index: Option<ValidatorIndex> = None;
@@ -865,12 +936,15 @@ pub(crate) fn sanitize_bitfields<T: crate::inclusion::Config>(
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(&["valid"]).inc();
} else {
log::warn!(target: LOG_TARGET, "Invalid bitfield signature");
bitfields_signature_checks_metric.with_label_values(&["invalid"]).inc();
};
} else {
bitfields.push(unchecked_bitfield);