-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor the register version metrics function
- Loading branch information
Showing
2 changed files
with
35 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
//! This exposes reth's version information over prometheus. | ||
use crate::version::{build_profile_name, VERGEN_GIT_SHA}; | ||
use crate::version::{ build_profile_name, VERGEN_GIT_SHA }; | ||
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", 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); | ||
} |