diff --git a/crates/katana/node/src/lib.rs b/crates/katana/node/src/lib.rs index 5c3e6b29bf..5cefd5dcb1 100644 --- a/crates/katana/node/src/lib.rs +++ b/crates/katana/node/src/lib.rs @@ -8,6 +8,7 @@ use std::sync::Arc; use std::time::Duration; use anyhow::Result; +use dojo_metrics::prometheus_exporter::PrometheusHandle; use dojo_metrics::{metrics_process, prometheus_exporter, Report}; use hyper::{Method, Uri}; use jsonrpsee::server::middleware::proxy_get_request::ProxyGetRequestLayer; @@ -88,6 +89,7 @@ pub struct Node { pub pool: TxPool, pub db: Option, pub task_manager: TaskManager, + pub prometheus_handle: PrometheusHandle, pub backend: Arc>, pub block_producer: BlockProducer, pub server_config: ServerConfig, @@ -100,20 +102,15 @@ impl Node { /// /// This method will start all the node process, running them until the node is stopped. pub async fn launch(self) -> Result { - // Metrics recorder must be initialized before calling any of the metrics macros, in order - // for it to be registered. - if let Some(addr) = self.server_config.metrics { - let prometheus_handle = prometheus_exporter::install_recorder("katana")?; let mut reports = Vec::new(); - if let Some(ref db) = self.db { reports.push(Box::new(db.clone()) as Box); } prometheus_exporter::serve( addr, - prometheus_handle, + self.prometheus_handle.clone(), metrics_process::Collector::default(), reports, ) @@ -167,6 +164,10 @@ pub async fn build( sequencer_config: SequencerConfig, mut starknet_config: StarknetConfig, ) -> Result { + // Metrics recorder must be initialized before calling any of the metrics macros, in order + // for it to be registered. + let prometheus_handle = prometheus_exporter::install_recorder("katana")?; + // --- build executor factory let cfg_env = CfgEnv { @@ -279,6 +280,7 @@ pub async fn build( server_config, block_producer, sequencer_config, + prometheus_handle, task_manager: TaskManager::current(), }; diff --git a/crates/metrics/src/prometheus_exporter.rs b/crates/metrics/src/prometheus_exporter.rs index a84f9a9e55..deaa9a0133 100644 --- a/crates/metrics/src/prometheus_exporter.rs +++ b/crates/metrics/src/prometheus_exporter.rs @@ -9,7 +9,8 @@ use anyhow::{Context, Result}; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Request, Response, Server}; use metrics::{describe_gauge, gauge}; -use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle}; +use metrics_exporter_prometheus::PrometheusBuilder; +pub use metrics_exporter_prometheus::PrometheusHandle; use metrics_util::layers::{PrefixLayer, Stack}; use crate::Report;