Skip to content

feat: add commit message and author in version metrics #236

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 20 additions & 3 deletions crates/op-rbuilder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ fn main() -> Result<(), Box<dyn Error>> {
.describe(false, true, None)
.dirty(true)
.sha(false)
.commit_author_name(true)
.commit_author_email(true)
.commit_message(true)
.build()?;

emitter.add_instructions(&git_builder)?;
Expand All @@ -51,6 +54,16 @@ fn main() -> Result<(), Box<dyn Error>> {
let sha = env::var("VERGEN_GIT_SHA")?;
let sha_short = &sha[0..7];

// Set short SHA
println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]);

let author_name = env::var("VERGEN_GIT_COMMIT_AUTHOR_NAME")?;
let author_email = env::var("VERGEN_GIT_COMMIT_AUTHOR_EMAIL")?;
let author_full = format!("{} <{}>", author_name, author_email);

// Set author full name
println!("cargo:rustc-env=VERGEN_GIT_COMMIT_AUTHOR={}", author_full);

let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true";
// > git describe --always --tags
// if not on a tag: v0.2.0-beta.3-82-g1939939b
Expand All @@ -59,9 +72,6 @@ fn main() -> Result<(), Box<dyn Error>> {
let version_suffix = if is_dirty || not_on_tag { "-dev" } else { "" };
println!("cargo:rustc-env=OP_RBUILDER_VERSION_SUFFIX={version_suffix}");

// Set short SHA
println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]);

// Set the build profile
let out_dir = env::var("OUT_DIR").unwrap();
let profile = out_dir.rsplit(std::path::MAIN_SEPARATOR).nth(3).unwrap();
Expand All @@ -86,6 +96,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// - The build datetime
// - The build features
// - The build profile
// - The latest commit message and author
//
// Example:
//
Expand All @@ -95,6 +106,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Build Timestamp: 2023-05-19T01:47:19.815651705Z
// Build Features: jemalloc
// Build Profile: maxperf
// Latest Commit: 'message' by John Doe <[email protected]>
// ```
println!("cargo:rustc-env=OP_RBUILDER_LONG_VERSION_0=Version: {pkg_version}{version_suffix}");
println!("cargo:rustc-env=OP_RBUILDER_LONG_VERSION_1=Commit SHA: {sha}");
Expand All @@ -107,6 +119,11 @@ fn main() -> Result<(), Box<dyn Error>> {
env::var("VERGEN_CARGO_FEATURES")?
);
println!("cargo:rustc-env=OP_RBUILDER_LONG_VERSION_4=Build Profile: {profile}");
println!(
"cargo:rustc-env=OP_RBUILDER_LONG_VERSION_5=Latest Commit: '{}' by {}",
env::var("VERGEN_GIT_COMMIT_MESSAGE")?.trim_end(),
author_full
);

// The version information for op-rbuilder formatted for P2P (devp2p).
// - The latest version from Cargo.toml
Expand Down
18 changes: 16 additions & 2 deletions crates/op-rbuilder/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub const VERGEN_CARGO_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
/// The build features.
pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES");

/// The latest commit message and author name and email.
pub const VERGEN_GIT_AUTHOR: &str = env!("VERGEN_GIT_COMMIT_AUTHOR");
pub const VERGEN_GIT_COMMIT_MESSAGE: &str = env!("VERGEN_GIT_COMMIT_MESSAGE");

/// The build profile name.
pub const BUILD_PROFILE_NAME: &str = env!("OP_RBUILDER_BUILD_PROFILE");

Expand All @@ -38,6 +42,8 @@ pub const LONG_VERSION: &str = concat!(
env!("OP_RBUILDER_LONG_VERSION_3"),
"\n",
env!("OP_RBUILDER_LONG_VERSION_4"),
"\n",
env!("OP_RBUILDER_LONG_VERSION_5"),
);

pub const VERSION: VersionInfo = VersionInfo {
Expand All @@ -47,6 +53,8 @@ pub const VERSION: VersionInfo = VersionInfo {
git_sha: VERGEN_GIT_SHA,
target_triple: VERGEN_CARGO_TARGET_TRIPLE,
build_profile: BUILD_PROFILE_NAME,
commit_author: VERGEN_GIT_AUTHOR,
commit_message: VERGEN_GIT_COMMIT_MESSAGE,
};

/// op-rbuilder metrics
Expand Down Expand Up @@ -198,18 +206,24 @@ pub struct VersionInfo {
pub target_triple: &'static str,
/// The build profile (e.g., debug or release).
pub build_profile: &'static str,
/// The author of the latest commit.
pub commit_author: &'static str,
/// The message of the latest commit.
pub commit_message: &'static str,
}

impl VersionInfo {
/// This exposes reth's version information over prometheus.
/// This exposes op-rbuilder's version information over prometheus.
pub fn register_version_metrics(&self) {
let labels: [(&str, &str); 6] = [
let labels: [(&str, &str); 8] = [
("version", self.version),
("build_timestamp", self.build_timestamp),
("cargo_features", self.cargo_features),
("git_sha", self.git_sha),
("target_triple", self.target_triple),
("build_profile", self.build_profile),
("commit_author", self.commit_author),
("commit_message", self.commit_message),
];

let gauge = gauge!("builder_info", &labels);
Expand Down
Loading