Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(node-core/matrics): refactor the register version metrics function #9149

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 33 additions & 11 deletions crates/node-core/src/metrics/version_metrics.rs
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • debug +clone

version: &str,
build_timestamp: &str,
cargo_features: &str,
git_sha: &str,
target_triple: &str,
build_profile: &str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make these pub?

if we extract metrics from node-core we'd need this as input I believe so makes sense to make these pub

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it makes sense

}

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this a function of versioninfo instead?

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);
}