Skip to content

Commit

Permalink
refactor: refactor the register version metrics function
Browse files Browse the repository at this point in the history
  • Loading branch information
kien6034 committed Jun 27, 2024
1 parent 9542f3b commit 72f74b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/node-core/src/metrics/prometheus_exporter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Prometheus exporter
use crate::metrics::version_metrics::register_version_metrics;
use crate::metrics::version_metrics::{register_version_metrics, VersionInfo};
use eyre::WrapErr;
use futures::{future::FusedFuture, FutureExt};
use http::Response;
Expand Down Expand Up @@ -151,7 +151,7 @@ where
process.describe();
describe_memory_stats();
describe_io_stats();
register_version_metrics();
register_version_metrics(VersionInfo::default());

Ok(())
}
Expand Down
42 changes: 32 additions & 10 deletions crates/node-core/src/metrics/version_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,38 @@
use crate::version::build_profile_name;
use metrics::gauge;

const LABELS: [(&str, &str); 6] = [
("version", env!("CARGO_PKG_VERSION")),
("build_timestamp", env!("VERGEN_BUILD_TIMESTAMP")),
("cargo_features", env!("VERGEN_CARGO_FEATURES")),
("git_sha", env!("VERGEN_GIT_SHA")),
("target_triple", env!("VERGEN_CARGO_TARGET_TRIPLE")),
("build_profile", build_profile_name()),
];
pub struct VersionInfo {
version: &str,
build_timestamp: &str,
cargo_features: &str,
git_sha: &str,
target_triple: &str,
build_profile: &str,
}

impl Default for VersionInfo {
fn default() -> Self {
VersionInfo {
version: env!("CARGO_PKG_VERSION"),
build_timestamp: env!("VERGEN_BUILD_TIMESTAMP"),
cargo_features: env!("VERGEN_CARGO_FEATURES"),
git_sha: env!("VERGEN_GIT_SHA"),
target_triple: env!("VERGEN_CARGO_TARGET_TRIPLE"),
build_profile: build_profile_name(),
}
}
}

/// This exposes reth's version information over prometheus.
pub fn register_version_metrics() {
let _gauge = gauge!("info", &LABELS);
pub fn register_version_metrics(version_info: VersionInfo) {
let labels: [(&str, &str); 6] = [
("version", version_info.version),
("build_timestamp", version_info.build_timestamp),
("cargo_features", version_info.cargo_features),
("git_sha", version_info.git_sha),
("target_triple", version_info.target_triple),
("build_profile", version_info.build_profile),
];

let _gauge = gauge!("info", &labels);
}

0 comments on commit 72f74b4

Please sign in to comment.