Skip to content

Commit 9f14938

Browse files
Merge pull request #22 from WuMenglong/main
Updated to 4.2.1
2 parents 7d09f7a + 3819941 commit 9f14938

File tree

9 files changed

+258
-125
lines changed

9 files changed

+258
-125
lines changed

.gitignore

-36
This file was deleted.

README.md

+49-19
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
create database starrocks_audit_db__;
2222
```
2323

24-
`starrocks_audit_db__` 库创建 `starrocks_audit_tbl__` 表,表的属性部分可以视实际业务进行修改
24+
`starrocks_audit_db__` 库创建 `starrocks_audit_tbl__` 表,表的字段顺序以及属性部分可以视实际业务进行修改
2525

2626
```SQL
2727
CREATE TABLE starrocks_audit_db__.starrocks_audit_tbl__ (
@@ -48,7 +48,10 @@ CREATE TABLE starrocks_audit_db__.starrocks_audit_tbl__ (
4848
`stmt` VARCHAR(1048576) COMMENT "SQL原始语句",
4949
`digest` VARCHAR(32) COMMENT "慢SQL指纹",
5050
`planCpuCosts` DOUBLE COMMENT "查询规划阶段CPU占用(纳秒)",
51-
`planMemCosts` DOUBLE COMMENT "查询规划阶段内存占用(字节)"
51+
`planMemCosts` DOUBLE COMMENT "查询规划阶段内存占用(字节)",
52+
`pendingTimeMs` BIGINT COMMENT "查询在队列中等待的时间(毫秒)",
53+
`candidateMVs` varchar(65533) NULL COMMENT "候选MV列表",
54+
`hitMvs` varchar(65533) NULL COMMENT "命中MV列表"
5255
) ENGINE = OLAP
5356
DUPLICATE KEY (`queryId`, `timestamp`, `queryType`)
5457
COMMENT "审计日志表"
@@ -98,41 +101,52 @@ Archive: auditloader.zip
98101
```XML
99102
### plugin configuration
100103

101-
# The max size of a batch, default is 50MB.
104+
# The max size of a batch, default is 50MB
102105
max_batch_size=52428800
103106

104-
# The max interval of batch loaded, default is 60 seconds.
107+
# The max interval of batch loaded, default is 60 seconds
105108
max_batch_interval_sec=60
106109

107-
# the max stmt length to be loaded in audit table, default is 1048576.
110+
# the max stmt length to be loaded in audit table, default is 1048576
108111
max_stmt_length=1048576
109112

110-
# StarRocks FE host for loading the audit, default is 127.0.0.1:8030.
111-
# this should be the host port for stream load.
113+
# StarRocks FE host for loading the audit, default is 127.0.0.1:8030
114+
# this should be the host port for stream load
112115
frontend_host_port=127.0.0.1:8030
113116

114-
# If the response time of a query exceed this threshold, it will be recored in audit table as slow_query.
117+
# If the response time of a query exceed this threshold, it will be recored in audit table as slow_query
115118
qe_slow_log_ms=5000
116119

117-
# Database of the audit table.
120+
# the capacity of audit queue, default is 1000
121+
max_queue_size=1000
122+
123+
# Database of the audit table
118124
database=starrocks_audit_db__
119125

120-
# Audit table name, to save the audit data.
126+
# Audit table name, to save the audit data
121127
table=starrocks_audit_tbl__
122128

123-
# StarRocks user. This user must have import permissions for the audit table.
129+
# StarRocks user. This user must have import permissions for the audit table
124130
user=root
125131

126-
# StarRocks user's password.
132+
# StarRocks user's password
127133
password=
128134

135+
# StarRocks password encryption key, with a length not exceeding 16 bytes
136+
secret_key=
137+
129138
# Whether to generate sql digest for all queries
130139
enable_compute_all_query_digest=false
140+
141+
# Filter conditions when importing audit information
142+
filter=
131143
```
132144

133145
**说明**
134-
1. 推荐使用参数 `frontend_host_port` 的默认配置,即 `127.0.0.1:8030` 。StarRocks 中各个 FE 是独立管理各自的审计信息的,在安装审计插件后,各个 FE 分别会启动各自的后台线程进行审计信息的获取攒批和 Stream load 写入。 `frontend_host_port` 配置项用于为插件后台 Stream Load 任务提供 http 协议的 IP 和端口,该参数不支持配置为多个值。其中,参数 IP 部分可以使用集群内任意某个 FE 的 IP,但并不推荐这样配置,因为若对应的 FE 出现异常,其他 FE 后台的审计信息写入任务也会因无法通信导致写入失败。推荐配置为默认的 `127.0.0.1:8030`,让各个 FE 均使用自身的 http 端口进行通信,以此规避其他 FE 异常时对通信的影响(当然,所有的写入任务最终都会被自动转发到 FE Leader 节点执行)。
135-
2. `enable_compute_all_query_digest`参数表示是否对所有查询都生成SQL指纹。
146+
1. 推荐使用参数 `frontend_host_port` 的默认配置,即 `127.0.0.1:8030` 。StarRocks 中各个 FE 是独立管理各自的审计信息的,在安装审计插件后,各个 FE 分别会启动各自的后台线程进行审计信息的获取攒批和 Stream Load 写入。 `frontend_host_port` 配置项用于为插件后台 Stream Load 任务提供 http 协议的 IP 和端口,该参数不支持配置为多个值。其中,参数 IP 部分可以使用集群内任意某个 FE 的 IP,但并不推荐这样配置,因为若对应的 FE 出现异常,其他 FE 后台的审计信息写入任务也会因无法通信导致写入失败。推荐配置为默认的 `127.0.0.1:8030`,让各个 FE 均使用自身的 http 端口进行通信,以此规避其他 FE 异常时对通信的影响(当然,所有的写入任务最终都会被自动转发到 FE Leader 节点执行)。
147+
2. `secret_key` 参数用于配置"加密密码的 key 字符串",在审计插件中其长度不得超过 16 个字节。如果该参数留空,表示不对 `plugin.conf` 中的密码进行加解密,在 password 处直接配置明文密码即可。如果该参数不为空,表示需要对密码进行加解密,password 处需配置为加密后的字符串,加密后的密码可在 StarRocks 中通过 `AES_ENCRYPT` 函数生成:`SELECT TO_BASE64(AES_ENCRYPT('password','secret_key'));`
148+
3. `enable_compute_all_query_digest` 参数表示是否对所有查询都生成 Hash SQL 指纹(StarRocks 默认只为慢查询开启 SQL 指纹,注意插件中的指纹计算方法与 FE 内部的方法不一致,FE 会对 SQL 语句[规范化处理](https://docs.mirrorship.cn/zh/docs/administration/Query_planning/#%E6%9F%A5%E7%9C%8B-sql-%E6%8C%87%E7%BA%B9),而插件不会,且如果开启该参数,指纹计算会额外占用集群内的计算资源)。
149+
4. `filter` 参数可以配置审计信息入库的过滤条件,该处使用 Stream Load 中 [where 参数](https://docs.mirrorship.cn/zh/docs/sql-reference/sql-statements/data-manipulation/STREAM_LOAD/#opt_properties)实现,即`-H "where: <condition>"`,默认为空,配置示例:`filter=isQuery=1 and clientIp like '127.0.0.1%' and user='root'`
136150

137151

138152
修改完成后,再将上面的三个文件重新打包为 zip 包:
@@ -147,13 +161,13 @@ enable_compute_all_query_digest=false
147161

148162
##### 3、分发插件
149163

150-
将 auditloader.zip 分发至集群所有 FE 节点,各节点分发路径需要一致。例如我们都分发至StarRocks部署目录 `/opt/module/starrocks/` 下,也即 auditloader.zip 文件在集群所有FE节点的路径都为:
164+
将 auditloader.zip 分发至集群所有 FE 节点,各节点分发路径需要一致。例如都分发至StarRocks部署目录 `/opt/module/starrocks/` 下,也即 auditloader.zip 文件在集群所有FE节点的路径都为:
151165

152166
```
153167
/opt/module/starrocks/auditloader.zip
154168
```
155169

156-
**说明**:也可将 auditloader.zip 分发至所有 FE 都可访问到的 http 服务中(例如 httpd 或 nginx),然后使用网络路径安装。
170+
**说明**:也可将 auditloader.zip 分发至所有 FE 都可访问到的 http 服务中(例如 httpd 或 nginx),然后使用网络路径安装。注意这两种方式下 auditloader.zip 在执行安装后都需要在该路径下持续保留,不可在安装后删除源文件。
157171

158172

159173

@@ -195,8 +209,8 @@ JavaVersion: 1.8.31
195209
*************************** 2. row ***************************
196210
Name: AuditLoader
197211
Type: AUDIT
198-
Description: Available for versions 2.3+. Load audit log to starrocks, and user can view the statistic of queries.
199-
Version: 4.0.0
212+
Description: Available for versions 2.5+. Load audit log to starrocks, and user can view the statistic of queries
213+
Version: 4.2.1
200214
JavaVersion: 1.8.0
201215
ClassName: com.starrocks.plugin.audit.AuditLoaderPlugin
202216
SoName: NULL
@@ -250,5 +264,21 @@ mysql> select * from starrocks_audit_db__.starrocks_audit_tbl__;
250264

251265
StarRocks审计表中支持的 `queryType` 类型包括:query、slow_query 和 connection。对于 query 和 slow_query,AuditLoader 插件使用 `plugin.conf` 中配置的 `qe_slow_log_ms` 时间来进行对比判断,SQL 执行时长大于 `qe_slow_log_ms` 的即为 slow_query,您可以以此进行集群慢 SQL 的统计。
252266

253-
对于 connection,StarRocks 3.0.6+ 版本支持在 fe.audit.log 中打印客户端连接时成功/失败的 connection 信息,您可以在 `fe.conf` 里配置 `audit_log_modules=slow_query, query, connection`,然后重启 FE 来进行启用。在启用 connection 信息后,AuditLoader 插件同样能采集到这类客户端连接信息并入库到表 `starrocks_audit_tbl__` 中,入库后该类信息对应的审计表的 `queryType` 字段即为 connection,您可以以此进行用户登录信息的审计。
267+
对于 connection,StarRocks 3.0.6+ 版本支持在 fe.audit.log 中打印客户端连接时成功/失败的 connection 信息,您可以在 `fe.conf` 里配置 `audit_log_modules=slow_query,query,connection`,然后重启 FE 来进行启用。在启用 connection 信息后,AuditLoader 插件同样能采集到这类客户端连接信息并入库到表 `starrocks_audit_tbl__` 中,入库后该类信息对应的审计表的 `queryType` 字段即为 connection,您可以以此进行用户登录信息的审计。
268+
269+
270+
271+
### 更新说明:
272+
273+
##### AuditLoader v4.2.1
274+
275+
1)新增在 plugin.conf 中配置密文密码的功能
276+
277+
2)在审计日志表中预留增加了 candidateMVs 和 hitMvs 两个重要监测字段
278+
279+
3)新增在 plugin.conf 中通过 filter 参数进行审计信息的入库条件筛选功能
280+
281+
4)调整插件攒批逻辑为 Json,规避 StarRocks 3.2.12+ 等版本 FE netty 依赖升级导致的原 CSV 攒批逻辑在写入时报错 `Validation failed for header 'column_separator'` 的问题
282+
283+
5)其他细节优化
254284

