|
2 | 2 |
|
3 | 3 | use std::{fs::File, path::PathBuf, sync::Arc, time::Duration}; |
4 | 4 |
|
5 | | -use base_cli_utils::{CliStyles, GlobalArgs, LogConfig, MetricsArgs}; |
| 5 | +use base_cli_utils::{CliStyles, GlobalArgs, LogConfig, RuntimeManager}; |
6 | 6 | use base_client_cli::{ |
7 | 7 | BuilderClientArgs, JwtSecret, L1ClientArgs, L2ClientArgs, P2PArgs, RollupBoostFlags, RpcArgs, |
8 | 8 | SequencerArgs, |
@@ -89,10 +89,18 @@ impl Cli { |
89 | 89 | Self::init_logs(&self.global)?; |
90 | 90 |
|
91 | 91 | // Initialize unified metrics |
92 | | - Self::init_metrics(&self.global.metrics)?; |
| 92 | + self.global.metrics.init_with(|| { |
| 93 | + kona_gossip::Metrics::init(); |
| 94 | + kona_disc::Metrics::init(); |
| 95 | + kona_engine::Metrics::init(); |
| 96 | + kona_node_service::Metrics::init(); |
| 97 | + kona_derive::Metrics::init(); |
| 98 | + kona_providers_alloy::Metrics::init(); |
| 99 | + version::VersionInfo::from_build().register_version_metrics(); |
| 100 | + })?; |
93 | 101 |
|
94 | 102 | // Run the subcommand. |
95 | | - Self::run_until_ctrl_c(self.exec(&self.global)) |
| 103 | + RuntimeManager::run_until_ctrl_c(self.exec(&self.global)) |
96 | 104 | } |
97 | 105 |
|
98 | 106 | /// Run the Node subcommand. |
@@ -241,45 +249,4 @@ impl Cli { |
241 | 249 | LogConfig::new(args.logging.clone()).init_tracing_subscriber(Some(filter))?; |
242 | 250 | Ok(()) |
243 | 251 | } |
244 | | - |
245 | | - /// Initializes metrics for a Kona application, including Prometheus and node-specific metrics. |
246 | | - /// Initialize the tracing stack and Prometheus metrics recorder. |
247 | | - /// |
248 | | - /// This function should be called at the beginning of the program. |
249 | | - pub fn init_metrics(args: &MetricsArgs) -> eyre::Result<()> { |
250 | | - args.init_metrics()?; |
251 | | - if args.enabled { |
252 | | - kona_gossip::Metrics::init(); |
253 | | - kona_disc::Metrics::init(); |
254 | | - kona_engine::Metrics::init(); |
255 | | - kona_node_service::Metrics::init(); |
256 | | - kona_derive::Metrics::init(); |
257 | | - kona_providers_alloy::Metrics::init(); |
258 | | - version::VersionInfo::from_build().register_version_metrics(); |
259 | | - } |
260 | | - Ok(()) |
261 | | - } |
262 | | - |
263 | | - /// Run until ctrl-c is pressed. |
264 | | - pub fn run_until_ctrl_c<F>(fut: F) -> eyre::Result<()> |
265 | | - where |
266 | | - F: std::future::Future<Output = eyre::Result<()>>, |
267 | | - { |
268 | | - let rt = Self::tokio_runtime().map_err(|e| eyre::eyre!(e))?; |
269 | | - rt.block_on(async move { |
270 | | - tokio::select! { |
271 | | - res = fut => res, |
272 | | - _ = tokio::signal::ctrl_c() => { |
273 | | - tracing::info!(target: "cli", "Received Ctrl-C, shutting down..."); |
274 | | - Ok(()) |
275 | | - } |
276 | | - } |
277 | | - }) |
278 | | - } |
279 | | - |
280 | | - /// Creates a new default tokio multi-thread [Runtime](tokio::runtime::Runtime) with all |
281 | | - /// features enabled |
282 | | - pub fn tokio_runtime() -> Result<tokio::runtime::Runtime, std::io::Error> { |
283 | | - tokio::runtime::Builder::new_multi_thread().enable_all().build() |
284 | | - } |
285 | 252 | } |
0 commit comments