diff --git a/config.toml b/config.toml index 84f578d101..82c9ce6581 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,6 @@ [global] strategy = 'naive' -log_level = 'debug' +log_level = 'info' telemetry_enabled = true telemetry_port = 3001 diff --git a/relayer-cli/src/commands/start_multi.rs b/relayer-cli/src/commands/start_multi.rs index a61fb2c902..accd764e9f 100644 --- a/relayer-cli/src/commands/start_multi.rs +++ b/relayer-cli/src/commands/start_multi.rs @@ -12,8 +12,12 @@ pub struct StartMultiCmd {} impl Runnable for StartMultiCmd { fn run(&self) { let config = app_config(); - let telemetry = telemetry::spawn(config.global.telemetry_port); - let supervisor = Supervisor::spawn(config.clone(), telemetry).expect("failed to spawn supervisor"); + let telemetry = telemetry::spawn( + config.global.telemetry_port, + config.global.telemetry_enabled, + ); + let supervisor = + Supervisor::spawn(config.clone(), telemetry).expect("failed to spawn supervisor"); match supervisor.run() { Ok(()) => Output::success_msg("done").exit(), Err(e) => Output::error(e).exit(), diff --git a/relayer/src/supervisor.rs b/relayer/src/supervisor.rs index 1bb586271e..fbefb25b76 100644 --- a/relayer/src/supervisor.rs +++ b/relayer/src/supervisor.rs @@ -30,8 +30,8 @@ use crate::{ }; mod error; -pub use error::Error; use crate::telemetry::service::MetricUpdate; +pub use error::Error; /// The supervisor listens for events on multiple pairs of chains, /// and dispatches the events it receives to the appropriate @@ -41,7 +41,7 @@ pub struct Supervisor { registry: Registry, workers: WorkerMap, worker_msg_rx: Receiver, - telemetry: Sender + telemetry: Sender, } impl Supervisor { @@ -55,7 +55,7 @@ impl Supervisor { registry, workers: WorkerMap::new(worker_msg_tx), worker_msg_rx, - telemetry + telemetry, }) } @@ -144,7 +144,7 @@ impl Supervisor { Ok(chain_handle) => { let _ = self.telemetry.send(MetricUpdate::RelayChainsNumber(1)); chain_handle - }, + } Err(e) => { error!("skipping workers for chain id {}. reason: failed to spawn chain runtime with error: {}", chain_id, e); continue; @@ -155,7 +155,7 @@ impl Supervisor { Ok(channels) => { let _ = self.telemetry.send(MetricUpdate::RelayChannelsNumber(1)); channels - }, + } Err(e) => { error!("failed to query channels from {}: {}", chain_id, e); continue; diff --git a/relayer/src/telemetry.rs b/relayer/src/telemetry.rs index 67f17f04c0..c620bf4ce6 100644 --- a/relayer/src/telemetry.rs +++ b/relayer/src/telemetry.rs @@ -1,22 +1,26 @@ -use crate::telemetry::state::TelemetryState; -use crate::telemetry::service::TelemetryService; use crate::telemetry::server::TelemetryServer; -use crossbeam_channel::Sender; use crate::telemetry::service::MetricUpdate; +use crate::telemetry::service::TelemetryService; +use crate::telemetry::state::TelemetryState; +use crossbeam_channel::Sender; -pub mod service; pub mod server; +pub mod service; pub mod state; -pub fn spawn(port: u16) -> Sender { +pub fn spawn(port: u16, enabled: bool) -> Sender { let (tx, rx) = crossbeam_channel::unbounded(); - let telemetry_state = TelemetryState::new(); - let service = TelemetryService::new(telemetry_state.clone(), rx); - let server = TelemetryServer::new(telemetry_state.clone()); - // Start the telemetry service and server - std::thread::spawn(move || server.run( telemetry_state.clone(),port)); - std::thread::spawn(move || service.run()); + // Only start the telemetry service and server if it is enabled in the configuration + if enabled { + let telemetry_state = TelemetryState::new(); + let service = TelemetryService::new(telemetry_state.clone(), rx); + let server = TelemetryServer::new(telemetry_state.clone()); + + // Start the telemetry service and server + std::thread::spawn(move || server.run(telemetry_state.clone(), port)); + std::thread::spawn(move || service.run()); + } tx -} \ No newline at end of file +} diff --git a/relayer/src/telemetry/server.rs b/relayer/src/telemetry/server.rs index 5e6cd3f0e6..dff177fdf6 100644 --- a/relayer/src/telemetry/server.rs +++ b/relayer/src/telemetry/server.rs @@ -1,5 +1,5 @@ -use prometheus::{Encoder, TextEncoder}; use crate::telemetry::state::TelemetryState; +use prometheus::{Encoder, TextEncoder}; pub struct TelemetryServer { pub state: TelemetryState, @@ -30,4 +30,4 @@ impl TelemetryServer { ) }); } -} \ No newline at end of file +} diff --git a/relayer/src/telemetry/service.rs b/relayer/src/telemetry/service.rs index 4109271522..4a9f3363b2 100644 --- a/relayer/src/telemetry/service.rs +++ b/relayer/src/telemetry/service.rs @@ -1,5 +1,5 @@ -use crossbeam_channel::Receiver; use crate::telemetry::state::TelemetryState; +use crossbeam_channel::Receiver; pub enum MetricUpdate { RelayChainsNumber(u64), @@ -10,15 +10,12 @@ pub enum MetricUpdate { pub struct TelemetryService { pub state: TelemetryState, - pub rx: Receiver + pub rx: Receiver, } impl TelemetryService { pub(crate) fn new(state: TelemetryState, rx: Receiver) -> Self { - Self { - state, - rx, - } + Self { state, rx } } pub(crate) fn run(self) { @@ -29,7 +26,7 @@ impl TelemetryService { fn apply_update(&self, update: MetricUpdate) { match update { - MetricUpdate::RelayChainsNumber(n) => self.state.relay_chains_num.add(n ), + MetricUpdate::RelayChainsNumber(n) => self.state.relay_chains_num.add(n), MetricUpdate::RelayChannelsNumber(n) => self.state.relay_channels_num.add(n), MetricUpdate::AcknowledgePacket(n) => self.state.tx_msg_ibc_acknowledge_packet.add(n), MetricUpdate::TxCount(n) => self.state.tx_count.add(n), diff --git a/relayer/src/telemetry/state.rs b/relayer/src/telemetry/state.rs index 2a18da4c62..d48f63bec3 100644 --- a/relayer/src/telemetry/state.rs +++ b/relayer/src/telemetry/state.rs @@ -1,7 +1,7 @@ -use opentelemetry::metrics::BoundCounter; -use opentelemetry_prometheus::PrometheusExporter; use opentelemetry::global; +use opentelemetry::metrics::BoundCounter; use opentelemetry::KeyValue; +use opentelemetry_prometheus::PrometheusExporter; lazy_static! { static ref HANDLER_ALL: [KeyValue; 1] = [KeyValue::new("hermes", "all")]; @@ -22,7 +22,6 @@ pub struct TelemetryState { // Total number of txs processed via Relay tx pub tx_count: BoundCounter<'static, u64>, - } impl TelemetryState { @@ -54,4 +53,4 @@ impl TelemetryState { }; telemetry_state } -} \ No newline at end of file +}