From 548f0d1e2a94fad0e80280d91c4da29fc3ad70ed Mon Sep 17 00:00:00 2001 From: Yingwen Date: Thu, 1 Jun 2023 14:31:08 +0800 Subject: [PATCH] feat: Add app version metric (#1685) * feat: Add app version metric * chore: use greptimedb instead of greptime --- Cargo.lock | 1 + src/cmd/Cargo.toml | 1 + src/cmd/build.rs | 4 ++++ src/cmd/src/bin/greptime.rs | 20 ++++++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1f3564a2a7..2d2ff00782 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1587,6 +1587,7 @@ dependencies = [ "futures", "meta-client", "meta-srv", + "metrics", "nu-ansi-term", "partition", "query", diff --git a/src/cmd/Cargo.toml b/src/cmd/Cargo.toml index 1e82a0a9ee..7fe90729b3 100644 --- a/src/cmd/Cargo.toml +++ b/src/cmd/Cargo.toml @@ -32,6 +32,7 @@ frontend = { path = "../frontend" } futures.workspace = true meta-client = { path = "../meta-client" } meta-srv = { path = "../meta-srv" } +metrics.workspace = true nu-ansi-term = "0.46" partition = { path = "../partition" } query = { path = "../query" } diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 1a32b5376b..d141625b65 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -18,6 +18,10 @@ fn main() { "cargo:rustc-env=GIT_COMMIT={}", build_data::get_git_commit().unwrap_or_else(|_| DEFAULT_VALUE.to_string()) ); + println!( + "cargo:rustc-env=GIT_COMMIT_SHORT={}", + build_data::get_git_commit_short().unwrap_or_else(|_| DEFAULT_VALUE.to_string()) + ); println!( "cargo:rustc-env=GIT_BRANCH={}", build_data::get_git_branch().unwrap_or_else(|_| DEFAULT_VALUE.to_string()) diff --git a/src/cmd/src/bin/greptime.rs b/src/cmd/src/bin/greptime.rs index 36448d5661..98207491fc 100644 --- a/src/cmd/src/bin/greptime.rs +++ b/src/cmd/src/bin/greptime.rs @@ -21,6 +21,7 @@ use cmd::error::Result; use cmd::options::{Options, TopLevelOptions}; use cmd::{cli, datanode, frontend, metasrv, standalone}; use common_telemetry::logging::{error, info, TracingOptions}; +use metrics::gauge; #[derive(Parser)] #[clap(name = "greptimedb", version = print_version())] @@ -163,6 +164,22 @@ fn print_version() -> &'static str { ) } +fn short_version() -> &'static str { + env!("CARGO_PKG_VERSION") +} + +// {app_name}-{branch_name}-{commit_short} +// The branch name (tag) of a release build should already contain the short +// version so the full version doesn't concat the short version explicitly. +fn full_version() -> &'static str { + concat!( + "greptimedb-", + env!("GIT_BRANCH"), + "-", + env!("GIT_COMMIT_SHORT") + ) +} + #[cfg(feature = "mem-prof")] #[global_allocator] static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; @@ -185,6 +202,9 @@ async fn main() -> Result<()> { common_telemetry::init_default_metrics_recorder(); let _guard = common_telemetry::init_global_logging(app_name, logging_opts, tracing_opts); + // Report app version as gauge. + gauge!("app_version", 1.0, "short_version" => short_version(), "version" => full_version()); + let mut app = cmd.build(opts).await?; tokio::select! {