lib/starrocks-fe.jar

1.5 MB
Binary file not shown.

pom.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
<groupId>com.starrocks</groupId>
88
<artifactId>fe-plugins-auditloader</artifactId>
9-
<version>3.0.1</version>
9+
<version>4.2.1</version>
1010

1111
<properties>
12-
<log4j2.version>2.19.0</log4j2.version>
12+
<log4j2.version>2.24.1</log4j2.version>
1313
<project.scm.id>github</project.scm.id>
1414
</properties>
1515
<dependencies>
1616
<dependency>
1717
<groupId>com.starrocks</groupId>
1818
<artifactId>starrocks-fe</artifactId>
19-
<version>3.0.0</version>
19+
<version>3.0.6</version>
2020
<scope>system</scope>
2121
<systemPath>${basedir}/lib/starrocks-fe.jar</systemPath>
2222
</dependency>
@@ -41,12 +41,12 @@
4141
<dependency>
4242
<groupId>org.apache.commons</groupId>
4343
<artifactId>commons-lang3</artifactId>
44-
<version>3.9</version>
44+
<version>3.17.0</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>commons-codec</groupId>
4848
<artifactId>commons-codec</artifactId>
49-
<version>1.15</version>
49+
<version>1.17.1</version>
5050
</dependency>
5151
</dependencies>
5252

@@ -67,15 +67,15 @@
6767
<plugin>
6868
<groupId>org.apache.maven.plugins</groupId>
6969
<artifactId>maven-compiler-plugin</artifactId>
70-
<version>2.3.2</version>
70+
<version>3.13.0</version>
7171
<configuration>
7272
<source>1.8</source>
7373
<target>1.8</target>
7474
</configuration>
7575
</plugin>
7676
<plugin>
7777
<artifactId>maven-assembly-plugin</artifactId>
78-
<version>2.4.1</version>
78+
<version>3.7.1</version>
7979
<configuration>
8080
<appendAssemblyId>false</appendAssemblyId>
8181
<descriptors>

src/main/assembly/plugin.conf

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ max_batch_interval_sec=60
2626
# the max stmt length to be loaded in audit table, default is 1048576
2727
max_stmt_length=1048576
2828

29-
# StarRocks FE host for loading the audit, default is 127.0.0.1:8030.
29+
# StarRocks FE host for loading the audit, default is 127.0.0.1:8030
3030
# this should be the host port for stream load
3131
frontend_host_port=127.0.0.1:8030
3232

33-
# If the response time of a query exceed this threshold, it will be recored in audit table as slow_query.
33+
# If the response time of a query exceed this threshold, it will be recored in audit table as slow_query
3434
qe_slow_log_ms=5000
3535

3636
# the capacity of audit queue, default is 1000
@@ -39,14 +39,20 @@ max_queue_size=1000
3939
# Database of the audit table
4040
database=starrocks_audit_db__
4141

42-
# Audit table name, to save the audit data.
42+
# Audit table name, to save the audit data
4343
table=starrocks_audit_tbl__
4444

45-
# StarRocks user. This user must have import permissions for the audit table.
45+
# StarRocks user. This user must have import permissions for the audit table
4646
user=root
4747

4848
# StarRocks user's password
4949
password=
5050

51+
# StarRocks password encryption key
52+
secret_key=
53+
5154
# Whether to generate sql digest for all queries
5255
enable_compute_all_query_digest=false
56+
57+
# Filter conditions when importing audit information
58+
filter=

src/main/assembly/plugin.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
name=AuditLoader
1919
type=AUDIT
20-
description=Available for versions 2.3+. Load audit log to starrocks, and user can view the statistic of queries.
21-
version=4.0.0
20+
description=Available for versions 2.5+. Load audit log to starrocks, and user can view the statistic of queries
21+
version=4.2.1
2222
java.version=1.8.0
2323
classname=com.starrocks.plugin.audit.AuditLoaderPlugin

0 commit comments

Comments
 (0)