Skip to content

Commit

Permalink
fix(witness_generator): Only spawn 1 prometheus exporter per witness …
Browse files Browse the repository at this point in the history
…generator (#2492)

## What ❔

Currently, when running with `--all-rounds`, witness generator will
spawn several prometheus exporter servers.
This is meaningless, as the metrics are collected by the global registry
anyways.
This PR changes the code so that we only spawn a single prometheus
exporter.

## Why ❔

Indeed

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
popzxc authored Jul 26, 2024
1 parent 572ad40 commit b9cb222
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions prover/crates/bin/witness_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,32 @@ async fn main() -> anyhow::Result<()> {
}
};

let prometheus_config = if use_push_gateway {
let prometheus_config = prometheus_config
.clone()
.context("prometheus config needed when use_push_gateway enabled")?;
PrometheusExporterConfig::push(
prometheus_config
.gateway_endpoint()
.context("gateway_endpoint needed when use_push_gateway enabled")?,
prometheus_config.push_interval(),
)
} else {
PrometheusExporterConfig::pull(prometheus_listener_port as u16)
};
let prometheus_task = prometheus_config.run(stop_receiver.clone());

let mut tasks = Vec::new();
tasks.push(tokio::spawn(prometheus_task));

for (i, round) in rounds.iter().enumerate() {
for round in rounds {
tracing::info!(
"initializing the {:?} witness generator, batch size: {:?} with protocol_version: {:?}",
round,
opt.batch_size,
&protocol_version
);

let prometheus_config = if use_push_gateway {
let prometheus_config = prometheus_config
.clone()
.context("prometheus config needed when use_push_gateway enabled")?;
PrometheusExporterConfig::push(
prometheus_config
.gateway_endpoint()
.context("gateway_endpoint needed when use_push_gateway enabled")?,
prometheus_config.push_interval(),
)
} else {
// `u16` cast is safe since i is in range [0, 4)
PrometheusExporterConfig::pull(prometheus_listener_port + i as u16)
};
let prometheus_task = prometheus_config.run(stop_receiver.clone());

let witness_generator_task = match round {
AggregationRound::BasicCircuits => {
let setup_data_path = prover_config.setup_data_path.clone();
Expand Down Expand Up @@ -276,15 +276,14 @@ async fn main() -> anyhow::Result<()> {
}
};

tasks.push(tokio::spawn(prometheus_task));
tasks.push(tokio::spawn(witness_generator_task));

tracing::info!(
"initialized {:?} witness generator in {:?}",
round,
started_at.elapsed()
);
SERVER_METRICS.init_latency[&(*round).into()].set(started_at.elapsed());
SERVER_METRICS.init_latency[&round.into()].set(started_at.elapsed());
}

let (mut stop_signal_sender, mut stop_signal_receiver) = mpsc::channel(256);
Expand Down

0 comments on commit b9cb222

Please sign in to comment.