From ad96477e82a1fb93fb010864148af5e2d2336359 Mon Sep 17 00:00:00 2001 From: yagagagaga Date: Tue, 17 Dec 2024 21:49:06 +0800 Subject: [PATCH] [chore](version) Show binary version in metrics: fe be ms (#45490) before ``` root@af0e5d234e63:~# curl 127.0.0.1:8030/metrics | grep doris_fe_version root@af0e5d234e63:~# curl 127.0.0.1:8060/brpc_metrics | grep doris_be_version root@af0e5d234e63:~# curl 127.0.0.1:5000/brpc_metrics | grep doris_cloud_version ``` after ``` [root@dbb7fecb3b61 output]# curl 127.0.0.1:8030/metrics | grep doris_fe_version # TYPE doris_fe_version gauge doris_fe_version 30004 [root@dbb7fecb3b61 output]# curl 127.0.0.1:8060/brpc_metrics | grep doris_be_version # TYPE doris_be_version gauge doris_be_version 30004 [root@dbb7fecb3b61 output]# curl 127.0.0.1:5000/brpc_metrics | grep doris_cloud_version # TYPE doris_cloud_version gauge doris_cloud_version 30004 ``` Co-authored-by: Gavin Chou (cherry picked from commit 038dd93f4d5e667813240fc839a2cc4ea86157ce) --- be/src/common/version_internal.cpp | 5 ++++- be/src/common/version_internal.h | 3 ++- be/src/util/debug_util.cpp | 11 ++++++++++ cloud/src/main.cpp | 3 +++ .../org/apache/doris/metric/MetricRepo.java | 20 +++++++++++++++++++ gensrc/script/gen_build_version.sh | 15 +++++++++++++- 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/be/src/common/version_internal.cpp b/be/src/common/version_internal.cpp index 1190242b6aa687..55402fab209400 100644 --- a/be/src/common/version_internal.cpp +++ b/be/src/common/version_internal.cpp @@ -34,6 +34,9 @@ int doris_build_version_minor() { int doris_build_version_patch() { return DORIS_BUILD_VERSION_PATCH; } +int doris_build_version_hotfix() { + return DORIS_BUILD_VERSION_HOTFIX; +} const char* doris_build_version_rc_version() { return DORIS_BUILD_VERSION_RC_VERSION; } @@ -56,4 +59,4 @@ const char* doris_build_info() { } // namespace version -} // namespace doris \ No newline at end of file +} // namespace doris diff --git a/be/src/common/version_internal.h b/be/src/common/version_internal.h index 8852d26dba9531..f4deaa15aff545 100644 --- a/be/src/common/version_internal.h +++ b/be/src/common/version_internal.h @@ -24,6 +24,7 @@ extern const char* doris_build_version_prefix(); extern int doris_build_version_major(); extern int doris_build_version_minor(); extern int doris_build_version_patch(); +extern int doris_build_version_hotfix(); extern const char* doris_build_version_rc_version(); extern const char* doris_build_version(); @@ -34,4 +35,4 @@ extern const char* doris_build_info(); } // namespace version -} // namespace doris \ No newline at end of file +} // namespace doris diff --git a/be/src/util/debug_util.cpp b/be/src/util/debug_util.cpp index 1cf03d2c22d0e1..0856b10c051709 100644 --- a/be/src/util/debug_util.cpp +++ b/be/src/util/debug_util.cpp @@ -17,6 +17,7 @@ #include "util/debug_util.h" +#include #include #include #include @@ -104,6 +105,16 @@ std::string hexdump(const char* buf, int len) { return ss.str(); } +bvar::Status be_version_metrics("doris_be_version", [] { + std::stringstream ss; + ss << version::doris_build_version_major() << 0 << version::doris_build_version_minor() << 0 + << version::doris_build_version_patch(); + if (version::doris_build_version_hotfix() > 0) { + ss << 0 << version::doris_build_version_hotfix(); + } + return std::strtoul(ss.str().c_str(), nullptr, 10); +}()); + std::string PrintThriftNetworkAddress(const TNetworkAddress& add) { std::stringstream ss; add.printTo(ss); diff --git a/cloud/src/main.cpp b/cloud/src/main.cpp index 74e6a8daaf161c..26033cdaad2a07 100644 --- a/cloud/src/main.cpp +++ b/cloud/src/main.cpp @@ -150,6 +150,9 @@ bvar::Status doris_cloud_version_metrics("doris_cloud_version", [] { std::stringstream ss; ss << DORIS_CLOUD_BUILD_VERSION_MAJOR << 0 << DORIS_CLOUD_BUILD_VERSION_MINOR << 0 << DORIS_CLOUD_BUILD_VERSION_PATCH; + if (DORIS_CLOUD_BUILD_VERSION_HOTFIX > 0) { + ss << 0 << DORIS_CLOUD_BUILD_VERSION_HOTFIX; + } return std::strtoul(ss.str().c_str(), nullptr, 10); }()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java b/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java index 86741758250e84..783872faf1988c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/metric/MetricRepo.java @@ -24,6 +24,7 @@ import org.apache.doris.common.Config; import org.apache.doris.common.Pair; import org.apache.doris.common.ThreadPoolManager; +import org.apache.doris.common.Version; import org.apache.doris.common.util.NetUtils; import org.apache.doris.load.EtlJobType; import org.apache.doris.load.loadv2.JobState; @@ -156,6 +157,25 @@ public static synchronized void init() { return; } + // version + GaugeMetric feVersion = new GaugeMetric("version", MetricUnit.NOUNIT, "") { + @Override + public Long getValue() { + try { + return Long.parseLong("" + Version.DORIS_BUILD_VERSION_MAJOR + "0" + + Version.DORIS_BUILD_VERSION_MINOR + "0" + + Version.DORIS_BUILD_VERSION_PATCH + + (Version.DORIS_BUILD_VERSION_HOTFIX > 0 + ? ("0" + Version.DORIS_BUILD_VERSION_HOTFIX) + : "")); + } catch (Throwable t) { + LOG.warn("failed to init version metrics", t); + return 0L; + } + } + }; + DORIS_METRIC_REGISTER.addMetrics(feVersion); + // load jobs for (EtlJobType jobType : EtlJobType.values()) { if (jobType == EtlJobType.UNKNOWN) { diff --git a/gensrc/script/gen_build_version.sh b/gensrc/script/gen_build_version.sh index abc38306ee44f5..08ee262e92ba81 100755 --- a/gensrc/script/gen_build_version.sh +++ b/gensrc/script/gen_build_version.sh @@ -31,9 +31,14 @@ build_version_prefix="doris" build_version_major=3 build_version_minor=0 build_version_patch=3 +build_version_hotfix=0 build_version_rc_version="rc03" -build_version="${build_version_prefix}-${build_version_major}.${build_version_minor}.${build_version_patch}-${build_version_rc_version}" +build_version="${build_version_prefix}-${build_version_major}.${build_version_minor}.${build_version_patch}" +if [[ ${build_version_hotfix} > 0 ]]; then + build_version+=".${build_version_hotfix}" +fi +build_version+="-${build_version_rc_version}" # This version is used to check FeMetaVersion is not changed during release build_fe_meta_version=0 @@ -125,6 +130,7 @@ public class Version { public static final int DORIS_BUILD_VERSION_MAJOR = ${build_version_major}; public static final int DORIS_BUILD_VERSION_MINOR = ${build_version_minor}; public static final int DORIS_BUILD_VERSION_PATCH = ${build_version_patch}; + public static final int DORIS_BUILD_VERSION_HOTFIX = ${build_version_hotfix}; public static final String DORIS_BUILD_VERSION_RC_VERSION = "${build_version_rc_version}"; public static final String DORIS_BUILD_VERSION = "${build_version}"; @@ -186,6 +192,7 @@ namespace doris { #define DORIS_BUILD_VERSION_MAJOR ${build_version_major}; #define DORIS_BUILD_VERSION_MINOR ${build_version_minor}; #define DORIS_BUILD_VERSION_PATCH ${build_version_patch}; +#define DORIS_BUILD_VERSION_HOTFIX ${build_version_hotfix}; #define DORIS_BUILD_VERSION_RC_VERSION "${build_version_rc_version}"; #define DORIS_BUILD_VERSION "${build_version}" @@ -207,6 +214,7 @@ EOF # build_version_major=0 # build_version_minor=0 # build_version_patch=0 +# build_version_hotfix=0 # build_version_rc_version="" if [[ -f /etc/os-release ]]; then @@ -217,6 +225,10 @@ fi build_version="${build_version_prefix}-${build_version_major}.${build_version_minor}.${build_version_patch}" +if [[ ${build_version_hotfix} > 0 ]]; then + build_version+=".${build_version_hotfix}" +fi + if [[ "${build_version_rc_version}" != "" ]]; then build_version=${build_version}"-${build_version_rc_version}" fi @@ -247,6 +259,7 @@ namespace doris::cloud { #define DORIS_CLOUD_BUILD_VERSION_MAJOR ${build_version_major} #define DORIS_CLOUD_BUILD_VERSION_MINOR ${build_version_minor} #define DORIS_CLOUD_BUILD_VERSION_PATCH ${build_version_patch} +#define DORIS_CLOUD_BUILD_VERSION_HOTFIX ${build_version_hotfix} #define DORIS_CLOUD_BUILD_VERSION_RC_VERSION R"(${build_version_rc_version})" #define DORIS_CLOUD_BUILD_VERSION R"(${build_version})"