forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...on-test/framework/src/main/groovy/org/apache/doris/regression/action/ProfileAction.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
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) { | ||
this.context = context | ||
} | ||
|
||
void tag(String tag) { | ||
this.tag = tag | ||
} | ||
void run(@ClosureParams(value = FromString, options = []) Runnable run) { | ||
runCallback = run | ||
} | ||
|
||
void check( | ||
@ClosureParams(value = FromString, options = ["String"]) Closure<String> check) { | ||
this.check = check | ||
} | ||
|
||
@Override | ||
void run() { | ||
if (tag.is(null)) { | ||
throw new IllegalStateException("Missing tag") | ||
} | ||
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") | ||
|
||
this.runCallback.run() | ||
|
||
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(" ", " ") | ||
profileText = profileText.replace("</br>", "\n") | ||
this.check(profileText) | ||
} | ||
profileCli.run() | ||
|
||
break | ||
} | ||
} | ||
} | ||
httpCli.run() | ||
} finally { | ||
JdbcUtils.executeToList(conn, "set enable_profile=false") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters