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

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


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 29f29f494fb [chore](test) add log to find bug of unstable test 
(#37982) (#42129)
29f29f494fb is described below

commit 29f29f494fbeb334227d9ffa48da3b69d0bc1479
Author: 924060929 <924060...@qq.com>
AuthorDate: Sat Oct 19 18:00:57 2024 +0800

    [chore](test) add log to find bug of unstable test (#37982) (#42129)
---
 regression-test/data/query_p0/cache/sql_cache.out  |  18 +--
 .../doris/regression/action/ProfileAction.groovy   | 122 +++++++++++++++++++++
 .../org/apache/doris/regression/suite/Suite.groovy |   5 +
 .../framework/src/main/groovy/suite.gdsl           |   4 +-
 .../suites/query_p0/cache/sql_cache.groovy         | 100 +++++++++++------
 5 files changed, 205 insertions(+), 44 deletions(-)

diff --git a/regression-test/data/query_p0/cache/sql_cache.out 
b/regression-test/data/query_p0/cache/sql_cache.out
index 1b3729294d1..75f28261bc3 100644
--- a/regression-test/data/query_p0/cache/sql_cache.out
+++ b/regression-test/data/query_p0/cache/sql_cache.out
@@ -1,50 +1,50 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
--- !sql_cache --
+-- !sql_cache1 --
 2022-05-28     0
 2022-05-29     0
 2022-05-30     0
 2022-06-01     0
 2022-06-02     0
 
--- !sql_cache --
+-- !sql_cache2 --
 2022-05-28     0
 2022-05-29     0
 2022-05-30     0
 2022-06-01     0
 2022-06-02     0
 
--- !sql_cache --
+-- !sql_cache3 --
 2022-05-28     0
 2022-05-29     0
 2022-05-30     0
 2022-06-01     0
 2022-06-02     0
 
--- !sql_cache --
+-- !sql_cache4 --
 2022-05-28     0
 2022-05-28     0
 
--- !sql_cache --
+-- !sql_cache5 --
 2022-05-28     0
 2022-05-28     0
 
--- !sql_cache --
+-- !sql_cache6 --
 2022-05-28     0
 2022-05-29     0
 2022-05-30     0
 2022-06-01     0
 2022-06-02     0
 
--- !sql_cache --
+-- !sql_cache7 --
 2022-05-28     0
 2022-05-29     0
 2022-05-30     0
 2022-06-01     0
 2022-06-02     0
 
--- !sql_cache --
+-- !sql_cache8 --
 2022-05-28     0
 
--- !sql_cache --
+-- !sql_cache9 --
 2022-05-28     0
 
diff --git 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/ProfileAction.groovy
 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/ProfileAction.groovy
new file mode 100644
index 00000000000..b019e6c24aa
--- /dev/null
+++ 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/ProfileAction.groovy
@@ -0,0 +1,122 @@
+// 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.action
+
+import groovy.json.JsonSlurper
+import groovy.transform.stc.ClosureParams
+import groovy.transform.stc.FromString
+import groovy.util.logging.Slf4j
+import org.apache.doris.regression.suite.SuiteContext
+import org.apache.doris.regression.util.JdbcUtils
+
+@Slf4j
+class ProfileAction implements SuiteAction {
+    private String tag
+    private Runnable runCallback
+    private Closure<String> check
+    private SuiteContext context
+
+    ProfileAction(SuiteContext context, String tag) {
+        this.context = context
+        this.tag = Objects.requireNonNull(tag, "tag can not be null")
+    }
+
+    void run(@ClosureParams(value = FromString, options = []) Runnable run) {
+        runCallback = run
+    }
+
+    void check(
+        @ClosureParams(value = FromString, options = ["String, Throwable"]) 
Closure check) {
+        this.check = check
+    }
+
+    @Override
+    void run() {
+        if (runCallback.is(null)) {
+            throw new IllegalStateException("Missing tag")
+        }
+        if (check.is(null)) {
+            throw new IllegalStateException("Missing check")
+        }
+        def conn = context.getConnection()
+        try {
+            JdbcUtils.executeToList(conn, "set enable_profile=true")
+
+            Throwable exception = null
+            try {
+                this.runCallback.run()
+            } catch (Throwable t) {
+                exception = t
+            }
+
+            def httpCli = new HttpCliAction(context)
+            httpCli.endpoint(context.config.feHttpAddress)
+            httpCli.uri("/rest/v1/query_profile")
+            httpCli.op("get")
+            httpCli.printResponse(false)
+
+            if (context.config.fetchRunMode()) {
+                httpCli.basicAuthorization(context.config.feCloudHttpUser, 
context.config.feCloudHttpPassword)
+            } else {
+                httpCli.basicAuthorization(context.config.feHttpUser, 
context.config.feHttpPassword)
+            }
+            httpCli.check { code, body ->
+                if (code != 200) {
+                    throw new IllegalStateException("Get profile list failed, 
code: ${code}, body:\n${body}")
+                }
+
+                def jsonSlurper = new JsonSlurper()
+                List profileData = jsonSlurper.parseText(body).data.rows
+                for (final def profileItem in profileData) {
+                    if (profileItem["Sql Statement"].toString().contains(tag)) 
{
+                        def profileId = profileItem["Profile ID"].toString()
+
+                        def profileCli = new HttpCliAction(context)
+                        profileCli.endpoint(context.config.feHttpAddress)
+                        profileCli.uri("/rest/v1/query_profile/${profileId}")
+                        profileCli.op("get")
+                        profileCli.printResponse(false)
+
+                        if (context.config.fetchRunMode()) {
+                            
profileCli.basicAuthorization(context.config.feCloudHttpUser, 
context.config.feCloudHttpPassword)
+                        } else {
+                            
profileCli.basicAuthorization(context.config.feHttpUser, 
context.config.feHttpPassword)
+                        }
+                        profileCli.check { profileCode, profileResp ->
+                            if (profileCode != 200) {
+                                throw new IllegalStateException("Get profile 
failed, url: ${"/rest/v1/query_profile/${profileId}"}, code: ${profileCode}, 
body:\n${profileResp}")
+                            }
+
+                            def jsonSlurper2 = new JsonSlurper()
+                            def profileText = 
jsonSlurper2.parseText(profileResp).data
+                            profileText = profileText.replace("&nbsp;", " ")
+                            profileText = profileText.replace("</br>", "\n")
+                            this.check(profileText, exception)
+                        }
+                        profileCli.run()
+
+                        break
+                    }
+                }
+            }
+            httpCli.run()
+        } finally {
+            JdbcUtils.executeToList(conn, "set enable_profile=false")
+        }
+    }
+}
diff --git 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
index 489e022ba0a..97bdad8d685 100644
--- 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
+++ 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
@@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableList
 import org.apache.commons.lang3.ObjectUtils
 import org.apache.doris.regression.Config
 import org.apache.doris.regression.action.BenchmarkAction
+import org.apache.doris.regression.action.ProfileAction
 import org.apache.doris.regression.action.WaitForAction
 import org.apache.doris.regression.util.DataUtils
 import org.apache.doris.regression.util.OutputUtils
@@ -610,6 +611,10 @@ class Suite implements GroovyInterceptable {
         }
     }
 
+    void profile(String tag, Closure<String> actionSupplier) {
+        runAction(new ProfileAction(context, tag), actionSupplier)
+    }
+
     void createMV(String sql) {
         (new CreateMVAction(context, sql)).run()
     }
diff --git a/regression-test/framework/src/main/groovy/suite.gdsl 
b/regression-test/framework/src/main/groovy/suite.gdsl
index aec43ab51a1..bf8da34c2c6 100644
--- a/regression-test/framework/src/main/groovy/suite.gdsl
+++ b/regression-test/framework/src/main/groovy/suite.gdsl
@@ -50,6 +50,7 @@ bindAction("streamLoad", 
"org.apache.doris.regression.action.StreamLoadAction")
 bindAction("httpTest", "org.apache.doris.regression.action.HttpCliAction")
 bindAction("benchmark", "org.apache.doris.regression.action.BenchmarkAction")
 bindAction("waitForSchemaChangeDone", 
"org.apache.doris.regression.action.WaitForAction")
+bindAction("profile", "org.apache.doris.regression.action.ProfileAction")
 
 // bind qt_xxx and order_qt_xxx methods
 contributor([suiteContext]) {
@@ -81,7 +82,8 @@ contributor([suiteContext]) {
                         !enclosingCall("explain") &&
                         !enclosingCall("streamLoad") &&
                         !enclosingCall("httpTest") &&
-                        !enclosingCall("waitForSchemaChangeDone"))) {
+                        !enclosingCall("waitForSchemaChangeDone") &&
+                        !enclosingCall("profile"))) {
             // bind other suite method and field
             def suiteClass = findClass(suiteClassName)
             delegatesTo(suiteClass)
diff --git a/regression-test/suites/query_p0/cache/sql_cache.groovy 
b/regression-test/suites/query_p0/cache/sql_cache.groovy
index 05ad8f6d81d..3f6c36ed771 100644
--- a/regression-test/suites/query_p0/cache/sql_cache.groovy
+++ b/regression-test/suites/query_p0/cache/sql_cache.groovy
@@ -19,12 +19,20 @@
 // 
/testing/trino-product-tests/src/main/resources/sql-tests/testcases/aggregate
 // and modified by Doris.
 
+import java.util.stream.Collectors
+
 suite("sql_cache") {
     // TODO: regression-test does not support check query profile,
     // so this suite does not check whether cache is used, :)
     def tableName = "test_sql_cache"
     sql  "ADMIN SET FRONTEND CONFIG ('cache_last_version_interval_second' = 
'0')"
 
+    def variables = sql "show variables"
+    def variableString = variables.stream()
+            .map { it.toString() }
+            .collect(Collectors.joining("\n"))
+    logger.info("Variables:\n${variableString}")
+
     sql """ DROP TABLE IF EXISTS ${tableName} """
     sql """
             CREATE TABLE IF NOT EXISTS ${tableName} (
@@ -55,7 +63,7 @@ suite("sql_cache") {
                     ("2022-06-02",0)
         """
 
-    qt_sql_cache """
+    qt_sql_cache1 """
                     select
                         k1,
                         sum(k2) as total_pv 
@@ -71,7 +79,7 @@ suite("sql_cache") {
     
     sql "set enable_sql_cache=true "
 
-    qt_sql_cache """
+    qt_sql_cache2 """
                     select
                         k1,
                         sum(k2) as total_pv 
@@ -84,7 +92,7 @@ suite("sql_cache") {
                     order by
                         k1;
                 """
-    qt_sql_cache """
+    qt_sql_cache3 """
                     select
                         k1,
                         sum(k2) as total_pv 
@@ -98,7 +106,7 @@ suite("sql_cache") {
                         k1;
                 """
 
-    qt_sql_cache """
+    qt_sql_cache4 """
                     select
                         k1,
                         sum(k2) as total_pv 
@@ -124,7 +132,7 @@ suite("sql_cache") {
                         k1;
                 """
     
-    qt_sql_cache """
+    qt_sql_cache5 """
                     select
                         k1,
                         sum(k2) as total_pv 
@@ -153,7 +161,7 @@ suite("sql_cache") {
     sql "SET enable_nereids_planner=true"
     sql "SET enable_fallback_to_original_planner=false"
 
-    qt_sql_cache """
+    qt_sql_cache6 """
                     select
                         k1,
                         sum(k2) as total_pv 
@@ -166,7 +174,7 @@ suite("sql_cache") {
                     order by
                         k1;
                 """
-    qt_sql_cache """
+    qt_sql_cache7 """
                     select
                         k1,
                         sum(k2) as total_pv 
@@ -183,33 +191,57 @@ suite("sql_cache") {
     sql 'set default_order_by_limit = 2'
     sql 'set sql_select_limit = 1'
 
-    qt_sql_cache """
-                    select
-                        k1,
-                        sum(k2) as total_pv 
-                    from
-                        ${tableName} 
-                    where
-                        k1 between '2022-05-28' and '2022-06-30' 
-                    group by
-                        k1 
-                    order by
-                        k1;
-                """
-    
-    qt_sql_cache """
-                    select
-                        k1,
-                        sum(k2) as total_pv 
-                    from
-                        ${tableName} 
-                    where
-                        k1 between '2022-05-28' and '2022-06-30' 
-                    group by
-                        k1 
-                    order by
-                        k1;
-                """
+    profile("sql_cache8") {
+        run {
+            qt_sql_cache8 """
+                -- sql_cache8
+                select
+                    k1,
+                    sum(k2) as total_pv 
+                from
+                    ${tableName} 
+                where
+                    k1 between '2022-05-28' and '2022-06-30' 
+                group by
+                    k1 
+                order by
+                    k1;
+            """
+        }
+
+        check { profileString, exception ->
+            if (!exception.is(null)) {
+                logger.error("Profile failed, profile 
result:\n${profileString}", exception)
+                throw exception
+            }
+        }
+    }
+
+    profile("sql_cache9") {
+        run {
+            qt_sql_cache9 """
+                -- sql_cache9
+                select
+                    k1,
+                    sum(k2) as total_pv 
+                from
+                    ${tableName} 
+                where
+                    k1 between '2022-05-28' and '2022-06-30' 
+                group by
+                    k1 
+                order by
+                    k1;
+            """
+        }
+
+        check { profileString, exception ->
+            if (!exception.is(null)) {
+                logger.error("Profile failed, profile 
result:\n${profileString}", exception)
+                throw exception
+            }
+        }
+    }
 
     sql  "ADMIN SET FRONTEND CONFIG ('cache_last_version_interval_second' = 
'10')"
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to