From 9a0d792b68ac2dcab78175326ed8dd51a51ff152 Mon Sep 17 00:00:00 2001
From: "Mingyu Chen (Rayner)" <yunyou@selectdb.com>
Date: Sat, 21 Jun 2025 01:02:30 +0800
Subject: [PATCH 1/2] [feat] modify audit log and profile http api

---
 docs/admin-manual/audit-plugin.md             |  6 +++
 .../open-api/fe-http/query-profile-action.md  | 40 ++++++++++++++++++
 .../current/admin-manual/audit-plugin.md      |  2 +-
 .../open-api/fe-http/query-profile-action.md  | 41 +++++++++++++++++++
 .../version-3.0/admin-manual/audit-plugin.md  |  2 +-
 .../version-3.0/admin-manual/audit-plugin.md  |  6 +++
 6 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/docs/admin-manual/audit-plugin.md b/docs/admin-manual/audit-plugin.md
index 1874f988f8d40..dec972198d3cb 100644
--- a/docs/admin-manual/audit-plugin.md
+++ b/docs/admin-manual/audit-plugin.md
@@ -56,6 +56,12 @@ The audit log table is a dynamically partitioned table, partitioned daily by def
 
 In `fe.conf`, `LOG_DIR` defines the storage path for FE logs. All database operations executed by this FE node are recorded in `${LOG_DIR}/fe.audit.log`. To view all operations in the cluster, you need to traverse the audit logs of each FE node.
 
+## Audit Log Format
+
+In versions before 3.0.7, the symbols `\n`, `\t`, and `\r` in statements would be replaced with `\\n`, `\\t`, and `\\r`. These modified statements were then stored in the `fe.audit.log` file and the `audit_log` table.
+
+Starting from version 3.0.7, for the `fe.audit.log` file, only `\n` in statements will be replaced with `\\n`. The `audit_log` table, stores the original format of statements.
+
 ## Audit Log Configuration
 
 **Global Variables:**
diff --git a/docs/admin-manual/open-api/fe-http/query-profile-action.md b/docs/admin-manual/open-api/fe-http/query-profile-action.md
index 5d3904a41366f..89fcc8389726b 100644
--- a/docs/admin-manual/open-api/fe-http/query-profile-action.md
+++ b/docs/admin-manual/open-api/fe-http/query-profile-action.md
@@ -46,6 +46,8 @@ under the License.
 
 `GET /rest/v2/manager/query/kill/{query_id}`
 
+`GET /rest/v2/manager/query/statistics/{trace_id}` (4.0.0+)
+
 ## Get the query information
 
 `GET /rest/v2/manager/query/query_info`
@@ -499,3 +501,41 @@ Cancel query of specified connection.
     "count": 0
 }
 ```
+
+## Get Query Progress by Trace ID
+
+`GET /rest/v2/manager/query/statistics/{trace_id}` (4.0.0+)
+
+### Description
+
+Retrieve the statistics of a currently running query by Trace ID. You can call this API periodically to obtain the progress of the query.
+
+### Path parameters
+
+* `{trace_id}`
+
+    Trace ID. The user-defined Trace ID set via `SET session_context="trace_id:xxxx"`.
+
+### Response
+
+```json
+{
+    "msg": "success",
+    "code": 0,
+    "data": {
+        "scanRows": 1234567,
+        "scanBytes": 987654321,
+        "returnedRows": 12345,
+        "cpuMs": 15600,
+        "maxPeakMemoryBytes": 536870912,
+        "currentUsedMemoryBytes": 268435456,
+        "shuffleSendBytes": 104857600,
+        "shuffleSendRows": 50000,
+        "scanBytesFromLocalStorage": 734003200,
+        "scanBytesFromRemoteStorage": 253651121,
+        "spillWriteBytesToLocalStorage": 0,
+        "spillReadBytesFromLocalStorage": 0
+    },
+    "count": 0
+}
+```
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md
index 4f05850cae44c..9a7a12eb5822f 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md
@@ -54,7 +54,7 @@ Doris 提供了对于数据库操作的审计能力，可以记录用户对数
 
 ## 审计日志文件
 
-在 fe.conf 中，LOG\_DIR 定义了 FE 日志的存储路径。在 ${LOG\_DIR}/fe.audit.log 中记录了这台 FE 节点执行的所有数据库操作。如果需要查看集群所有的操作，需要便利每一台 FE 的审计日志。
+在 fe.conf 中，`LOG_DIR` 定义了 FE 日志的存储路径。在 `${LOG_DIR}/fe.audit.log` 中记录了这台 FE 节点执行的所有数据库操作。如果需要查看集群所有的操作，需要遍历每一台 FE 的审计日志。
 
 ## 审计日志相关配置
 
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/open-api/fe-http/query-profile-action.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/open-api/fe-http/query-profile-action.md
index 88d52f9afcb4d..b9feed32ed31d 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/open-api/fe-http/query-profile-action.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/open-api/fe-http/query-profile-action.md
@@ -46,6 +46,8 @@ under the License.
 
 `GET /rest/v2/manager/query/kill/{query_id}`
 
+`GET /rest/v2/manager/query/statistics/{trace_id}` (4.0.0+)
+
 ## 获取查询信息
 
 `GET /rest/v2/manager/query/query_info`
@@ -477,3 +479,42 @@ Admin 和 Root 用户可以查看所有 Query。普通用户仅能查看自己
 }
 ```
 
