Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Always respect the --metrics-port disabled option #2459

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions iroh-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Cli {
Commands::Console => {
let data_dir_owned = data_dir.to_owned();
if self.start {
let config = NodeConfig::load(self.config.as_deref()).await?;
let config = Self::load_config(self.config, self.metrics_port).await?;
start::run_with_command(
&config,
data_dir,
Expand All @@ -138,7 +138,7 @@ impl Cli {
Commands::Rpc(command) => {
let data_dir_owned = data_dir.to_owned();
if self.start {
let config = NodeConfig::load(self.config.as_deref()).await?;
let config = Self::load_config(self.config, self.metrics_port).await?;
start::run_with_command(
&config,
data_dir,
Expand All @@ -165,13 +165,7 @@ impl Cli {
path.display()
);
}
let mut config = NodeConfig::load(self.config.as_deref()).await?;
if let Some(metrics_port) = self.metrics_port {
config.metrics_addr = match metrics_port {
MetricsPort::Disabled => None,
MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()),
};
}
let config = Self::load_config(self.config, self.metrics_port).await?;

let add_command = add.map(|source| blob::BlobCommands::Add {
source,
Expand All @@ -192,15 +186,23 @@ impl Cli {
.await
}
Commands::Doctor { command } => {
let mut config = NodeConfig::load(self.config.as_deref()).await?;
if let Some(metrics_port) = self.metrics_port {
config.metrics_addr = match metrics_port {
MetricsPort::Disabled => None,
MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()),
};
}
let config = Self::load_config(self.config, self.metrics_port).await?;
self::doctor::run(command, &config).await
}
}
}

async fn load_config(
config: Option<PathBuf>,
metrics_port: Option<MetricsPort>,
) -> Result<NodeConfig> {
let mut config = NodeConfig::load(config.as_deref()).await?;
if let Some(metrics_port) = metrics_port {
config.metrics_addr = match metrics_port {
MetricsPort::Disabled => None,
MetricsPort::Port(port) => Some(([127, 0, 0, 1], port).into()),
};
}
Ok(config)
}
}
Loading