Histogram support in runtime metrics (#6935)

* Histogram support in runtime metrics

Add support for histograms to the runtime metrics. Additionally add
`polkadot_parachain_verify_dispute_signature` histogram which tracks the
time needed from the runtime to verify a single validator signature of a
dispute statement.

* Add noops

* u64 instead of f64

* Update buckets

* Wrap `get_current_time()` in runtime metrics

* Change the dimension of the Histogram from usec to sec

* Fix a compilation error

* Update buckets

* Fix `on_signature_check_complete` calculation

* Update buckets

* Update buckets

* formatting

* Another weights update

* Adjust buckets again

* Final buckets adjustment

* Revert "Fix a compilation error"

This reverts commit 06290b40a39eeb78de2602d8916a39edf7a8b714.

* Update primitives/src/v4/metrics.rs

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>

* Use `saturating_sub` for time difference calculation

* Pass nanoseconds to client instead of seconds (using f64 in runtime is dangerous)

---------

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
This commit is contained in:
Tsvetomir Dimitrov
2023-03-28 16:37:19 +03:00
committed by GitHub
parent 4903859544
commit 22f404f092
9 changed files with 153 additions and 39 deletions
+12 -4
View File
@@ -16,12 +16,12 @@
//! Runtime declaration of the parachain metrics.
use polkadot_runtime_metrics::{Counter, CounterVec};
use polkadot_runtime_metrics::{Counter, CounterVec, Histogram};
use primitives::metric_definitions::{
PARACHAIN_CREATE_INHERENT_BITFIELDS_SIGNATURE_CHECKS,
PARACHAIN_INHERENT_DATA_BITFIELDS_PROCESSED, PARACHAIN_INHERENT_DATA_CANDIDATES_PROCESSED,
PARACHAIN_INHERENT_DATA_DISPUTE_SETS_INCLUDED, PARACHAIN_INHERENT_DATA_DISPUTE_SETS_PROCESSED,
PARACHAIN_INHERENT_DATA_WEIGHT,
PARACHAIN_INHERENT_DATA_WEIGHT, PARACHAIN_VERIFY_DISPUTE_SIGNATURE,
};
pub struct Metrics {
@@ -37,6 +37,9 @@ pub struct Metrics {
disputes_included: Counter,
/// Counts bitfield signature checks in `enter_inner`.
bitfields_signature_checks: CounterVec,
/// Histogram with the time spent checking a validator signature of a dispute statement
signature_timings: Histogram,
}
impl Metrics {
@@ -98,11 +101,15 @@ impl Metrics {
}
pub fn on_valid_bitfield_signature(&self) {
self.bitfields_signature_checks.with_label_values(&["valid"]).inc();
self.bitfields_signature_checks.with_label_values(&["valid"]).inc_by(1);
}
pub fn on_invalid_bitfield_signature(&self) {
self.bitfields_signature_checks.with_label_values(&["invalid"]).inc();
self.bitfields_signature_checks.with_label_values(&["invalid"]).inc_by(1);
}
pub fn on_signature_check_complete(&self, val: u128) {
self.signature_timings.observe(val);
}
}
@@ -115,4 +122,5 @@ pub const METRICS: Metrics = Metrics {
bitfields_signature_checks: CounterVec::new(
PARACHAIN_CREATE_INHERENT_BITFIELDS_SIGNATURE_CHECKS,
),
signature_timings: Histogram::new(PARACHAIN_VERIFY_DISPUTE_SIGNATURE),
};