+## 通过 Trace ID 获取查询进度
+
+`GET /rest/v2/manager/query/statistics/{trace_id}` (4.0.0+)
+
+### Description
+
+通过 Trace ID，获取指定的当前正在运行的查询的统计信息。可以通过间隔调用这个接口来获取查询的进度。
+
+### Path parameters
+
+* `{trace_id}`
+
+    Trace ID。通过 `SET session_context="trace_id:xxxx"` 设置的用户自定义 Trace ID。
+
+### Response
+
+```json
+{
+    "msg": "success",
+    "code": 0,
+    "data": {
+        "scanRows": 1234567,
+        "scanBytes": 987654321,
+        "returnedRows": 12345,
+        "cpuMs": 15600,
+        "maxPeakMemoryBytes": 536870912,
+        "currentUsedMemoryBytes": 268435456,
+        "shuffleSendBytes": 104857600,
+        "shuffleSendRows": 50000,
+        "scanBytesFromLocalStorage": 734003200,
+        "scanBytesFromRemoteStorage": 253651121,
+        "spillWriteBytesToLocalStorage": 0,
+        "spillReadBytesFromLocalStorage": 0
+    },
+    "count": 0
+}
+```
+
+
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/admin-manual/audit-plugin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/admin-manual/audit-plugin.md
index 4f05850cae44c..9a7a12eb5822f 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/admin-manual/audit-plugin.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/admin-manual/audit-plugin.md
@@ -54,7 +54,7 @@ Doris 提供了对于数据库操作的审计能力，可以记录用户对数
 
 ## 审计日志文件
 
-在 fe.conf 中，LOG\_DIR 定义了 FE 日志的存储路径。在 ${LOG\_DIR}/fe.audit.log 中记录了这台 FE 节点执行的所有数据库操作。如果需要查看集群所有的操作，需要便利每一台 FE 的审计日志。
+在 fe.conf 中，`LOG_DIR` 定义了 FE 日志的存储路径。在 `${LOG_DIR}/fe.audit.log` 中记录了这台 FE 节点执行的所有数据库操作。如果需要查看集群所有的操作，需要遍历每一台 FE 的审计日志。
 
 ## 审计日志相关配置
 
diff --git a/versioned_docs/version-3.0/admin-manual/audit-plugin.md b/versioned_docs/version-3.0/admin-manual/audit-plugin.md
index 1874f988f8d40..dec972198d3cb 100644
--- a/versioned_docs/version-3.0/admin-manual/audit-plugin.md
+++ b/versioned_docs/version-3.0/admin-manual/audit-plugin.md
@@ -56,6 +56,12 @@ The audit log table is a dynamically partitioned table, partitioned daily by def
 
 In `fe.conf`, `LOG_DIR` defines the storage path for FE logs. All database operations executed by this FE node are recorded in `${LOG_DIR}/fe.audit.log`. To view all operations in the cluster, you need to traverse the audit logs of each FE node.
 
+## Audit Log Format
+
+In versions before 3.0.7, the symbols `\n`, `\t`, and `\r` in statements would be replaced with `\\n`, `\\t`, and `\\r`. These modified statements were then stored in the `fe.audit.log` file and the `audit_log` table.
+
+Starting from version 3.0.7, for the `fe.audit.log` file, only `\n` in statements will be replaced with `\\n`. The `audit_log` table, stores the original format of statements.
+
 ## Audit Log Configuration
 
 **Global Variables:**

From 00c98fb0b7722f3472e86f7bffc44b49c36dd4c3 Mon Sep 17 00:00:00 2001
From: "Mingyu Chen (Rayner)" <yunyou@selectdb.com>
Date: Sat, 21 Jun 2025 01:04:09 +0800
Subject: [PATCH 2/2] [feat] modify audit log and profile http api

---
 .../current/admin-manual/audit-plugin.md                    | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md
index 9a7a12eb5822f..173b0770aa347 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/audit-plugin.md
@@ -56,6 +56,12 @@ Doris 提供了对于数据库操作的审计能力，可以记录用户对数
 
 在 fe.conf 中，`LOG_DIR` 定义了 FE 日志的存储路径。在 `${LOG_DIR}/fe.audit.log` 中记录了这台 FE 节点执行的所有数据库操作。如果需要查看集群所有的操作，需要遍历每一台 FE 的审计日志。
 
+## 审计日志格式
+
+在 3.0.7 之前的版本的版本中，用户执行语句中的 `\n`, `\t`, `\r` 符号会把替换成 `\\n`, `\\t`, `\\r`。之后存储在 `fe.audit.log` 日志和 `audit_log` 表中。
+
+3.0.7 开始，对于 `fe.audit.log` 日志，用户执行语句中仅 `\n` 会被替换成 `\\n`。而 `audit_log` 表存储的是原始的语句格式。
+
 ## 审计日志相关配置
 
 **全局变量：**
