This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new e1a280a893e [feature](metric):add labels for metric doris_fe_version 
(#53614)
e1a280a893e is described below

commit e1a280a893ef957ef3fa5ead70fc2aba55e8bea1
Author: htyoung <[email protected]>
AuthorDate: Wed Jul 30 06:32:55 2025 +0800

    [feature](metric):add labels for metric doris_fe_version (#53614)
---
 .../java/org/apache/doris/metric/MetricRepo.java   | 28 +++++++++++++---------
 gensrc/script/gen_build_version.sh                 |  4 +++-
 .../suites/metrics_p0/test_version_metrics.groovy  | 11 +++++++--
 3 files changed, 29 insertions(+), 14 deletions(-)

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 ee39f8e90f4..84bfc10093a 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
@@ -191,11 +191,11 @@ public final class MetricRepo {
 
     private static Map<Pair<EtlJobType, JobState>, Long> loadJobNum = 
Maps.newHashMap();
 
-    private static ScheduledThreadPoolExecutor metricTimer = 
ThreadPoolManager.newDaemonScheduledThreadPool(1,
+    private static final ScheduledThreadPoolExecutor metricTimer = 
ThreadPoolManager.newDaemonScheduledThreadPool(1,
             "metric-timer-pool", true);
-    private static MetricCalculator metricCalculator = new MetricCalculator();
+    private static final MetricCalculator metricCalculator = new 
MetricCalculator();
 
-    // init() should only be called after catalog is contructed.
+    // init() should only be called after catalog is constructed.
     public static synchronized void init() {
         if (isInit) {
             return;
@@ -206,18 +206,24 @@ public final class MetricRepo {
             @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)
-                                                : ""));
+                    String verStr = Version.DORIS_BUILD_VERSION_MAJOR + "0" + 
Version.DORIS_BUILD_VERSION_MINOR + "0"
+                            + Version.DORIS_BUILD_VERSION_PATCH;
+                    if (Version.DORIS_BUILD_VERSION_HOTFIX > 0) {
+                        verStr += ("0" + Version.DORIS_BUILD_VERSION_HOTFIX);
+                    }
+                    return Long.parseLong(verStr);
                 } catch (Throwable t) {
                     LOG.warn("failed to init version metrics", t);
                     return 0L;
                 }
             }
         };
+        feVersion.addLabel(new MetricLabel("version", 
Version.DORIS_BUILD_VERSION));
+        feVersion.addLabel(new MetricLabel("major", 
String.valueOf(Version.DORIS_BUILD_VERSION_MAJOR)));
+        feVersion.addLabel(new MetricLabel("minor", 
String.valueOf(Version.DORIS_BUILD_VERSION_MINOR)));
+        feVersion.addLabel(new MetricLabel("patch", 
String.valueOf(Version.DORIS_BUILD_VERSION_PATCH)));
+        feVersion.addLabel(new MetricLabel("hotfix", 
String.valueOf(Version.DORIS_BUILD_VERSION_HOTFIX)));
+        feVersion.addLabel(new MetricLabel("short_hash", 
Version.DORIS_BUILD_SHORT_HASH));
         DORIS_METRIC_REGISTER.addMetrics(feVersion);
 
         // load jobs
@@ -362,14 +368,14 @@ public final class MetricRepo {
                 "total query from hive table");
         DORIS_METRIC_REGISTER.addMetrics(COUNTER_QUERY_HIVE_TABLE);
         USER_COUNTER_QUERY_ALL = new AutoMappedMetric<>(name -> {
-            LongCounterMetric userCountQueryAll  = new 
LongCounterMetric("query_total", MetricUnit.REQUESTS,
+            LongCounterMetric userCountQueryAll = new 
LongCounterMetric("query_total", MetricUnit.REQUESTS,
                     "total query for single user");
             userCountQueryAll.addLabel(new MetricLabel("user", name));
             DORIS_METRIC_REGISTER.addMetrics(userCountQueryAll);
             return userCountQueryAll;
         });
         USER_COUNTER_QUERY_ERR = new AutoMappedMetric<>(name -> {
-            LongCounterMetric userCountQueryErr  = new 
LongCounterMetric("query_err", MetricUnit.REQUESTS,
+            LongCounterMetric userCountQueryErr = new 
LongCounterMetric("query_err", MetricUnit.REQUESTS,
                     "total error query for single user");
             userCountQueryErr.addLabel(new MetricLabel("user", name));
             DORIS_METRIC_REGISTER.addMetrics(userCountQueryErr);
diff --git a/gensrc/script/gen_build_version.sh 
b/gensrc/script/gen_build_version.sh
index 6b685219968..3c2dd548ab8 100755
--- a/gensrc/script/gen_build_version.sh
+++ b/gensrc/script/gen_build_version.sh
@@ -38,7 +38,9 @@ 
build_version="${build_version_prefix}-${build_version_major}.${build_version_mi
 if [[ ${build_version_hotfix} -gt 0 ]]; then
     build_version+=".${build_version_hotfix}"
 fi
-build_version+="-${build_version_rc_version}"
+if [[ -n "${build_version_rc_version}" ]]; then
+    build_version+="-${build_version_rc_version}"
+fi
 
 # This version is used to check FeMetaVersion is not changed during release
 build_fe_meta_version=0
diff --git a/regression-test/suites/metrics_p0/test_version_metrics.groovy 
b/regression-test/suites/metrics_p0/test_version_metrics.groovy
index 51f6cc8539d..e6625f698ea 100644
--- a/regression-test/suites/metrics_p0/test_version_metrics.groovy
+++ b/regression-test/suites/metrics_p0/test_version_metrics.groovy
@@ -1,3 +1,6 @@
+import java.util.regex.Matcher
+import java.util.regex.Pattern
+
 // Licensed to the Apache Software Foundation (ASF) under one
 // or more contributor license agreements.  See the NOTICE file
 // distributed with this work for additional information
@@ -25,8 +28,12 @@ suite("test_version_metrics") {
             assertEquals(200, code)
             assertTrue(body.contains("doris_fe_version"))
             for (final def line in body.split("\n")) {
-                if (line.contains("doris_fe_version") && !line.contains("#")) {
-                    assertTrue(Long.parseLong(line.split(" ")[1]) >= 0)
+                if (line.startsWith("doris_fe_version")) {
+                    Pattern pattern = 
Pattern.compile(/^doris_fe_version\{.*}\s+(\d+)$/)
+                    Matcher matcher = pattern.matcher(line)
+                    assertTrue(matcher.matches())
+                    assertTrue(Long.parseLong(matcher.group(1)) >= 0)
+                    break
                 }
             }
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to