Skip to content

Commit

Permalink
feat: add --metrics [flag] to forest (#3609)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Oct 20, 2023
1 parent dd2d422 commit 0dd8211
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
files.
- [#3589](https://github.com/ChainSafe/forest/pull/3589) Add
`forest-tool archive diff` command for debugging state-root mismatches.
- [#3609](https://github.com/ChainSafe/forest/pull/3609) Add `--no-metrics`
option to `forest` for controlling the availability of the metrics Prometheus
server.

### Changed

Expand Down
2 changes: 2 additions & 0 deletions src/cli_shared/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct Client {
pub data_dir: PathBuf,
pub genesis_file: Option<String>,
pub enable_rpc: bool,
pub enable_metrics_endpoint: bool,
pub rpc_token: Option<String>,
/// If this is true, then we do not validate the imported snapshot.
/// Otherwise, we validate and compute the states.
Expand Down Expand Up @@ -82,6 +83,7 @@ impl Default for Client {
data_dir: dir.data_dir().to_path_buf(),
genesis_file: None,
enable_rpc: true,
enable_metrics_endpoint: true,
rpc_token: None,
snapshot_path: None,
snapshot: false,
Expand Down
14 changes: 12 additions & 2 deletions src/cli_shared/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub struct CliOpts {
/// Allow RPC to be active or not (default: true)
#[arg(short, long)]
pub rpc: Option<bool>,
/// Disable Metrics endpoint
#[arg(short, long)]
pub no_metrics: bool,
/// Client JWT token to use for JSON-RPC authentication
#[arg(short, long)]
pub token: Option<String>,
Expand Down Expand Up @@ -186,9 +189,16 @@ impl CliOpts {
} else {
cfg.client.enable_rpc = false;
}
if let Some(metrics_address) = self.metrics_address {
cfg.client.metrics_address = metrics_address;

if self.no_metrics {
cfg.client.enable_metrics_endpoint = false;
} else {
cfg.client.enable_metrics_endpoint = true;
if let Some(metrics_address) = self.metrics_address {
cfg.client.metrics_address = metrics_address;
}
}

if self.import_snapshot.is_some() && self.import_chain.is_some() {
anyhow::bail!("Can't set import_snapshot and import_chain at the same time!")
} else if self.import_snapshot.is_some() && self.consume_snapshot.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub(super) async fn start(
});
}

{
if config.client.enable_metrics_endpoint {
// Start Prometheus server port
let prometheus_listener = TcpListener::bind(config.client.metrics_address).context(
format!("could not bind to {}", config.client.metrics_address),
Expand Down

0 comments on commit 0dd8211

Please sign in to comment.