Skip to content

Commit

Permalink
chore: move metrics init into CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Arqu committed Apr 2, 2024
1 parent c3252b6 commit c4e05d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions iroh-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
10 changes: 10 additions & 0 deletions iroh-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
9 changes: 0 additions & 9 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?)
Expand Down

0 comments on commit c4e05d3

Please sign in to comment.