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

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new f8433f9e0fe branch-3.1: [test](metric)add meta-serivce metric format 
check #53649 (#54046)
f8433f9e0fe is described below

commit f8433f9e0fea3438f54ea07a9f37546fcef76b8d
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jul 30 15:42:08 2025 +0800

    branch-3.1: [test](metric)add meta-serivce metric format check #53649 
(#54046)
    
    Cherry-picked from #53649
    
    Co-authored-by: koarz <[email protected]>
---
 .../doris/regression/util/PromethuesChecker.groovy | 75 ++++++++++++++++++++++
 .../suites/cloud_p0/test_metrics_format.groovy     | 41 ++++++++++++
 2 files changed, 116 insertions(+)

diff --git 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/util/PromethuesChecker.groovy
 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/util/PromethuesChecker.groovy
new file mode 100644
index 00000000000..8a45052fb7f
--- /dev/null
+++ 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/util/PromethuesChecker.groovy
@@ -0,0 +1,75 @@
+// 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
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.regression.util
+
+import groovy.transform.CompileStatic
+import java.util.regex.Matcher
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+@CompileStatic
+class PromethuesChecker {
+    private static final Logger log = 
LoggerFactory.getLogger(PromethuesChecker.class)
+
+    static boolean regexp(String s) {
+        if (s == null) return false
+        s =~ 
/^[a-zA-Z_][a-zA-Z0-9_]*(\{[a-zA-Z_][a-zA-Z0-9_]*="[^"]+"(,[a-zA-Z_][a-zA-Z0-9_]*="[^"]+")*\})?\s+-?([0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?)$/
+    }
+
+    static boolean check(String str) {
+        // counter gauge summary histogram
+        String type = ""
+        if (str == null || str.trim().isEmpty()) return false
+
+        def lines = str.split('\n')
+        boolean allValid = true
+
+        for (String line : lines) {
+            line = line.trim()
+            if (line.isEmpty()) continue
+            if (line.startsWith("# HELP ")) continue
+
+            if (line.startsWith("# TYPE ")) {
+                def matcher = (line =~ /^# 
TYPE\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+(counter|gauge|histogram|summary)$/) as 
Matcher
+                if (matcher.matches()) {
+                    type = matcher.group(2)?.toLowerCase()
+                } else {
+                    allValid = false
+                }
+            } else {
+                switch (type) {
+                    case "counter":
+                    case "gauge":
+                    case "summary":
+                    case "histogram":
+                        if (!regexp(line)) {
+                            log.info("invalid metric format ${line} type 
${type}, please check regexp or metric format".toString())
+                            allValid = false
+                        }
+                        break
+                    default:
+                        allValid = false
+                        log.info("unknow metric type ${type}".toString())
+                        break
+                }
+            }
+        }
+
+        return allValid
+    }
+}
diff --git a/regression-test/suites/cloud_p0/test_metrics_format.groovy 
b/regression-test/suites/cloud_p0/test_metrics_format.groovy
new file mode 100644
index 00000000000..2b366c692c6
--- /dev/null
+++ b/regression-test/suites/cloud_p0/test_metrics_format.groovy
@@ -0,0 +1,41 @@
+// 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
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.apache.doris.regression.util.PromethuesChecker
+
+suite('test_metrics_format') {
+    if (!isCloudMode()) {
+        log.info("not cloud mode just return")
+        return
+    }
+    def get_meta_service_metric = { check_func ->
+        httpTest {
+            op "get"
+            endpoint context.config.metaServiceHttpAddress
+            uri "/brpc_metrics"
+            check check_func
+        }
+    }
+
+    get_meta_service_metric.call {
+        respCode, body ->
+            assertEquals("${respCode}".toString(), "200")
+            String out = "${body}".toString()
+            Boolean res = PromethuesChecker.check(out)
+            assertTrue(res)
+    }
+}
\ No newline at end of file


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

Reply via email to