Skip to content

Commit

Permalink
[Enhancement] Add catalog information in FE's query_detail #40894 (ba…
Browse files Browse the repository at this point in the history
…ckport #45372) (#45469)

Co-authored-by: wangfei <[email protected]>
  • Loading branch information
mergify[bot] and happut authored May 11, 2024
1 parent 6409a26 commit 044322b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static void logConnectionInfoToAuditLogAndQueryQueue(ConnectContext ctx,
queryDetail.setRemoteIP(ctx.getRemoteIP());
queryDetail.setDatabase(authPacket == null ? "null" : authPacket.getDb());
queryDetail.setErrorMessage(ctx.getState().getErrorMessage());
queryDetail.setCatalog(ctx.getCurrentCatalog());
QueryDetailQueue.addQueryDetail(queryDetail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ protected void addFinishedQueryDetail() {
queryDetail.setMemCostBytes(statistics.memCostBytes == null ? -1 : statistics.memCostBytes);
queryDetail.setSpillBytes(statistics.spillBytes == null ? -1 : statistics.spillBytes);
}
queryDetail.setCatalog(ctx.getCurrentCatalog());

if (Config.enable_profile_log) {
String jsonString = GSON.toJson(queryDetail);
Expand Down Expand Up @@ -350,7 +351,8 @@ protected void addRunningQueryDetail(StatementBase parsedStmt) {
ctx.getDatabase(),
sql,
ctx.getQualifiedUser(),
Optional.ofNullable(ctx.getResourceGroup()).map(TWorkGroup::getName).orElse(""));
Optional.ofNullable(ctx.getResourceGroup()).map(TWorkGroup::getName).orElse(""),
ctx.getCurrentCatalog());
ctx.setQueryDetail(queryDetail);
// copy queryDetail, cause some properties can be changed in future
QueryDetailQueue.addQueryDetail(queryDetail.copy());
Expand Down Expand Up @@ -547,7 +549,7 @@ private void handleExecute() {
packetBuf.get(nullBitmap);
try {
ctx.setQueryId(UUIDUtil.genUUID());

// new_params_bind_flag
if (packetBuf.hasRemaining() && (int) packetBuf.get() != 0) {
// parse params types
Expand Down
18 changes: 15 additions & 3 deletions fe/fe-core/src/main/java/com/starrocks/qe/QueryDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public enum QueryMemState {

// When query received, FE will construct a QueryDetail
// object. This object will set queryId, startTime, sql
// fields. As well state is be set as RUNNING.
// fields. As well state is be set as RUNNING.
// After query finished, endTime and latency will
// be set and state will be updated to be FINISHED/FAILED/CANCELLED
// according to the query execution results.
// So, one query will be inserted into as a item and
// So, one query will be inserted into as a item and
// be udpated upon finished. To indicate the two event,
// a extra field named eventTime is added.
private long eventTime;
Expand Down Expand Up @@ -78,13 +78,14 @@ public enum QueryMemState {
private long memCostBytes = -1;
private long spillBytes = -1;
private String digest;
private String catalog;

public QueryDetail() {
}

public QueryDetail(String queryId, boolean isQuery, int connId, String remoteIP,
long startTime, long endTime, long latency, QueryMemState state,
String database, String sql, String user, String resourceGroupName) {
String database, String sql, String user, String resourceGroupName, String catalog) {
this.queryId = queryId;
this.isQuery = isQuery;
this.connId = connId;
Expand All @@ -105,6 +106,7 @@ public QueryDetail(String queryId, boolean isQuery, int connId, String remoteIP,
}
this.sql = sql;
this.user = user;
this.catalog = catalog;
}

public QueryDetail copy() {
Expand All @@ -131,6 +133,8 @@ public QueryDetail copy() {
queryDetail.memCostBytes = this.memCostBytes;
queryDetail.spillBytes = this.spillBytes;
queryDetail.digest = this.digest;
queryDetail.resourceGroupName = this.resourceGroupName;
queryDetail.catalog = this.catalog;
return queryDetail;
}

Expand Down Expand Up @@ -305,4 +309,12 @@ public String getDigest() {
public void setDigest(String digest) {
this.digest = digest;
}

public String getCatalog() {
return catalog;
}

public void setCatalog(String catalog) {
this.catalog = catalog;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testQueryDetailQueue() {
QueryDetail startQueryDetail = new QueryDetail("219a2d5443c542d4-8fc938db37c892e3", false, 1, "127.0.0.1",
System.currentTimeMillis(), -1, -1, QueryDetail.QueryMemState.RUNNING,
"testDb", "select * from table1 limit 1",
"root", "");
"root", "", "default_catalog");
startQueryDetail.setScanRows(100);
startQueryDetail.setScanBytes(10001);
startQueryDetail.setReturnRows(1);
Expand All @@ -73,7 +73,8 @@ public void testQueryDetailQueue() {
+ "\"returnRows\":1,"
+ "\"cpuCostNs\":1002,"
+ "\"memCostBytes\":100003,"
+ "\"spillBytes\":-1"
+ "\"spillBytes\":-1,"
+ "\"catalog\":\"default_catalog\""
+ "}]";
Assert.assertEquals(jsonString, queryDetailString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testQueryDetail() {
QueryDetail queryDetail = new QueryDetail("219a2d5443c542d4-8fc938db37c892e3", true, 1, "127.0.0.1",
System.currentTimeMillis(), -1, -1, QueryDetail.QueryMemState.RUNNING,
"testDb", "select * from table1 limit 1",
"root", "");
"root", "", "default_catalog");
queryDetail.setProfile("bbbbb");
queryDetail.setErrorMessage("cancelled");

Expand Down

0 comments on commit 044322b

Please sign in to comment.