Skip to content

Commit

Permalink
fix(common_version): short_version with empty branch (#4572)
Browse files Browse the repository at this point in the history
  • Loading branch information
leaf-potato authored Aug 19, 2024
1 parent c8de8b8 commit 2a73e09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod standalone;

lazy_static::lazy_static! {
static ref APP_VERSION: prometheus::IntGaugeVec =
prometheus::register_int_gauge_vec!("greptime_app_version", "app version", &["short_version", "version"]).unwrap();
prometheus::register_int_gauge_vec!("greptime_app_version", "app version", &["version", "short_version"]).unwrap();
}

#[async_trait]
Expand Down Expand Up @@ -74,16 +74,16 @@ pub trait App: Send {
}

/// Log the versions of the application, and the arguments passed to the cli.
/// `version_string` should be the same as the output of cli "--version";
/// and the `app_version` is the short version of the codes, often consist of git branch and commit.
pub fn log_versions(version_string: &str, app_version: &str) {
/// `version` should be the same as the output of cli "--version";
/// and the `short_version` is the short version of the codes, often consist of git branch and commit.
pub fn log_versions(version: &str, short_version: &str) {
// Report app version as gauge.
APP_VERSION
.with_label_values(&[env!("CARGO_PKG_VERSION"), app_version])
.with_label_values(&[env!("CARGO_PKG_VERSION"), short_version])
.inc();

// Log version and argument flags.
info!("GreptimeDB version: {}", version_string);
info!("GreptimeDB version: {}", version);

log_env_flags();
}
Expand Down
11 changes: 10 additions & 1 deletion src/common/version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,14 @@ pub const fn version() -> &'static str {
}

pub const fn short_version() -> &'static str {
const_format::formatcp!("{}-{}", BUILD_INFO.branch, BUILD_INFO.commit_short,)
const BRANCH: &str = BUILD_INFO.branch;
const COMMIT_ID: &str = BUILD_INFO.commit_short;

// When git checkout to a commit, the branch is empty.
#[allow(clippy::const_is_empty)]
if !BRANCH.is_empty() {
const_format::formatcp!("{}-{}", BRANCH, COMMIT_ID)
} else {
COMMIT_ID
}
}

0 comments on commit 2a73e09

Please sign in to comment.