mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-25 20:01:09 +00:00
Unify metric names (#1209)
* unify metric names * refactor standalone metrics * headers sync metrics * post-merge fix * fix compilation * fmt * fix dashboards * fix local dashboards * update Rococo/Wococo runtime version * remove commented code * fixed grumbles * fmt * fixed widget names
This commit is contained in:
committed by
Bastian Köcher
parent
940d7e463b
commit
bbf8b51f9c
@@ -16,7 +16,7 @@
|
||||
|
||||
use crate::{
|
||||
error::Error,
|
||||
metrics::{Metrics, MetricsAddress, MetricsParams, PrometheusError, StandaloneMetrics},
|
||||
metrics::{Metric, MetricsAddress, MetricsParams},
|
||||
FailedClient, MaybeConnectionError,
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ pub fn relay_loop<SC, TC>(source_client: SC, target_client: TC) -> Loop<SC, TC,
|
||||
|
||||
/// Returns generic relay loop metrics that may be customized and used in one or several relay
|
||||
/// loops.
|
||||
pub fn relay_metrics(prefix: Option<String>, params: MetricsParams) -> LoopMetrics<(), (), ()> {
|
||||
pub fn relay_metrics(params: MetricsParams) -> LoopMetrics<(), (), ()> {
|
||||
LoopMetrics {
|
||||
relay_loop: Loop {
|
||||
reconnect_delay: RECONNECT_DELAY,
|
||||
@@ -62,8 +62,7 @@ pub fn relay_metrics(prefix: Option<String>, params: MetricsParams) -> LoopMetri
|
||||
loop_metric: None,
|
||||
},
|
||||
address: params.address,
|
||||
registry: params.registry.unwrap_or_else(|| create_metrics_registry(prefix)),
|
||||
metrics_prefix: params.metrics_prefix,
|
||||
registry: params.registry,
|
||||
loop_metric: None,
|
||||
}
|
||||
}
|
||||
@@ -81,7 +80,6 @@ pub struct LoopMetrics<SC, TC, LM> {
|
||||
relay_loop: Loop<SC, TC, ()>,
|
||||
address: Option<MetricsAddress>,
|
||||
registry: Registry,
|
||||
metrics_prefix: Option<String>,
|
||||
loop_metric: Option<LM>,
|
||||
}
|
||||
|
||||
@@ -93,11 +91,7 @@ impl<SC, TC, LM> Loop<SC, TC, LM> {
|
||||
}
|
||||
|
||||
/// Start building loop metrics using given prefix.
|
||||
pub fn with_metrics(
|
||||
self,
|
||||
prefix: Option<String>,
|
||||
params: MetricsParams,
|
||||
) -> LoopMetrics<SC, TC, ()> {
|
||||
pub fn with_metrics(self, params: MetricsParams) -> LoopMetrics<SC, TC, ()> {
|
||||
LoopMetrics {
|
||||
relay_loop: Loop {
|
||||
reconnect_delay: self.reconnect_delay,
|
||||
@@ -106,8 +100,7 @@ impl<SC, TC, LM> Loop<SC, TC, LM> {
|
||||
loop_metric: None,
|
||||
},
|
||||
address: params.address,
|
||||
registry: params.registry.unwrap_or_else(|| create_metrics_registry(prefix)),
|
||||
metrics_prefix: params.metrics_prefix,
|
||||
registry: params.registry,
|
||||
loop_metric: None,
|
||||
}
|
||||
}
|
||||
@@ -160,44 +153,23 @@ impl<SC, TC, LM> LoopMetrics<SC, TC, LM> {
|
||||
/// Add relay loop metrics.
|
||||
///
|
||||
/// Loop metrics will be passed to the loop callback.
|
||||
pub fn loop_metric<NewLM: Metrics>(
|
||||
pub fn loop_metric<NewLM: Metric>(
|
||||
self,
|
||||
create_metric: impl FnOnce(&Registry, Option<&str>) -> Result<NewLM, PrometheusError>,
|
||||
metric: NewLM,
|
||||
) -> Result<LoopMetrics<SC, TC, NewLM>, Error> {
|
||||
let loop_metric = create_metric(&self.registry, self.metrics_prefix.as_deref())?;
|
||||
metric.register(&self.registry)?;
|
||||
|
||||
Ok(LoopMetrics {
|
||||
relay_loop: self.relay_loop,
|
||||
address: self.address,
|
||||
registry: self.registry,
|
||||
metrics_prefix: self.metrics_prefix,
|
||||
loop_metric: Some(loop_metric),
|
||||
loop_metric: Some(metric),
|
||||
})
|
||||
}
|
||||
|
||||
/// Add standalone metrics.
|
||||
pub fn standalone_metric<M: StandaloneMetrics>(
|
||||
self,
|
||||
create_metric: impl FnOnce(&Registry, Option<&str>) -> Result<M, PrometheusError>,
|
||||
) -> Result<Self, Error> {
|
||||
// since standalone metrics are updating themselves, we may just ignore the fact that the
|
||||
// same standalone metric is exposed by several loops && only spawn single metric
|
||||
match create_metric(&self.registry, self.metrics_prefix.as_deref()) {
|
||||
Ok(standalone_metrics) => standalone_metrics.spawn(),
|
||||
Err(PrometheusError::AlreadyReg) => (),
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Convert into `MetricsParams` structure so that metrics registry may be extended later.
|
||||
pub fn into_params(self) -> MetricsParams {
|
||||
MetricsParams {
|
||||
address: self.address,
|
||||
registry: Some(self.registry),
|
||||
metrics_prefix: self.metrics_prefix,
|
||||
}
|
||||
MetricsParams { address: self.address, registry: self.registry }
|
||||
}
|
||||
|
||||
/// Expose metrics using address passed at creation.
|
||||
@@ -274,15 +246,3 @@ pub async fn reconnect_failed_client(
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/// Create new registry with global metrics.
|
||||
fn create_metrics_registry(prefix: Option<String>) -> Registry {
|
||||
match prefix {
|
||||
Some(prefix) => {
|
||||
assert!(!prefix.is_empty(), "Metrics prefix can not be empty");
|
||||
Registry::new_custom(Some(prefix), None)
|
||||
.expect("only fails if prefix is empty; prefix is not empty; qed")
|
||||
},
|
||||
None => Registry::new(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user