Skip to content

Commit

Permalink
chore: move metrics init into CLI (#2136)
Browse files Browse the repository at this point in the history
## Description

Moved the metrics init into CLI so the lib doesn't init the full metrics
collection on its own and block other lib users to do their custom setup
on top.

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [ ] Documentation updates if relevant.
- [ ] Tests if relevant.
  • Loading branch information
Arqu authored Apr 2, 2024
1 parent 5e1a71f commit 319e9cc
Show file tree
Hide file tree
Showing 3 changed files with 13 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 = []
9 changes: 9 additions & 0 deletions iroh-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ 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 @@ -280,15 +280,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 319e9cc

Please sign in to comment.