diff --git a/fe/fe-core/src/main/java/com/starrocks/common/util/LogUtil.java b/fe/fe-core/src/main/java/com/starrocks/common/util/LogUtil.java index 750c105c40d61..2fc4b3de4a1ce 100644 --- a/fe/fe-core/src/main/java/com/starrocks/common/util/LogUtil.java +++ b/fe/fe-core/src/main/java/com/starrocks/common/util/LogUtil.java @@ -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); } diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java index 91789fb7bfc35..ab2c5b6c492d6 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java @@ -321,6 +321,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); @@ -353,7 +354,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()); @@ -550,7 +552,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 diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/QueryDetail.java b/fe/fe-core/src/main/java/com/starrocks/qe/QueryDetail.java index 9b4ab1ce661e6..d10b4bcdd7ba8 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/QueryDetail.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/QueryDetail.java @@ -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; @@ -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; @@ -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() { @@ -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; } @@ -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; + } } diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailQueueTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailQueueTest.java index 4c4f172be6780..92c4f0203a437 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailQueueTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailQueueTest.java @@ -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); @@ -73,7 +73,8 @@ public void testQueryDetailQueue() { + "\"returnRows\":1," + "\"cpuCostNs\":1002," + "\"memCostBytes\":100003," - + "\"spillBytes\":-1" + + "\"spillBytes\":-1," + + "\"catalog\":\"default_catalog\"" + "}]"; Assert.assertEquals(jsonString, queryDetailString); diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailTest.java index 8e25b7f846c4c..cb731ab94a64a 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/QueryDetailTest.java @@ -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");