Skip to content

Commit

Permalink
sc-consensus-beefy: fix metrics: use correct names (paritytech#13494)
Browse files Browse the repository at this point in the history
Signed-off-by: acatangiu <[email protected]>
  • Loading branch information
acatangiu authored and nathanwhit committed Jul 19, 2023
1 parent 720d953 commit 5063c9a
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions client/consensus/beefy/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

//! BEEFY Prometheus metrics definition

use log::debug;
use crate::LOG_TARGET;
use log::{debug, error};
use prometheus::{register, Counter, Gauge, PrometheusError, Registry, U64};

/// Helper trait for registering BEEFY metrics to Prometheus registry.
Expand Down Expand Up @@ -129,13 +130,13 @@ impl PrometheusRegister for VoterMetrics {
)?,
beefy_equivocation_votes: register(
Counter::new(
"substrate_beefy_stale_votes",
"substrate_beefy_equivocation_votes",
"Number of equivocation votes received",
)?,
registry,
)?,
beefy_invalid_votes: register(
Counter::new("substrate_beefy_stale_votes", "Number of invalid votes received")?,
Counter::new("substrate_beefy_invalid_votes", "Number of invalid votes received")?,
registry,
)?,
beefy_stale_votes: register(
Expand Down Expand Up @@ -200,14 +201,14 @@ impl PrometheusRegister for BlockImportMetrics {
beefy_good_justification_imports: register(
Counter::new(
"substrate_beefy_good_justification_imports",
"Number of Good Justification imports",
"Number of good justifications on block-import",
)?,
registry,
)?,
beefy_bad_justification_imports: register(
Counter::new(
"substrate_beefy_bad_justification_imports",
"Number of Bad Justification imports",
"Number of bad justifications on block-import",
)?,
registry,
)?,
Expand Down Expand Up @@ -309,11 +310,16 @@ pub(crate) fn register_metrics<T: PrometheusRegister>(
) -> Option<T> {
prometheus_registry.as_ref().map(T::register).and_then(|result| match result {
Ok(metrics) => {
debug!(target: "beefy", "🥩 Registered {} metrics", T::DESCRIPTION);
debug!(target: LOG_TARGET, "🥩 Registered {} metrics", T::DESCRIPTION);
Some(metrics)
},
Err(err) => {
debug!(target: "beefy", "🥩 Failed to register {} metrics: {:?}", T::DESCRIPTION, err);
error!(
target: LOG_TARGET,
"🥩 Failed to register {} metrics: {:?}",
T::DESCRIPTION,
err
);
None
},
})
Expand Down Expand Up @@ -347,3 +353,17 @@ macro_rules! metric_get {
$self.metrics.as_ref().map(|metrics| metrics.$m.clone())
}};
}

#[cfg(test)]
pub(crate) mod tests {
use super::*;

#[test]
fn should_register_metrics() {
let registry = Some(Registry::new());
assert!(register_metrics::<VoterMetrics>(registry.clone()).is_some());
assert!(register_metrics::<BlockImportMetrics>(registry.clone()).is_some());
assert!(register_metrics::<OnDemandIncomingRequestsMetrics>(registry.clone()).is_some());
assert!(register_metrics::<OnDemandOutgoingRequestsMetrics>(registry.clone()).is_some());
}
}

0 comments on commit 5063c9a

Please sign in to comment.