diff --git a/core/bin/external_node/src/config/observability.rs b/core/bin/external_node/src/config/observability.rs index 4dc310ee26c2..4cd4efe0df04 100644 --- a/core/bin/external_node/src/config/observability.rs +++ b/core/bin/external_node/src/config/observability.rs @@ -123,7 +123,7 @@ impl ObservabilityENConfig { if let Some(prometheus) = general_config.prometheus_config.as_ref() { ( Some(prometheus.listener_port), - Some(prometheus.pushgateway_url.clone()), + prometheus.pushgateway_url.clone(), prometheus.push_interval_ms.unwrap_or_default(), ) } else { diff --git a/core/bin/snapshots_creator/src/main.rs b/core/bin/snapshots_creator/src/main.rs index 41775ff6f6ae..aee3919a4b0a 100644 --- a/core/bin/snapshots_creator/src/main.rs +++ b/core/bin/snapshots_creator/src/main.rs @@ -31,18 +31,18 @@ async fn maybe_enable_prometheus_metrics( stop_receiver: watch::Receiver, ) -> anyhow::Result>>> { let prometheus_config = PrometheusConfig::from_env().ok(); - if let Some(prometheus_config) = prometheus_config { - let exporter_config = PrometheusExporterConfig::push( - prometheus_config.gateway_endpoint(), - prometheus_config.push_interval(), - ); + match prometheus_config.map(|c| (c.gateway_endpoint(), c.push_interval())) { + Some((Some(gateway_endpoint), push_interval)) => { + tracing::info!("Starting prometheus exporter with gateway {gateway_endpoint:?} and push_interval {push_interval:?}"); + let exporter_config = PrometheusExporterConfig::push(gateway_endpoint, push_interval); - tracing::info!("Starting prometheus exporter with config {prometheus_config:?}"); - let prometheus_exporter_task = tokio::spawn(exporter_config.run(stop_receiver)); - Ok(Some(prometheus_exporter_task)) - } else { - tracing::info!("Starting without prometheus exporter"); - Ok(None) + let prometheus_exporter_task = tokio::spawn(exporter_config.run(stop_receiver)); + Ok(Some(prometheus_exporter_task)) + } + _ => { + tracing::info!("Starting without prometheus exporter"); + Ok(None) + } } } diff --git a/core/bin/zksync_tee_prover/src/main.rs b/core/bin/zksync_tee_prover/src/main.rs index 8de6bacef6fd..b6c311cb55de 100644 --- a/core/bin/zksync_tee_prover/src/main.rs +++ b/core/bin/zksync_tee_prover/src/main.rs @@ -47,22 +47,23 @@ fn main() -> anyhow::Result<()> { let attestation_quote_bytes = std::fs::read(tee_prover_config.attestation_quote_file_path)?; let prometheus_config = PrometheusConfig::from_env()?; - let exporter_config = PrometheusExporterConfig::push( - prometheus_config.gateway_endpoint(), - prometheus_config.push_interval(), - ); - ZkStackServiceBuilder::new() + let mut builder = ZkStackServiceBuilder::new(); + let mut builder_mut = builder .add_layer(SigintHandlerLayer) - .add_layer(PrometheusExporterLayer(exporter_config)) .add_layer(TeeProverLayer::new( tee_prover_config.api_url, tee_prover_config.signing_key, attestation_quote_bytes, tee_prover_config.tee_type, - )) - .build()? - .run()?; + )); + if let Some(gateway) = prometheus_config.gateway_endpoint() { + let exporter_config = + PrometheusExporterConfig::push(gateway, prometheus_config.push_interval()); + builder_mut = builder_mut.add_layer(PrometheusExporterLayer(exporter_config)); + } + + builder_mut.build()?.run()?; Ok(()) } diff --git a/core/lib/config/src/configs/utils.rs b/core/lib/config/src/configs/utils.rs index 977a48e82d20..23cd0d6dd740 100644 --- a/core/lib/config/src/configs/utils.rs +++ b/core/lib/config/src/configs/utils.rs @@ -7,7 +7,7 @@ pub struct PrometheusConfig { /// Port to which the Prometheus exporter server is listening. pub listener_port: u16, /// URL of the push gateway. - pub pushgateway_url: String, + pub pushgateway_url: Option, /// Push interval in ms. pub push_interval_ms: Option, } @@ -18,12 +18,16 @@ impl PrometheusConfig { } /// Returns the full endpoint URL for the push gateway. - pub fn gateway_endpoint(&self) -> String { - let gateway_url = &self.pushgateway_url; + pub fn gateway_endpoint(&self) -> Option { + let Some(gateway_url) = &self.pushgateway_url else { + return None; + }; let job_id = "zksync-pushgateway"; let namespace = env::var("POD_NAMESPACE").unwrap_or_else(|_| "UNKNOWN_NAMESPACE".to_owned()); let pod = env::var("POD_NAME").unwrap_or_else(|_| "UNKNOWN_POD".to_owned()); - format!("{gateway_url}/metrics/job/{job_id}/namespace/{namespace}/pod/{pod}") + Some(format!( + "{gateway_url}/metrics/job/{job_id}/namespace/{namespace}/pod/{pod}" + )) } } diff --git a/core/lib/env_config/src/api.rs b/core/lib/env_config/src/api.rs index 68af37393bba..64d8696f50bb 100644 --- a/core/lib/env_config/src/api.rs +++ b/core/lib/env_config/src/api.rs @@ -103,7 +103,7 @@ mod tests { }, prometheus: PrometheusConfig { listener_port: 3312, - pushgateway_url: "http://127.0.0.1:9091".into(), + pushgateway_url: Some("http://127.0.0.1:9091".into()), push_interval_ms: Some(100), }, healthcheck: HealthCheckConfig { diff --git a/core/lib/protobuf_config/src/utils.rs b/core/lib/protobuf_config/src/utils.rs index e528e156248b..0fd3ac20effa 100644 --- a/core/lib/protobuf_config/src/utils.rs +++ b/core/lib/protobuf_config/src/utils.rs @@ -11,9 +11,7 @@ impl ProtoRepr for proto::Prometheus { listener_port: required(&self.listener_port) .and_then(|p| Ok((*p).try_into()?)) .context("listener_port")?, - pushgateway_url: required(&self.pushgateway_url) - .context("pushgateway_url")? - .clone(), + pushgateway_url: self.pushgateway_url.clone(), push_interval_ms: self.push_interval_ms, }) } @@ -21,7 +19,7 @@ impl ProtoRepr for proto::Prometheus { fn build(this: &Self::Type) -> Self { Self { listener_port: Some(this.listener_port.into()), - pushgateway_url: Some(this.pushgateway_url.clone()), + pushgateway_url: this.pushgateway_url.clone(), push_interval_ms: this.push_interval_ms, } } diff --git a/core/tests/loadnext/src/main.rs b/core/tests/loadnext/src/main.rs index c1b6f8b725c1..7ba6e762ea26 100644 --- a/core/tests/loadnext/src/main.rs +++ b/core/tests/loadnext/src/main.rs @@ -62,16 +62,15 @@ async fn main() -> anyhow::Result<()> { let mut executor = Executor::new(config, execution_config).await?; let (stop_sender, stop_receiver) = watch::channel(false); - if let Some(prometheus_config) = prometheus_config { - let exporter_config = PrometheusExporterConfig::push( - prometheus_config.gateway_endpoint(), - prometheus_config.push_interval(), - ); - - tracing::info!("Starting prometheus exporter with config {prometheus_config:?}"); - tokio::spawn(exporter_config.run(stop_receiver)); - } else { - tracing::info!("Starting without prometheus exporter"); + match prometheus_config.map(|c| (c.gateway_endpoint(), c.push_interval())) { + Some((Some(gateway_endpoint), push_interval)) => { + tracing::info!("Starting prometheus exporter with gateway {gateway_endpoint:?} and push_interval {push_interval:?}"); + let exporter_config = PrometheusExporterConfig::push(gateway_endpoint, push_interval); + tokio::spawn(exporter_config.run(stop_receiver)); + } + _ => { + tracing::info!("Starting without prometheus exporter"); + } } let result = executor.start().await; diff --git a/prover/witness_generator/src/main.rs b/prover/witness_generator/src/main.rs index 584588291d51..1093ac853765 100644 --- a/prover/witness_generator/src/main.rs +++ b/prover/witness_generator/src/main.rs @@ -194,7 +194,9 @@ async fn main() -> anyhow::Result<()> { .clone() .context("prometheus config needed when use_push_gateway enabled")?; PrometheusExporterConfig::push( - prometheus_config.gateway_endpoint(), + prometheus_config + .gateway_endpoint() + .context("gateway_endpoint needed when use_push_gateway enabled")?, prometheus_config.push_interval(), ) } else {