diff --git a/fe/fe-core/src/main/java/org/apache/doris/plugin/AuditEvent.java b/fe/fe-core/src/main/java/org/apache/doris/plugin/AuditEvent.java index 5fc735a0bb882a..7d64b600d8a9f1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/plugin/AuditEvent.java +++ b/fe/fe-core/src/main/java/org/apache/doris/plugin/AuditEvent.java @@ -60,6 +60,8 @@ public enum EventType { public String ctl = ""; @AuditField(value = "Db") public String db = ""; + @AuditField(value = "CommandType") + public String commandType = ""; @AuditField(value = "State") public String state = ""; @AuditField(value = "ErrorCode") @@ -242,6 +244,11 @@ public AuditEventBuilder setWorkloadGroup(String workloadGroup) { return this; } + public AuditEventBuilder setCommandType(String commandType) { + auditEvent.commandType = commandType; + return this; + } + public AuditEvent build() { return this.auditEvent; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java b/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java index 02a66a5f6e1c55..d10e1bbfbb87c5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java @@ -30,6 +30,7 @@ import org.apache.doris.datasource.CatalogIf; import org.apache.doris.datasource.InternalCatalog; import org.apache.doris.metric.MetricRepo; +import org.apache.doris.mysql.MysqlCommand; import org.apache.doris.nereids.analyzer.UnboundOneRowRelation; import org.apache.doris.nereids.analyzer.UnboundTableSink; import org.apache.doris.nereids.glue.LogicalPlanAdapter; @@ -197,7 +198,8 @@ private static void logAuditLogImpl(ConnectContext ctx, String origStmt, Stateme .setStmtId(ctx.getStmtId()) .setQueryId(ctx.queryId() == null ? "NaN" : DebugUtil.printId(ctx.queryId())) .setWorkloadGroup(ctx.getWorkloadGroupName()) - .setFuzzyVariables(!printFuzzyVariables ? "" : ctx.getSessionVariable().printFuzzyVariables()); + .setFuzzyVariables(!printFuzzyVariables ? "" : ctx.getSessionVariable().printFuzzyVariables()) + .setCommandType(ctx.getCommand().toString()); if (ctx.getState().isQuery()) { if (!ctx.getSessionVariable().internalSession) { @@ -248,6 +250,9 @@ private static void logAuditLogImpl(ConnectContext ctx, String origStmt, Stateme } } } + if (ctx.getCommand() == MysqlCommand.COM_STMT_PREPARE && ctx.getState().getErrorCode() == null) { + auditEventBuilder.setState(String.valueOf(MysqlStateType.OK)); + } Env.getCurrentEnv().getWorkloadRuntimeStatusMgr().submitFinishQueryToAudit(auditEventBuilder.build()); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java index 138f4202ab2771..931dc3d4717020 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java @@ -221,6 +221,7 @@ private void handleExecute(PrepareCommand prepareCommand, long stmtId, PreparedS executor.execute(); if (ctx.getSessionVariable().isEnablePreparedStmtAuditLog()) { stmtStr = executeStmt.toSql(); + stmtStr = stmtStr + " /*originalSql = " + prepareCommand.getOriginalStmt().originStmt + "*/"; } } catch (Throwable e) { // Catch all throwable.