mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 12:11:02 +00:00
Expose relay version metric (#1750)
* expose relay version metric * spelling * and clippy * clippy * typo * use version directly and determine git commit * typos and leftovers
This commit is contained in:
committed by
Bastian Köcher
parent
444dbe7173
commit
70eb076ab2
@@ -15,6 +15,7 @@ hex = "0.4"
|
|||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
num-format = "0.4"
|
num-format = "0.4"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
|
rbtag = "0.3"
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
signal-hook = "0.3.14"
|
signal-hook = "0.3.14"
|
||||||
signal-hook-async-std = "0.2.2"
|
signal-hook-async-std = "0.2.2"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use std::convert::TryInto;
|
|||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use futures::{select, FutureExt};
|
use futures::{select, FutureExt};
|
||||||
|
use rbtag::BuildInfo;
|
||||||
use signal_hook::consts::*;
|
use signal_hook::consts::*;
|
||||||
use signal_hook_async_std::Signals;
|
use signal_hook_async_std::Signals;
|
||||||
use structopt::{clap::arg_enum, StructOpt};
|
use structopt::{clap::arg_enum, StructOpt};
|
||||||
@@ -254,17 +255,30 @@ pub struct PrometheusParams {
|
|||||||
pub prometheus_port: u16,
|
pub prometheus_port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<PrometheusParams> for relay_utils::metrics::MetricsParams {
|
/// Struct to get git commit info and build time.
|
||||||
fn from(cli_params: PrometheusParams) -> relay_utils::metrics::MetricsParams {
|
#[derive(BuildInfo)]
|
||||||
if !cli_params.no_prometheus {
|
struct SubstrateRelayBuildInfo;
|
||||||
|
|
||||||
|
impl PrometheusParams {
|
||||||
|
/// Tries to convert CLI metrics params into metrics params, used by the relay.
|
||||||
|
pub fn into_metrics_params(self) -> anyhow::Result<relay_utils::metrics::MetricsParams> {
|
||||||
|
let metrics_address = if !self.no_prometheus {
|
||||||
Some(relay_utils::metrics::MetricsAddress {
|
Some(relay_utils::metrics::MetricsAddress {
|
||||||
host: cli_params.prometheus_host,
|
host: self.prometheus_host,
|
||||||
port: cli_params.prometheus_port,
|
port: self.prometheus_port,
|
||||||
})
|
})
|
||||||
.into()
|
|
||||||
} else {
|
} else {
|
||||||
None.into()
|
None
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let relay_version = option_env!("CARGO_PKG_VERSION").unwrap_or("unknown");
|
||||||
|
let relay_commit = SubstrateRelayBuildInfo.get_build_commit();
|
||||||
|
relay_utils::metrics::MetricsParams::new(
|
||||||
|
metrics_address,
|
||||||
|
relay_version.into(),
|
||||||
|
relay_commit.into(),
|
||||||
|
)
|
||||||
|
.map_err(|e| anyhow::format_err!("{:?}", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ where
|
|||||||
let target_transactions_mortality = data.target_sign.target_transactions_mortality;
|
let target_transactions_mortality = data.target_sign.target_transactions_mortality;
|
||||||
let target_sign = data.target_sign.to_keypair::<Self::Target>()?;
|
let target_sign = data.target_sign.to_keypair::<Self::Target>()?;
|
||||||
|
|
||||||
let metrics_params: relay_utils::metrics::MetricsParams = data.prometheus_params.into();
|
let metrics_params: relay_utils::metrics::MetricsParams =
|
||||||
|
data.prometheus_params.into_metrics_params()?;
|
||||||
GlobalMetrics::new()?.register_and_spawn(&metrics_params.registry)?;
|
GlobalMetrics::new()?.register_and_spawn(&metrics_params.registry)?;
|
||||||
|
|
||||||
let target_transactions_params = substrate_relay_helper::TransactionParams {
|
let target_transactions_params = substrate_relay_helper::TransactionParams {
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ impl<Left: ChainWithTransactions + CliChain, Right: ChainWithTransactions + CliC
|
|||||||
right: BridgeEndCommonParams<Right>,
|
right: BridgeEndCommonParams<Right>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
// Create metrics registry.
|
// Create metrics registry.
|
||||||
let metrics_params = shared.prometheus_params.clone().into();
|
let metrics_params = shared.prometheus_params.clone().into_metrics_params()?;
|
||||||
let metrics_params = relay_utils::relay_metrics(metrics_params).into_params();
|
let metrics_params = relay_utils::relay_metrics(metrics_params).into_params();
|
||||||
|
|
||||||
Ok(Self { shared, left, right, metrics_params })
|
Ok(Self { shared, left, right, metrics_params })
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ where
|
|||||||
source_to_target_headers_relay: None,
|
source_to_target_headers_relay: None,
|
||||||
target_to_source_headers_relay: None,
|
target_to_source_headers_relay: None,
|
||||||
lane_id: data.lane.into(),
|
lane_id: data.lane.into(),
|
||||||
metrics_params: data.prometheus_params.into(),
|
metrics_params: data.prometheus_params.into_metrics_params()?,
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow::format_err!("{}", e))
|
.map_err(|e| anyhow::format_err!("{}", e))
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ where
|
|||||||
target_transaction_params,
|
target_transaction_params,
|
||||||
);
|
);
|
||||||
|
|
||||||
let metrics_params: relay_utils::metrics::MetricsParams = data.prometheus_params.into();
|
let metrics_params: relay_utils::metrics::MetricsParams =
|
||||||
|
data.prometheus_params.into_metrics_params()?;
|
||||||
GlobalMetrics::new()?.register_and_spawn(&metrics_params.registry)?;
|
GlobalMetrics::new()?.register_and_spawn(&metrics_params.registry)?;
|
||||||
|
|
||||||
parachains_relay::parachains_loop::run(
|
parachains_relay::parachains_loop::run(
|
||||||
|
|||||||
@@ -99,6 +99,39 @@ impl Default for MetricsAddress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetricsParams {
|
impl MetricsParams {
|
||||||
|
/// Creates metrics params from metrics address.
|
||||||
|
pub fn new(
|
||||||
|
address: Option<MetricsAddress>,
|
||||||
|
relay_version: String,
|
||||||
|
relay_commit: String,
|
||||||
|
) -> Result<Self, PrometheusError> {
|
||||||
|
const BUILD_INFO_METRIC: &str = "substrate_relay_build_info";
|
||||||
|
|
||||||
|
let registry = Registry::new();
|
||||||
|
register(
|
||||||
|
Gauge::<U64>::with_opts(
|
||||||
|
Opts::new(
|
||||||
|
BUILD_INFO_METRIC,
|
||||||
|
"A metric with a constant '1' value labeled by version",
|
||||||
|
)
|
||||||
|
.const_label("version", &relay_version)
|
||||||
|
.const_label("commit", &relay_commit),
|
||||||
|
)?,
|
||||||
|
®istry,
|
||||||
|
)?
|
||||||
|
.set(1);
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
target: "bridge",
|
||||||
|
"Exposed {} metric: version={} commit={}",
|
||||||
|
BUILD_INFO_METRIC,
|
||||||
|
relay_version,
|
||||||
|
relay_commit,
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(MetricsParams { address, registry })
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates metrics params so that metrics are not exposed.
|
/// Creates metrics params so that metrics are not exposed.
|
||||||
pub fn disabled() -> Self {
|
pub fn disabled() -> Self {
|
||||||
MetricsParams { address: None, registry: Registry::new() }
|
MetricsParams { address: None, registry: Registry::new() }
|
||||||
@@ -112,12 +145,6 @@ impl MetricsParams {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Option<MetricsAddress>> for MetricsParams {
|
|
||||||
fn from(address: Option<MetricsAddress>) -> Self {
|
|
||||||
MetricsParams { address, registry: Registry::new() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns metric name optionally prefixed with given prefix.
|
/// Returns metric name optionally prefixed with given prefix.
|
||||||
pub fn metric_name(prefix: Option<&str>, name: &str) -> String {
|
pub fn metric_name(prefix: Option<&str>, name: &str) -> String {
|
||||||
if let Some(prefix) = prefix {
|
if let Some(prefix) = prefix {
|
||||||
|
|||||||
Reference in New Issue
Block a user