Skip to content

Commit 4b6a7fe

Browse files
committed
pkg/config: add buffer config for plugin audit log
1 parent fb4717d commit 4b6a7fe

File tree

8 files changed

+60
-12
lines changed

8 files changed

+60
-12
lines changed

DEPS.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6608,13 +6608,13 @@ def go_deps():
66086608
name = "com_github_pingcap_log",
66096609
build_file_proto_mode = "disable_global",
66106610
importpath = "github.com/pingcap/log",
6611-
sha256 = "ca74400554017427f09ab72ffb5ba4b6e1f8b92235839f518fc102a3231aa267",
6612-
strip_prefix = "github.com/pingcap/[email protected].20250514022801-14f3b4ca066e",
6611+
sha256 = "50df543d8d2d5f5f24f6ec5926855f074714a958f1f58e7fe50920c7e4d5fe5d",
6612+
strip_prefix = "github.com/pingcap/[email protected].20250917021125-19901e015dc9",
66136613
urls = [
6614-
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
6615-
"http://ats.apps.svc/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
6616-
"https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
6617-
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
6614+
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
6615+
"http://ats.apps.svc/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
6616+
"https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
6617+
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
66186618
],
66196619
)
66206620
go_repository(

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ require (
9090
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
9191
github.com/pingcap/fn v1.0.0
9292
github.com/pingcap/kvproto v0.0.0-20250915095348-efd5134a6d6c
93-
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e
93+
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9
9494
github.com/pingcap/metering_sdk v0.0.0-20250918015914-468cd6feb1dc
9595
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5
9696
github.com/pingcap/tidb/pkg/parser v0.0.0-20211011031125-9b13dc409c5e
@@ -350,7 +350,7 @@ require (
350350
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
351351
google.golang.org/protobuf v1.36.6
352352
gopkg.in/inf.v0 v0.9.1 // indirect
353-
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
353+
gopkg.in/natefinch/lumberjack.v2 v2.2.1
354354
gopkg.in/yaml.v3 v3.0.1 // indirect
355355
k8s.io/apimachinery v0.29.11 // indirect
356356
k8s.io/klog/v2 v2.120.1 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,8 @@ github.com/pingcap/kvproto v0.0.0-20250915095348-efd5134a6d6c h1:dZQmQHDT5YhvrWt
786786
github.com/pingcap/kvproto v0.0.0-20250915095348-efd5134a6d6c/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
787787
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
788788
github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
789-
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e h1:8AZZRv1Ox9FVGATVZBBgr6y1MrNBQFABEdovNJt1QIc=
790-
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA=
789+
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9 h1:qG9BSvlWFEE5otQGamuWedx9LRm0nrHvsQRQiW8SxEs=
790+
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA=
791791
github.com/pingcap/metering_sdk v0.0.0-20250918015914-468cd6feb1dc h1:WQYup3tMJq1tyDU8aWTpSZcMPJIKHV+LNlCu6S7OH1I=
792792
github.com/pingcap/metering_sdk v0.0.0-20250918015914-468cd6feb1dc/go.mod h1:Qj77xzm/Bscv47607+/BkP0ovAHnf4j7HWSLKQaKwBw=
793793
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 h1:T4pXRhBflzDeAhmOQHNPRRogMYxP13V7BkYw3ZsoSfE=

pkg/config/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ go_test(
4141
data = glob(["**"]),
4242
embed = [":config"],
4343
flaky = True,
44-
shard_count = 29,
44+
shard_count = 30,
4545
deps = [
4646
"//pkg/config/kerneltype",
4747
"//pkg/testkit/testsetup",

pkg/config/config.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ const (
5151
MaxLogFileSize = 4096 // MB
5252
// MaxTxnEntrySize is the max value of TxnEntrySizeLimit.
5353
MaxTxnEntrySizeLimit = 120 * 1024 * 1024 // 120MB
54+
// MaxPluginAuditLogBufferSize is the max buffer size for plugin audit log.
55+
MaxPluginAuditLogBufferSize = 100 * 1024 * 1024
56+
// MaxPluginAuditLogFlushInterval is the max time interval to flush plugin audit log.
57+
MaxPluginAuditLogFlushInterval = 3600
5458
// DefTxnEntrySizeLimit is the default value of TxnEntrySizeLimit.
5559
DefTxnEntrySizeLimit = 6 * 1024 * 1024
5660
// DefTxnTotalSizeLimit is the default value of TxnTxnTotalSizeLimit.
@@ -94,6 +98,10 @@ const (
9498
DefMemoryUsageAlarmRatio = 0.8
9599
// DefTempDir is the default temporary directory path for TiDB.
96100
DefTempDir = "/tmp/tidb"
101+
// DefPluginAuditLogBufferSize is the default buffer size for plugin audit log.
102+
DefPluginAuditLogBufferSize = 0
103+
// DefPluginAuditLogFlushInterval is the default time interval to flush plugin audit log.
104+
DefPluginAuditLogFlushInterval = 30
97105
// DefAuthTokenRefreshInterval is the default time interval to refresh tidb auth token.
98106
DefAuthTokenRefreshInterval = time.Hour
99107
// EnvVarKeyspaceName is the system env name for keyspace name.
@@ -562,6 +570,10 @@ type Instance struct {
562570
EnableCollectExecutionInfo AtomicBool `toml:"tidb_enable_collect_execution_info" json:"tidb_enable_collect_execution_info"`
563571
PluginDir string `toml:"plugin_dir" json:"plugin_dir"`
564572
PluginLoad string `toml:"plugin_load" json:"plugin_load"`
573+
// PluginAuditLogBufferSize is the buffer size (in bytes) of plugin audit log, default is 0(buffer disabled)
574+
PluginAuditLogBufferSize int `toml:"plugin_audit_log_buffer_size" json:"plugin_audit_log_buffer_size"`
575+
// PluginAuditLogFlushInterval is the flush interval (in seconds) of plugin audit log, it works only when PluginAuditLogBufferSize is greater than 0.
576+
PluginAuditLogFlushInterval int `toml:"plugin_audit_log_flush_interval" json:"plugin_audit_log_flush_interval"`
565577
// MaxConnections is the maximum permitted number of simultaneous client connections.
566578
MaxConnections uint32 `toml:"max_connections" json:"max_connections"`
567579
TiDBEnableDDL AtomicBool `toml:"tidb_enable_ddl" json:"tidb_enable_ddl"`
@@ -1005,6 +1017,8 @@ var defaultConf = Config{
10051017
EnableCollectExecutionInfo: *NewAtomicBool(true),
10061018
PluginDir: "/data/deploy/plugin",
10071019
PluginLoad: "",
1020+
PluginAuditLogBufferSize: 0,
1021+
PluginAuditLogFlushInterval: 30,
10081022
MaxConnections: 0,
10091023
TiDBEnableDDL: *NewAtomicBool(true),
10101024
TiDBEnableStatsOwner: *NewAtomicBool(true),
@@ -1388,7 +1402,12 @@ func (c *Config) Valid() error {
13881402
if c.TableColumnCountLimit < DefTableColumnCountLimit || c.TableColumnCountLimit > DefMaxOfTableColumnCountLimit {
13891403
return fmt.Errorf("table-column-limit should be [%d, %d]", DefIndexLimit, DefMaxOfTableColumnCountLimit)
13901404
}
1391-
1405+
if c.Instance.PluginAuditLogBufferSize < 0 || c.Instance.PluginAuditLogBufferSize > MaxPluginAuditLogBufferSize {
1406+
return fmt.Errorf("plugin-audit-log-buffer-size should be [%d, %d]", 0, MaxPluginAuditLogBufferSize)
1407+
}
1408+
if c.Instance.PluginAuditLogFlushInterval <= 0 || c.Instance.PluginAuditLogFlushInterval > MaxPluginAuditLogFlushInterval {
1409+
return fmt.Errorf("plugin-audit-log-flush-interval should be [%d, %d]", 1, MaxPluginAuditLogFlushInterval)
1410+
}
13921411
// txn-local-latches
13931412
if err := c.TxnLocalLatches.Valid(); err != nil {
13941413
return err

pkg/config/config_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,25 @@ func TestTableColumnCountLimit(t *testing.T) {
11921192
checkValid(DefMaxOfTableColumnCountLimit, true)
11931193
checkValid(DefMaxOfTableColumnCountLimit+1, false)
11941194
}
1195+
func TestPluginAuditLog(t *testing.T) {
1196+
conf := NewConfig()
1197+
checkValid := func(bufferSize int, shouldBeValid bool) {
1198+
conf.Instance.PluginAuditLogBufferSize = bufferSize
1199+
require.Equal(t, shouldBeValid, conf.Valid() == nil)
1200+
}
1201+
checkValid(-1, false)
1202+
checkValid(MaxPluginAuditLogBufferSize, true)
1203+
checkValid(MaxPluginAuditLogBufferSize+1, false)
1204+
1205+
conf = NewConfig()
1206+
checkValid = func(flushInterval int, shouldBeValid bool) {
1207+
conf.Instance.PluginAuditLogFlushInterval = flushInterval
1208+
require.Equal(t, shouldBeValid, conf.Valid() == nil)
1209+
}
1210+
checkValid(-1, false)
1211+
checkValid(MaxPluginAuditLogFlushInterval, true)
1212+
checkValid(MaxPluginAuditLogFlushInterval+1, false)
1213+
}
11951214

11961215
func TestTokenLimit(t *testing.T) {
11971216
storeDir := t.TempDir()

pkg/sessionctx/vardef/sysvar.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ const (
142142
PluginDir = "plugin_dir"
143143
// PluginLoad is the name of 'plugin_load' system variable.
144144
PluginLoad = "plugin_load"
145+
// PluginAuditLogBufferSize is the name of 'plugin_audit_log_buffer_size' system variable.
146+
PluginAuditLogBufferSize = "plugin_audit_log_buffer_size"
147+
// PluginAuditLogFlushInterval is the name of 'plugin_audit_log_flush_interval' system variable.
148+
PluginAuditLogFlushInterval = "plugin_audit_log_flush_interval"
145149
// TiDBEnableDDL indicates whether the tidb-server campaigns the DDL owner,
146150
TiDBEnableDDL = "tidb_enable_ddl"
147151
// TiDBEnableStatsOwner indicates whether the tidb-server campaigns the Stats owner,

pkg/sessionctx/variable/sysvar.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ var defaultSysVars = []*SysVar{
536536
{Scope: vardef.ScopeInstance, Name: vardef.PluginDir, Value: "/data/deploy/plugin", ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
537537
return config.GetGlobalConfig().Instance.PluginDir, nil
538538
}},
539+
{Scope: vardef.ScopeInstance, Name: vardef.PluginAuditLogBufferSize, Value: strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogFlushInterval), ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
540+
return strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogBufferSize), nil
541+
}},
542+
{Scope: vardef.ScopeInstance, Name: vardef.PluginAuditLogFlushInterval, Value: strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogFlushInterval), ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
543+
return strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogFlushInterval), nil
544+
}},
539545
{Scope: vardef.ScopeInstance, Name: vardef.MaxConnections, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().Instance.MaxConnections), 10), Type: vardef.TypeUnsigned, MinValue: 0, MaxValue: 100000, SetGlobal: func(_ context.Context, s *SessionVars, val string) error {
540546
config.GetGlobalConfig().Instance.MaxConnections = uint32(TidbOptInt64(val, 0))
541547
return nil

0 commit comments

Comments
 (0)