Skip to content

Commit

Permalink
Prometheus options in Substrate relay (paritytech#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent 9695206 commit fc9c667
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 4 additions & 1 deletion bridges/relays/substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
30 changes: 30 additions & 0 deletions bridges/relays/substrate/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,46 @@ 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,
#[structopt(flatten)]
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<PrometheusParams> for Option<relay_utils::metrics::MetricsParams> {
fn from(cli_params: PrometheusParams) -> Option<relay_utils::metrics::MetricsParams> {
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! {
Expand Down
3 changes: 2 additions & 1 deletion bridges/relays/substrate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
}
}

Expand Down
8 changes: 6 additions & 2 deletions bridges/relays/substrate/src/millau_headers_to_rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ impl TargetClient<MillauHeadersToRialto> 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<relay_utils::metrics::MetricsParams>,
) {
let millau_tick = Duration::from_secs(5);
let rialto_tick = Duration::from_secs(5);
let sync_params = HeadersSyncParams {
Expand All @@ -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),
Expand Down

0 comments on commit fc9c667

Please sign in to comment.