Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -272,6 +274,11 @@ public AuditEventBuilder setScanBytesFromRemoteStorage(long scanBytesFromRemoteS
return this;
}

public AuditEventBuilder setCommandType(String commandType) {
auditEvent.commandType = commandType;
return this;
}

public AuditEvent build() {
return this.auditEvent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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;
Expand Down Expand Up @@ -208,7 +209,8 @@ private static void logAuditLogImpl(ConnectContext ctx, String origStmt, Stateme
.setQueryId(ctx.queryId() == null ? "NaN" : DebugUtil.printId(ctx.queryId()))
.setCloudCluster(Strings.isNullOrEmpty(cluster) ? "UNKNOWN" : cluster)
.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) {
Expand Down Expand Up @@ -277,6 +279,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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,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.
Expand Down