This is an automated email from the ASF dual-hosted git repository.

eldenmoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c55f2b8d51 [Improve](auditlog) audit log print real sql in prepared 
statement (#43038)
8c55f2b8d51 is described below

commit 8c55f2b8d51c74f545f520f5fd806b34d75e576b
Author: He xueyu <[email protected]>
AuthorDate: Wed Nov 6 13:45:53 2024 +0800

    [Improve](auditlog) audit log print real sql in prepared statement (#43038)
    
    1. Use the "execute *** using *** /*original sql = */" in the audit log 
instead of "execute *** using ***".
    2. Add a CommandType parameter to the audit log.
    3. When the prepared statement is ready, it should log OK instead of NOOP
---
 fe/fe-core/src/main/java/org/apache/doris/plugin/AuditEvent.java   | 7 +++++++
 fe/fe-core/src/main/java/org/apache/doris/qe/AuditLogHelper.java   | 7 ++++++-
 .../src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java   | 1 +
 3 files changed, 14 insertions(+), 1 deletion(-)

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 8a4ca5db749..20c05d982f8 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 class AuditEvent {
     public String ctl = "";
     @AuditField(value = "Db")
     public String db = "";
+    @AuditField(value = "CommandType")
+    public String commandType = "";
     @AuditField(value = "State")
     public String state = "";
     @AuditField(value = "ErrorCode")
@@ -270,6 +272,11 @@ public class AuditEvent {
             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 5d24452e092..12958d53390 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
@@ -32,6 +32,7 @@ import org.apache.doris.common.util.DebugUtil;
 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;
@@ -211,7 +212,8 @@ public class AuditLogHelper {
                 .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) {
@@ -292,6 +294,9 @@ public class AuditLogHelper {
                 }
             }
         }
+        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 d5f4ab7dfcc..376d4740e63 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
@@ -151,6 +151,7 @@ public class MysqlConnectProcessor extends ConnectProcessor 
{
             executor.execute();
             if (ctx.getSessionVariable().isEnablePreparedStmtAuditLog()) {
                 stmtStr = executeStmt.toSql();
+                stmtStr = stmtStr + " /*originalSql = " + 
prepareCommand.getOriginalStmt().originStmt + "*/";
             }
         } catch (Throwable e) {
             // Catch all throwable.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to