From fc9c667ada789c40062ba711d3cb55466ae27b21 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 7 Oct 2020 21:39:07 +0300 Subject: [PATCH] Prometheus options in Substrate relay (#402) --- bridges/relays/substrate/Cargo.toml | 5 +++- bridges/relays/substrate/src/cli.rs | 30 +++++++++++++++++++ bridges/relays/substrate/src/main.rs | 3 +- .../substrate/src/millau_headers_to_rialto.rs | 8 +++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/bridges/relays/substrate/Cargo.toml b/bridges/relays/substrate/Cargo.toml index bd52598ff596b..ea7f37c02ea55 100644 --- a/bridges/relays/substrate/Cargo.toml +++ b/bridges/relays/substrate/Cargo.toml @@ -12,7 +12,6 @@ codec = { package = "parity-scale-codec", version = "1.3.4" } futures = "0.3.5" log = "0.4.11" paste = "1.0" -sp-runtime = "2.0" structopt = "0.3" # Bridge dependencies @@ -24,3 +23,7 @@ relay-millau-client = { path = "../millau-client" } relay-rialto-client = { path = "../rialto-client" } relay-substrate-client = { path = "../substrate-client" } relay-utils = { path = "../utils" } + +# Substrate dependencies + +sp-runtime = "2.0" diff --git a/bridges/relays/substrate/src/cli.rs b/bridges/relays/substrate/src/cli.rs index ca97aa00249ea..3dfda38e8a505 100644 --- a/bridges/relays/substrate/src/cli.rs +++ b/bridges/relays/substrate/src/cli.rs @@ -27,6 +27,7 @@ pub fn parse_args() -> Command { #[derive(StructOpt)] #[structopt(about = "Substrate-to-Substrate relay")] pub enum Command { + /// Relay Millau headers to Rialto. MillauHeadersToRialto { #[structopt(flatten)] millau: MillauConnectionParams, @@ -34,9 +35,38 @@ pub enum Command { rialto: RialtoConnectionParams, #[structopt(flatten)] rialto_sign: RialtoSigningParams, + #[structopt(flatten)] + prometheus_params: PrometheusParams, }, } +/// Prometheus metrics params. +#[derive(StructOpt)] +pub struct PrometheusParams { + /// Do not expose a Prometheus metric endpoint. + #[structopt(long)] + pub no_prometheus: bool, + /// Expose Prometheus endpoint at given interface. + #[structopt(long, default_value = "127.0.0.1")] + pub prometheus_host: String, + /// Expose Prometheus endpoint at given port. + #[structopt(long, default_value = "9616")] + pub prometheus_port: u16, +} + +impl From for Option { + fn from(cli_params: PrometheusParams) -> Option { + if !cli_params.no_prometheus { + Some(relay_utils::metrics::MetricsParams { + host: cli_params.prometheus_host, + port: cli_params.prometheus_port, + }) + } else { + None + } + } +} + macro_rules! declare_chain_options { ($chain:ident, $chain_prefix:ident) => { paste::item! { diff --git a/bridges/relays/substrate/src/main.rs b/bridges/relays/substrate/src/main.rs index 09728ef6941c7..743827ab8d871 100644 --- a/bridges/relays/substrate/src/main.rs +++ b/bridges/relays/substrate/src/main.rs @@ -45,6 +45,7 @@ async fn run_command(command: cli::Command) -> Result<(), String> { millau, rialto, rialto_sign, + prometheus_params, } => { let millau_client = MillauClient::new(ConnectionParams { host: millau.millau_host, @@ -61,7 +62,7 @@ async fn run_command(command: cli::Command) -> Result<(), String> { rialto_sign.rialto_signer_password.as_deref(), ) .map_err(|e| format!("Failed to parse rialto-signer: {:?}", e))?; - millau_headers_to_rialto::run(millau_client, rialto_client, rialto_sign); + millau_headers_to_rialto::run(millau_client, rialto_client, rialto_sign, prometheus_params.into()); } } diff --git a/bridges/relays/substrate/src/millau_headers_to_rialto.rs b/bridges/relays/substrate/src/millau_headers_to_rialto.rs index d927a9e133f42..f7064c51bf111 100644 --- a/bridges/relays/substrate/src/millau_headers_to_rialto.rs +++ b/bridges/relays/substrate/src/millau_headers_to_rialto.rs @@ -97,7 +97,12 @@ impl TargetClient for RialtoTargetClient { } /// Run Millau-to-Rialto headers sync. -pub fn run(millau_client: MillauClient, rialto_client: RialtoClient, rialto_sign: RialtoSigningParams) { +pub fn run( + millau_client: MillauClient, + rialto_client: RialtoClient, + rialto_sign: RialtoSigningParams, + metrics_params: Option, +) { let millau_tick = Duration::from_secs(5); let rialto_tick = Duration::from_secs(5); let sync_params = HeadersSyncParams { @@ -108,7 +113,6 @@ pub fn run(millau_client: MillauClient, rialto_client: RialtoClient, rialto_sign prune_depth: 256, target_tx_mode: TargetTransactionMode::Signed, }; - let metrics_params = None; headers_relay::sync_loop::run( MillauSourceClient::new(millau_client),