diff --git a/Cargo.lock b/Cargo.lock index a7613862..60cab634 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1896,7 +1896,9 @@ dependencies = [ "clap", "eyre", "libc", + "metrics-exporter-prometheus 0.18.1", "reth", + "thiserror 2.0.17", "tokio", "tracing", ] @@ -6650,6 +6652,26 @@ dependencies = [ "tracing", ] +[[package]] +name = "metrics-exporter-prometheus" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3589659543c04c7dc5526ec858591015b87cd8746583b51b48ef4353f99dbcda" +dependencies = [ + "base64 0.22.1", + "http-body-util", + "hyper", + "hyper-util", + "indexmap 2.13.0", + "ipnet", + "metrics", + "metrics-util 0.20.1", + "quanta", + "thiserror 2.0.17", + "tokio", + "tracing", +] + [[package]] name = "metrics-process" version = "2.4.2" diff --git a/Cargo.toml b/Cargo.toml index 3b4d2312..0b1da15a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,6 +215,9 @@ vergen = "9.0.6" vergen-git2 = "1.0.7" clap = { version = "4.5.53", features = ["derive", "env", "string"] } +# Metrics +metrics-exporter-prometheus = { version = "0.18.1", default-features = false } + # misc url = "2.5.7" lru = "0.16.2" diff --git a/crates/shared/cli-utils/Cargo.toml b/crates/shared/cli-utils/Cargo.toml index e058dea6..9167608b 100644 --- a/crates/shared/cli-utils/Cargo.toml +++ b/crates/shared/cli-utils/Cargo.toml @@ -17,6 +17,8 @@ tokio = { workspace = true, features = ["full"] } eyre.workspace = true clap = { workspace = true, features = ["derive"] } tracing.workspace = true +thiserror.workspace = true +metrics-exporter-prometheus = { workspace = true, features = ["http-listener"] } [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/crates/shared/cli-utils/src/errors.rs b/crates/shared/cli-utils/src/errors.rs new file mode 100644 index 00000000..a99705a8 --- /dev/null +++ b/crates/shared/cli-utils/src/errors.rs @@ -0,0 +1,26 @@ +//! Error types for CLI utilities. + +use thiserror::Error; + +/// Errors that can occur in CLI operations. +#[derive(Error, Debug)] +pub enum CliError { + /// Error when no chain config is found for the given chain ID. + #[error("No chain config found for chain ID: {0}")] + ChainConfigNotFound(u64), + + /// Error when no roles are found for the given chain ID. + #[error("No roles found for chain ID: {0}")] + RolesNotFound(u64), + + /// Error when no unsafe block signer is found for the given chain ID. + #[error("No unsafe block signer found for chain ID: {0}")] + UnsafeBlockSignerNotFound(u64), + + /// Error initializing metrics. + #[error("Failed to initialize metrics")] + MetricsInitialization(#[from] metrics_exporter_prometheus::BuildError), +} + +/// Type alias for CLI results. +pub type CliResult = Result; diff --git a/crates/shared/cli-utils/src/lib.rs b/crates/shared/cli-utils/src/lib.rs index fe92be91..5c3b7580 100644 --- a/crates/shared/cli-utils/src/lib.rs +++ b/crates/shared/cli-utils/src/lib.rs @@ -9,6 +9,9 @@ pub use sigsegv::SigsegvHandler; mod backtrace; pub use backtrace::Backtracing; +mod errors; +pub use errors::{CliError, CliResult}; + mod args; pub use args::GlobalArgs;