pkg/config: add buffer config for plugin audit log (#63651)
close pingcap/tidb#63650
This commit is contained in:
12
DEPS.bzl
12
DEPS.bzl
@ -6608,13 +6608,13 @@ def go_deps():
|
||||
name = "com_github_pingcap_log",
|
||||
build_file_proto_mode = "disable_global",
|
||||
importpath = "github.com/pingcap/log",
|
||||
sha256 = "ca74400554017427f09ab72ffb5ba4b6e1f8b92235839f518fc102a3231aa267",
|
||||
strip_prefix = "github.com/pingcap/log@v1.1.1-0.20250514022801-14f3b4ca066e",
|
||||
sha256 = "50df543d8d2d5f5f24f6ec5926855f074714a958f1f58e7fe50920c7e4d5fe5d",
|
||||
strip_prefix = "github.com/pingcap/log@v1.1.1-0.20250917021125-19901e015dc9",
|
||||
urls = [
|
||||
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
|
||||
"http://ats.apps.svc/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
|
||||
"https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
|
||||
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250514022801-14f3b4ca066e.zip",
|
||||
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
|
||||
"http://ats.apps.svc/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
|
||||
"https://cache.hawkingrei.com/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
|
||||
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/log/com_github_pingcap_log-v1.1.1-0.20250917021125-19901e015dc9.zip",
|
||||
],
|
||||
)
|
||||
go_repository(
|
||||
|
||||
4
go.mod
4
go.mod
@ -90,7 +90,7 @@ require (
|
||||
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
|
||||
github.com/pingcap/fn v1.0.0
|
||||
github.com/pingcap/kvproto v0.0.0-20250915095348-efd5134a6d6c
|
||||
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e
|
||||
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9
|
||||
github.com/pingcap/metering_sdk v0.0.0-20250918015914-468cd6feb1dc
|
||||
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5
|
||||
github.com/pingcap/tidb/pkg/parser v0.0.0-20211011031125-9b13dc409c5e
|
||||
@ -351,7 +351,7 @@ require (
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
|
||||
google.golang.org/protobuf v1.36.6
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/apimachinery v0.29.11 // indirect
|
||||
k8s.io/klog/v2 v2.120.1 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@ -786,8 +786,8 @@ github.com/pingcap/kvproto v0.0.0-20250915095348-efd5134a6d6c h1:dZQmQHDT5YhvrWt
|
||||
github.com/pingcap/kvproto v0.0.0-20250915095348-efd5134a6d6c/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
|
||||
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
|
||||
github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
|
||||
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e h1:8AZZRv1Ox9FVGATVZBBgr6y1MrNBQFABEdovNJt1QIc=
|
||||
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA=
|
||||
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9 h1:qG9BSvlWFEE5otQGamuWedx9LRm0nrHvsQRQiW8SxEs=
|
||||
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA=
|
||||
github.com/pingcap/metering_sdk v0.0.0-20250918015914-468cd6feb1dc h1:WQYup3tMJq1tyDU8aWTpSZcMPJIKHV+LNlCu6S7OH1I=
|
||||
github.com/pingcap/metering_sdk v0.0.0-20250918015914-468cd6feb1dc/go.mod h1:Qj77xzm/Bscv47607+/BkP0ovAHnf4j7HWSLKQaKwBw=
|
||||
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 h1:T4pXRhBflzDeAhmOQHNPRRogMYxP13V7BkYw3ZsoSfE=
|
||||
|
||||
@ -41,7 +41,7 @@ go_test(
|
||||
data = glob(["**"]),
|
||||
embed = [":config"],
|
||||
flaky = True,
|
||||
shard_count = 29,
|
||||
shard_count = 30,
|
||||
deps = [
|
||||
"//pkg/config/kerneltype",
|
||||
"//pkg/testkit/testsetup",
|
||||
|
||||
@ -51,6 +51,10 @@ const (
|
||||
MaxLogFileSize = 4096 // MB
|
||||
// MaxTxnEntrySize is the max value of TxnEntrySizeLimit.
|
||||
MaxTxnEntrySizeLimit = 120 * 1024 * 1024 // 120MB
|
||||
// MaxPluginAuditLogBufferSize is the max buffer size for plugin audit log.
|
||||
MaxPluginAuditLogBufferSize = 100 * 1024 * 1024
|
||||
// MaxPluginAuditLogFlushInterval is the max time interval to flush plugin audit log.
|
||||
MaxPluginAuditLogFlushInterval = 3600
|
||||
// DefTxnEntrySizeLimit is the default value of TxnEntrySizeLimit.
|
||||
DefTxnEntrySizeLimit = 6 * 1024 * 1024
|
||||
// DefTxnTotalSizeLimit is the default value of TxnTxnTotalSizeLimit.
|
||||
@ -94,6 +98,10 @@ const (
|
||||
DefMemoryUsageAlarmRatio = 0.8
|
||||
// DefTempDir is the default temporary directory path for TiDB.
|
||||
DefTempDir = "/tmp/tidb"
|
||||
// DefPluginAuditLogBufferSize is the default buffer size for plugin audit log.
|
||||
DefPluginAuditLogBufferSize = 0
|
||||
// DefPluginAuditLogFlushInterval is the default time interval to flush plugin audit log.
|
||||
DefPluginAuditLogFlushInterval = 30
|
||||
// DefAuthTokenRefreshInterval is the default time interval to refresh tidb auth token.
|
||||
DefAuthTokenRefreshInterval = time.Hour
|
||||
// EnvVarKeyspaceName is the system env name for keyspace name.
|
||||
@ -562,6 +570,10 @@ type Instance struct {
|
||||
EnableCollectExecutionInfo AtomicBool `toml:"tidb_enable_collect_execution_info" json:"tidb_enable_collect_execution_info"`
|
||||
PluginDir string `toml:"plugin_dir" json:"plugin_dir"`
|
||||
PluginLoad string `toml:"plugin_load" json:"plugin_load"`
|
||||
// PluginAuditLogBufferSize is the buffer size (in bytes) of plugin audit log, default is 0(buffer disabled)
|
||||
PluginAuditLogBufferSize int `toml:"plugin_audit_log_buffer_size" json:"plugin_audit_log_buffer_size"`
|
||||
// PluginAuditLogFlushInterval is the flush interval (in seconds) of plugin audit log, it works only when PluginAuditLogBufferSize is greater than 0.
|
||||
PluginAuditLogFlushInterval int `toml:"plugin_audit_log_flush_interval" json:"plugin_audit_log_flush_interval"`
|
||||
// MaxConnections is the maximum permitted number of simultaneous client connections.
|
||||
MaxConnections uint32 `toml:"max_connections" json:"max_connections"`
|
||||
TiDBEnableDDL AtomicBool `toml:"tidb_enable_ddl" json:"tidb_enable_ddl"`
|
||||
@ -1005,6 +1017,8 @@ var defaultConf = Config{
|
||||
EnableCollectExecutionInfo: *NewAtomicBool(true),
|
||||
PluginDir: "/data/deploy/plugin",
|
||||
PluginLoad: "",
|
||||
PluginAuditLogBufferSize: 0,
|
||||
PluginAuditLogFlushInterval: 30,
|
||||
MaxConnections: 0,
|
||||
TiDBEnableDDL: *NewAtomicBool(true),
|
||||
TiDBEnableStatsOwner: *NewAtomicBool(true),
|
||||
@ -1388,7 +1402,12 @@ func (c *Config) Valid() error {
|
||||
if c.TableColumnCountLimit < DefTableColumnCountLimit || c.TableColumnCountLimit > DefMaxOfTableColumnCountLimit {
|
||||
return fmt.Errorf("table-column-limit should be [%d, %d]", DefIndexLimit, DefMaxOfTableColumnCountLimit)
|
||||
}
|
||||
|
||||
if c.Instance.PluginAuditLogBufferSize < 0 || c.Instance.PluginAuditLogBufferSize > MaxPluginAuditLogBufferSize {
|
||||
return fmt.Errorf("plugin-audit-log-buffer-size should be [%d, %d]", 0, MaxPluginAuditLogBufferSize)
|
||||
}
|
||||
if c.Instance.PluginAuditLogFlushInterval <= 0 || c.Instance.PluginAuditLogFlushInterval > MaxPluginAuditLogFlushInterval {
|
||||
return fmt.Errorf("plugin-audit-log-flush-interval should be [%d, %d]", 1, MaxPluginAuditLogFlushInterval)
|
||||
}
|
||||
// txn-local-latches
|
||||
if err := c.TxnLocalLatches.Valid(); err != nil {
|
||||
return err
|
||||
|
||||
@ -1192,6 +1192,25 @@ func TestTableColumnCountLimit(t *testing.T) {
|
||||
checkValid(DefMaxOfTableColumnCountLimit, true)
|
||||
checkValid(DefMaxOfTableColumnCountLimit+1, false)
|
||||
}
|
||||
func TestPluginAuditLog(t *testing.T) {
|
||||
conf := NewConfig()
|
||||
checkValid := func(bufferSize int, shouldBeValid bool) {
|
||||
conf.Instance.PluginAuditLogBufferSize = bufferSize
|
||||
require.Equal(t, shouldBeValid, conf.Valid() == nil)
|
||||
}
|
||||
checkValid(-1, false)
|
||||
checkValid(MaxPluginAuditLogBufferSize, true)
|
||||
checkValid(MaxPluginAuditLogBufferSize+1, false)
|
||||
|
||||
conf = NewConfig()
|
||||
checkValid = func(flushInterval int, shouldBeValid bool) {
|
||||
conf.Instance.PluginAuditLogFlushInterval = flushInterval
|
||||
require.Equal(t, shouldBeValid, conf.Valid() == nil)
|
||||
}
|
||||
checkValid(-1, false)
|
||||
checkValid(MaxPluginAuditLogFlushInterval, true)
|
||||
checkValid(MaxPluginAuditLogFlushInterval+1, false)
|
||||
}
|
||||
|
||||
func TestTokenLimit(t *testing.T) {
|
||||
storeDir := t.TempDir()
|
||||
|
||||
@ -142,6 +142,10 @@ const (
|
||||
PluginDir = "plugin_dir"
|
||||
// PluginLoad is the name of 'plugin_load' system variable.
|
||||
PluginLoad = "plugin_load"
|
||||
// PluginAuditLogBufferSize is the name of 'plugin_audit_log_buffer_size' system variable.
|
||||
PluginAuditLogBufferSize = "plugin_audit_log_buffer_size"
|
||||
// PluginAuditLogFlushInterval is the name of 'plugin_audit_log_flush_interval' system variable.
|
||||
PluginAuditLogFlushInterval = "plugin_audit_log_flush_interval"
|
||||
// TiDBEnableDDL indicates whether the tidb-server campaigns the DDL owner,
|
||||
TiDBEnableDDL = "tidb_enable_ddl"
|
||||
// TiDBEnableStatsOwner indicates whether the tidb-server campaigns the Stats owner,
|
||||
|
||||
@ -536,6 +536,12 @@ var defaultSysVars = []*SysVar{
|
||||
{Scope: vardef.ScopeInstance, Name: vardef.PluginDir, Value: "/data/deploy/plugin", ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
|
||||
return config.GetGlobalConfig().Instance.PluginDir, nil
|
||||
}},
|
||||
{Scope: vardef.ScopeInstance, Name: vardef.PluginAuditLogBufferSize, Value: strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogFlushInterval), ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
|
||||
return strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogBufferSize), nil
|
||||
}},
|
||||
{Scope: vardef.ScopeInstance, Name: vardef.PluginAuditLogFlushInterval, Value: strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogFlushInterval), ReadOnly: true, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {
|
||||
return strconv.Itoa(config.GetGlobalConfig().Instance.PluginAuditLogFlushInterval), nil
|
||||
}},
|
||||
{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 {
|
||||
config.GetGlobalConfig().Instance.MaxConnections = uint32(TidbOptInt64(val, 0))
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user