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

fix(common_version): short_version with empty branch #4572

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
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
}
}