From ede29bb842ac713e9bff6fa41b3022dcc7be48a2 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 29 Dec 2022 11:51:27 +0300 Subject: [PATCH] Expose metrics of on-demand relay chain headers sync from with-parachain complex relays (#1737) * expose metrics of on-demand relay chain headers sync from with-parachain complex relays * spelling * remove renundant arg --- .../relay_headers_and_messages/parachain_to_parachain.rs | 2 ++ .../cli/relay_headers_and_messages/relay_to_parachain.rs | 2 ++ .../src/cli/relay_headers_and_messages/relay_to_relay.rs | 2 ++ .../relays/lib-substrate-relay/src/on_demand/headers.rs | 8 +++++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs index f832722c6b346..3be07404ebe36 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs @@ -245,6 +245,7 @@ where self.common.right.client.clone(), self.left_headers_to_right_transaction_params.clone(), self.common.shared.only_mandatory_headers, + Some(self.common.metrics_params.clone()), ); let right_relay_to_left_on_demand_headers = OnDemandHeadersRelay::<::RelayFinality>::new( @@ -252,6 +253,7 @@ where self.common.left.client.clone(), self.right_headers_to_left_transaction_params.clone(), self.common.shared.only_mandatory_headers, + Some(self.common.metrics_params.clone()), ); let left_to_right_on_demand_parachains = OnDemandParachainsRelay::< diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs index 281996534e23f..babd39e558bb1 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs @@ -224,6 +224,7 @@ where self.common.right.client.clone(), self.left_headers_to_right_transaction_params.clone(), self.common.shared.only_mandatory_headers, + None, ); let right_relay_to_left_on_demand_headers = OnDemandHeadersRelay::<::RelayFinality>::new( @@ -231,6 +232,7 @@ where self.common.left.client.clone(), self.right_headers_to_left_transaction_params.clone(), self.common.shared.only_mandatory_headers, + Some(self.common.metrics_params.clone()), ); let right_to_left_on_demand_parachains = OnDemandParachainsRelay::< ::ParachainFinality, diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs index a2815bb613916..071716dedb859 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs @@ -173,6 +173,7 @@ where self.common.right.client.clone(), self.left_to_right_transaction_params.clone(), self.common.shared.only_mandatory_headers, + None, ); let right_to_left_on_demand_headers = OnDemandHeadersRelay::<::Finality>::new( @@ -180,6 +181,7 @@ where self.common.left.client.clone(), self.right_to_left_transaction_params.clone(), self.common.shared.only_mandatory_headers, + None, ); Ok((Arc::new(left_to_right_on_demand_headers), Arc::new(right_to_left_on_demand_headers))) diff --git a/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs b/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs index 369520f0e9a41..465b03c04a4a4 100644 --- a/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs +++ b/bridges/relays/lib-substrate-relay/src/on_demand/headers.rs @@ -64,11 +64,15 @@ pub struct OnDemandHeadersRelay { impl OnDemandHeadersRelay

{ /// Create new on-demand headers relay. + /// + /// If `metrics_params` is `Some(_)`, the metrics of the finality relay are registered. + /// Otherwise, all required metrics must be exposed outside of this method. pub fn new( source_client: Client, target_client: Client, target_transaction_params: TransactionParams>, only_mandatory_headers: bool, + metrics_params: Option, ) -> Self where AccountIdOf: @@ -87,6 +91,7 @@ impl OnDemandHeadersRelay

{ target_transaction_params, only_mandatory_headers, required_header_number, + metrics_params, ) .await; }); @@ -148,6 +153,7 @@ async fn background_task( target_transaction_params: TransactionParams>, only_mandatory_headers: bool, required_header_number: RequiredHeaderNumberRef, + metrics_params: Option, ) where AccountIdOf: From< as sp_core::Pair>::Public>, { @@ -310,7 +316,7 @@ async fn background_task( stall_timeout, only_mandatory_headers, }, - MetricsParams::disabled(), + metrics_params.clone().unwrap_or_else(|| MetricsParams::disabled()), futures::future::pending(), ) .fuse(),