From c4e05d3d6acd845790c20c9c9c2e33d94da0e9db Mon Sep 17 00:00:00 2001 From: Asmir Avdicevic Date: Tue, 2 Apr 2024 13:04:06 +0200 Subject: [PATCH] chore: move metrics init into CLI --- iroh-cli/Cargo.toml | 4 ++++ iroh-cli/src/commands.rs | 10 ++++++++++ iroh/src/node/builder.rs | 9 --------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/iroh-cli/Cargo.toml b/iroh-cli/Cargo.toml index 643b3f1c90..57addbf15c 100644 --- a/iroh-cli/Cargo.toml +++ b/iroh-cli/Cargo.toml @@ -65,3 +65,7 @@ nix = { version = "0.27", features = ["signal", "process"] } regex = "1.10.3" testdir = "0.9.1" walkdir = "2" + +[features] +default = ["metrics"] +metrics = [] \ No newline at end of file diff --git a/iroh-cli/src/commands.rs b/iroh-cli/src/commands.rs index eba273bb37..26e75d3fea 100644 --- a/iroh-cli/src/commands.rs +++ b/iroh-cli/src/commands.rs @@ -85,6 +85,16 @@ pub(crate) enum Commands { impl Cli { pub(crate) async fn run(self, data_dir: &Path) -> Result<()> { + + // Initialize the metrics collection. + // + // The metrics are global per process. Subsequent calls do not change the metrics + // collection and will return an error. We ignore this error. This means that if you'd + // spawn multiple Iroh nodes in the same process, the metrics would be shared between the + // nodes. + #[cfg(feature = "metrics")] + iroh::metrics::try_init_metrics_collection().ok(); + match self.command { Commands::Console => { let env = ConsoleEnv::for_console(data_dir)?; diff --git a/iroh/src/node/builder.rs b/iroh/src/node/builder.rs index d7bcd6c512..c76ece0557 100644 --- a/iroh/src/node/builder.rs +++ b/iroh/src/node/builder.rs @@ -313,15 +313,6 @@ where trace!("spawning node"); let lp = LocalPoolHandle::new(num_cpus::get()); - // Initialize the metrics collection. - // - // The metrics are global per process. Subsequent calls do not change the metrics - // collection and will return an error. We ignore this error. This means that if you'd - // spawn multiple Iroh nodes in the same process, the metrics would be shared between the - // nodes. - #[cfg(feature = "metrics")] - crate::metrics::try_init_metrics_collection().ok(); - let mut transport_config = quinn::TransportConfig::default(); transport_config .max_concurrent_bidi_streams(MAX_STREAMS.try_into()?)