mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
initial prometheus metrics (#1536)
* service-new: cosmetic changes * overseer: draft of prometheus metrics * metrics: update active_leaves metrics * metrics: extract into functions * metrics: resolve XXX * metrics: it's ugly, but it works * Bump Substrate * metrics: move a bunch of code around * Bumb substrate again * metrics: fix a warning * fix a warning in runtime * metrics: statements signed * metrics: statements impl RegisterMetrics * metrics: refactor Metrics trait * metrics: add Metrics assoc type to JobTrait * metrics: move Metrics trait to util * metrics: fix overseer * metrics: fix backing * metrics: fix candidate validation * metrics: derive Default * metrics: docs * metrics: add stubs for other subsystems * metrics: add more stubs and fix compilation * metrics: fix doctest * metrics: move to subsystem * metrics: fix candidate validation * metrics: bitfield signing * metrics: av store * metrics: chain API * metrics: runtime API * metrics: stub for avad * metrics: candidates seconded * metrics: ok I gave up * metrics: provisioner * metrics: remove a clone by requiring Metrics: Sync * metrics: YAGNI * metrics: remove another TODO * metrics: for later * metrics: add parachain_ prefix * metrics: s/signed_statement/signed_statements * utils: add a comment for job metrics * metrics: address review comments * metrics: oops * metrics: make sure to save files before commit 😅 * use _total suffix for requests metrics Co-authored-by: Max Inden <mail@max-inden.de> * metrics: add tests for overseer * update Cargo.lock * overseer: add a test for CollationGeneration * collation-generation: impl metrics * collation-generation: use kebab-case for name * collation-generation: add a constructor Co-authored-by: Gav Wood <gavin@parity.io> Co-authored-by: Ashley Ruglys <ashley.ruglys@gmail.com> Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
//! Node-side logic for Polkadot is mostly comprised of Subsystems, which are discrete components
|
||||
//! that communicate via message-passing. They are coordinated by an overseer, provided by a
|
||||
//! separate crate.
|
||||
//!
|
||||
//! This crate also reexports Prometheus metric types which are expected to be implemented by subsystems.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
@@ -128,9 +130,9 @@ impl From<oneshot::Canceled> for SubsystemError {
|
||||
}
|
||||
|
||||
impl From<futures::task::SpawnError> for SubsystemError {
|
||||
fn from(_: futures::task::SpawnError) -> Self {
|
||||
fn from(_: futures::task::SpawnError) -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::convert::Infallible> for SubsystemError {
|
||||
@@ -202,6 +204,9 @@ pub trait SubsystemContext: Send + 'static {
|
||||
/// [`Overseer`]: struct.Overseer.html
|
||||
/// [`Subsystem`]: trait.Subsystem.html
|
||||
pub trait Subsystem<C: SubsystemContext> {
|
||||
/// Subsystem-specific Prometheus metrics.
|
||||
type Metrics: metrics::Metrics;
|
||||
|
||||
/// Start this `Subsystem` and return `SpawnedSubsystem`.
|
||||
fn start(self, ctx: C) -> SpawnedSubsystem;
|
||||
}
|
||||
@@ -211,6 +216,8 @@ pub trait Subsystem<C: SubsystemContext> {
|
||||
pub struct DummySubsystem;
|
||||
|
||||
impl<C: SubsystemContext> Subsystem<C> for DummySubsystem {
|
||||
type Metrics = ();
|
||||
|
||||
fn start(self, mut ctx: C) -> SpawnedSubsystem {
|
||||
let future = Box::pin(async move {
|
||||
loop {
|
||||
@@ -227,4 +234,41 @@ impl<C: SubsystemContext> Subsystem<C> for DummySubsystem {
|
||||
future,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This module reexports Prometheus types and defines the [`Metrics`] trait.
|
||||
pub mod metrics {
|
||||
/// Reexport Prometheus types.
|
||||
pub use substrate_prometheus_endpoint as prometheus;
|
||||
|
||||
/// Subsystem- or job-specific Prometheus metrics.
|
||||
///
|
||||
/// Usually implemented as a wrapper for `Option<ActualMetrics>`
|
||||
/// to ensure `Default` bounds or as a dummy type ().
|
||||
/// Prometheus metrics internally hold an `Arc` reference, so cloning them is fine.
|
||||
pub trait Metrics: Default + Clone {
|
||||
/// Try to register metrics in the Prometheus registry.
|
||||
fn try_register(registry: &prometheus::Registry) -> Result<Self, prometheus::PrometheusError>;
|
||||
|
||||
/// Convience method to register metrics in the optional Prometheus registry.
|
||||
/// If the registration fails, prints a warning and returns `Default::default()`.
|
||||
fn register(registry: Option<&prometheus::Registry>) -> Self {
|
||||
registry.map(|r| {
|
||||
match Self::try_register(r) {
|
||||
Err(e) => {
|
||||
log::warn!("Failed to register metrics: {:?}", e);
|
||||
Default::default()
|
||||
},
|
||||
Ok(metrics) => metrics,
|
||||
}
|
||||
}).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
// dummy impl
|
||||
impl Metrics for () {
|
||||
fn try_register(_registry: &prometheus::Registry) -> Result<(), prometheus::PrometheusError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user