diff --git a/docs/api-references/docs.html b/docs/api-references/docs.html
index cc2407aefe..5c050a1663 100644
--- a/docs/api-references/docs.html
+++ b/docs/api-references/docs.html
@@ -2961,6 +2961,7 @@
FileLogConfig
+(Optional)
Log filename, leave empty to disable file log.
|
@@ -2972,6 +2973,7 @@ FileLogConfig
+(Optional)
Is log rotate enabled.
|
@@ -2983,6 +2985,7 @@ FileLogConfig
+(Optional)
Max size for a single file, in MB.
|
@@ -2994,6 +2997,7 @@ FileLogConfig
+(Optional)
Max log keep days, default is never deleting.
|
@@ -3005,6 +3009,7 @@ FileLogConfig
+(Optional)
Maximum number of old log files to retain.
|
diff --git a/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go b/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go
index eac2b434ee..b7e6ace341 100644
--- a/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go
+++ b/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go
@@ -26,6 +26,10 @@ const (
defaultBinlogImage = "pingcap/tidb-binlog"
)
+var (
+ tidbLogMaxBackups = 3
+)
+
func SetTidbClusterDefault(tc *v1alpha1.TidbCluster) {
setTidbClusterSpecDefault(tc)
setPdSpecDefault(tc)
@@ -59,6 +63,27 @@ func setTidbSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiDB.MaxFailoverCount == nil {
tc.Spec.TiDB.MaxFailoverCount = pointer.Int32Ptr(3)
}
+
+ // we only set default log
+ if tc.Spec.TiDB.Config != nil {
+ if tc.Spec.TiDB.Config.Log == nil {
+ tc.Spec.TiDB.Config.Log = &v1alpha1.Log{
+ File: &v1alpha1.FileLogConfig{
+ MaxBackups: &tidbLogMaxBackups,
+ },
+ }
+ } else {
+ if tc.Spec.TiDB.Config.Log.File == nil {
+ tc.Spec.TiDB.Config.Log.File = &v1alpha1.FileLogConfig{
+ MaxBackups: &tidbLogMaxBackups,
+ }
+ } else {
+ if tc.Spec.TiDB.Config.Log.File.MaxBackups == nil {
+ tc.Spec.TiDB.Config.Log.File.MaxBackups = &tidbLogMaxBackups
+ }
+ }
+ }
+ }
}
func setTikvSpecDefault(tc *v1alpha1.TidbCluster) {
diff --git a/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster_test.go b/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster_test.go
new file mode 100644
index 0000000000..fa57445328
--- /dev/null
+++ b/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster_test.go
@@ -0,0 +1,96 @@
+// Copyright 2020 PingCAP, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package defaulting
+
+import (
+ . "github.com/onsi/gomega"
+ "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
+ "testing"
+)
+
+func TestSetTidbSpecDefault(t *testing.T) {
+ g := NewGomegaWithT(t)
+
+ tc := newTidbCluster()
+ setTidbSpecDefault(tc)
+ g.Expect(tc.Spec.TiDB.Config).Should(BeNil())
+
+ tc = newTidbCluster()
+ tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{}
+ setTidbSpecDefault(tc)
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.MaxBackups).Should(Equal(tidbLogMaxBackups))
+
+ tc = newTidbCluster()
+ oomAction := "cancel"
+ tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{
+ OOMAction: &oomAction,
+ }
+ setTidbSpecDefault(tc)
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.MaxBackups).Should(Equal(tidbLogMaxBackups))
+ g.Expect(*tc.Spec.TiDB.Config.OOMAction).Should(Equal(oomAction))
+
+ tc = newTidbCluster()
+ infoLevel := "info"
+ tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{
+ OOMAction: &oomAction,
+ Log: &v1alpha1.Log{
+ Level: &infoLevel,
+ },
+ }
+ setTidbSpecDefault(tc)
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.MaxBackups).Should(Equal(tidbLogMaxBackups))
+ g.Expect(*tc.Spec.TiDB.Config.OOMAction).Should(Equal(oomAction))
+ g.Expect(*tc.Spec.TiDB.Config.Log.Level).Should(Equal(infoLevel))
+
+ tc = newTidbCluster()
+ fileName := "slowlog.log"
+ tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{
+ OOMAction: &oomAction,
+ Log: &v1alpha1.Log{
+ Level: &infoLevel,
+ File: &v1alpha1.FileLogConfig{
+ Filename: &fileName,
+ },
+ },
+ }
+ setTidbSpecDefault(tc)
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.MaxBackups).Should(Equal(tidbLogMaxBackups))
+ g.Expect(*tc.Spec.TiDB.Config.OOMAction).Should(Equal(oomAction))
+ g.Expect(*tc.Spec.TiDB.Config.Log.Level).Should(Equal(infoLevel))
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.Filename).Should(Equal(fileName))
+
+ tc = newTidbCluster()
+ maxSize := 600
+ tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{
+ OOMAction: &oomAction,
+ Log: &v1alpha1.Log{
+ Level: &infoLevel,
+ File: &v1alpha1.FileLogConfig{
+ Filename: &fileName,
+ MaxSize: &maxSize,
+ },
+ },
+ }
+ setTidbSpecDefault(tc)
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.MaxSize).Should(Equal(maxSize))
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.MaxBackups).Should(Equal(tidbLogMaxBackups))
+ g.Expect(*tc.Spec.TiDB.Config.OOMAction).Should(Equal(oomAction))
+ g.Expect(*tc.Spec.TiDB.Config.Log.Level).Should(Equal(infoLevel))
+ g.Expect(*tc.Spec.TiDB.Config.Log.File.Filename).Should(Equal(fileName))
+
+}
+
+func newTidbCluster() *v1alpha1.TidbCluster {
+ return &v1alpha1.TidbCluster{}
+}
diff --git a/pkg/apis/pingcap/v1alpha1/pd_config.go b/pkg/apis/pingcap/v1alpha1/pd_config.go
index e7ed6429c3..49490476b4 100644
--- a/pkg/apis/pingcap/v1alpha1/pd_config.go
+++ b/pkg/apis/pingcap/v1alpha1/pd_config.go
@@ -428,15 +428,20 @@ type PDMetricConfig struct {
// +k8s:openapi-gen=true
type FileLogConfig struct {
// Log filename, leave empty to disable file log.
- Filename string `toml:"filename,omitempty" json:"filename,omitempty"`
+ // +optional
+ Filename *string `toml:"filename,omitempty" json:"filename,omitempty"`
// Is log rotate enabled.
- LogRotate bool `toml:"log-rotate,omitempty" json:"log-rotate,omitempty"`
+ // +optional
+ LogRotate *bool `toml:"log-rotate,omitempty" json:"log-rotate,omitempty"`
// Max size for a single file, in MB.
- MaxSize int `toml:"max-size,omitempty" json:"max-size,omitempty"`
+ // +optional
+ MaxSize *int `toml:"max-size,omitempty" json:"max-size,omitempty"`
// Max log keep days, default is never deleting.
- MaxDays int `toml:"max-days,omitempty" json:"max-days,omitempty"`
+ // +optional
+ MaxDays *int `toml:"max-days,omitempty" json:"max-days,omitempty"`
// Maximum number of old log files to retain.
- MaxBackups int `toml:"max-backups,omitempty" json:"max-backups,omitempty"`
+ // +optional
+ MaxBackups *int `toml:"max-backups,omitempty" json:"max-backups,omitempty"`
}
//StringSlice is more friendly to json encode/decode
diff --git a/pkg/apis/pingcap/v1alpha1/tidb_config.go b/pkg/apis/pingcap/v1alpha1/tidb_config.go
index 771ee2ddf8..2abab5f784 100644
--- a/pkg/apis/pingcap/v1alpha1/tidb_config.go
+++ b/pkg/apis/pingcap/v1alpha1/tidb_config.go
@@ -172,7 +172,7 @@ type Log struct {
QueryLogMaxLen *uint64 `toml:"query-log-max-len,omitempty" json:"query-log-max-len,omitempty"`
// Optional: Defaults to 1
// +optional
- RecordPlanInSlowLog uint32 `toml:"record-plan-in-slow-log,omitempty" json:"record-plan-in-slow-log,omitempty"`
+ RecordPlanInSlowLog *uint32 `toml:"record-plan-in-slow-log,omitempty" json:"record-plan-in-slow-log,omitempty"`
}
// Security is the security section of the config.
diff --git a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go
index 96a4a66989..661c1a19d1 100644
--- a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go
@@ -687,6 +687,31 @@ func (in *Experimental) DeepCopy() *Experimental {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FileLogConfig) DeepCopyInto(out *FileLogConfig) {
*out = *in
+ if in.Filename != nil {
+ in, out := &in.Filename, &out.Filename
+ *out = new(string)
+ **out = **in
+ }
+ if in.LogRotate != nil {
+ in, out := &in.LogRotate, &out.LogRotate
+ *out = new(bool)
+ **out = **in
+ }
+ if in.MaxSize != nil {
+ in, out := &in.MaxSize, &out.MaxSize
+ *out = new(int)
+ **out = **in
+ }
+ if in.MaxDays != nil {
+ in, out := &in.MaxDays, &out.MaxDays
+ *out = new(int)
+ **out = **in
+ }
+ if in.MaxBackups != nil {
+ in, out := &in.MaxBackups, &out.MaxBackups
+ *out = new(int)
+ **out = **in
+ }
return
}
@@ -843,7 +868,7 @@ func (in *Log) DeepCopyInto(out *Log) {
if in.File != nil {
in, out := &in.File, &out.File
*out = new(FileLogConfig)
- **out = **in
+ (*in).DeepCopyInto(*out)
}
if in.EnableSlowLog != nil {
in, out := &in.EnableSlowLog, &out.EnableSlowLog
@@ -870,6 +895,11 @@ func (in *Log) DeepCopyInto(out *Log) {
*out = new(uint64)
**out = **in
}
+ if in.RecordPlanInSlowLog != nil {
+ in, out := &in.RecordPlanInSlowLog, &out.RecordPlanInSlowLog
+ *out = new(uint32)
+ **out = **in
+ }
return
}
@@ -1150,7 +1180,7 @@ func (in *PDLogConfig) DeepCopyInto(out *PDLogConfig) {
if in.File != nil {
in, out := &in.File, &out.File
*out = new(FileLogConfig)
- **out = **in
+ (*in).DeepCopyInto(*out)
}
if in.Development != nil {
in, out := &in.Development, &out.Development