From 7caaf3de7d99f4bba5d193abd6ef7d1d4dad1fe3 Mon Sep 17 00:00:00 2001 From: Yeh-lei Wu Date: Tue, 26 Feb 2019 19:48:56 +0800 Subject: [PATCH 1/7] Support slow log tailing sidcar for tidb instance Signed-off-by: Yeh-lei Wu --- .../templates/config/_tidb-config.tpl | 4 + .../tidb-cluster/templates/tidb-cluster.yaml | 9 ++ charts/tidb-cluster/values.yaml | 10 ++ .../tidb-cluster-values.yaml | 1 + pkg/apis/pingcap.com/v1alpha1/types.go | 25 ++-- pkg/controller/controller_utils.go | 9 ++ pkg/controller/controller_utils_test.go | 9 ++ pkg/manager/member/tidb_member_manager.go | 123 +++++++++++------- .../member/tidb_member_manager_test.go | 1 + values.yml | 3 + 10 files changed, 141 insertions(+), 53 deletions(-) create mode 100644 values.yml diff --git a/charts/tidb-cluster/templates/config/_tidb-config.tpl b/charts/tidb-cluster/templates/config/_tidb-config.tpl index 56525ec41f..10e43636bd 100644 --- a/charts/tidb-cluster/templates/config/_tidb-config.tpl +++ b/charts/tidb-cluster/templates/config/_tidb-config.tpl @@ -59,7 +59,11 @@ format = "text" disable-timestamp = false # Stores slow query log into separated files. +{{- if .Values.tidb.separateSlowLog }} +slow-query-file = "/tmp/log/tidb/slowlog" +{{- else }} slow-query-file = "" +{{- end }} # Queries with execution time greater than this value will be logged. (Milliseconds) slow-threshold = 300 diff --git a/charts/tidb-cluster/templates/tidb-cluster.yaml b/charts/tidb-cluster/templates/tidb-cluster.yaml index 0628b511b9..444be9f4a1 100644 --- a/charts/tidb-cluster/templates/tidb-cluster.yaml +++ b/charts/tidb-cluster/templates/tidb-cluster.yaml @@ -76,3 +76,12 @@ spec: {{- end }} binlogEnabled: {{ .Values.binlog.pump.create | default false }} maxFailoverCount: {{ .Values.tidb.maxFailoverCount | default 3 }} + separateSlowLog: {{ .Values.separateSlowLog | default false }} +{{- if .Values.separateSlowLog }} + slowLogTailer: + image: {{ .Values.tidb.slowLogTailer.image }} + imagePullPolicy: {{ .Values.tidb.slowLogTailer.imagePullPolicy | default "IfNotPresent" }} + {{- if .Values.tidb.slowLogTailer.resources }} + {{ toYaml .Values.tidb.slowLogTailer.resources | indent 6 }} + {{- end }} +{{- end }} diff --git a/charts/tidb-cluster/values.yaml b/charts/tidb-cluster/values.yaml index 5a6098862a..59d909804b 100644 --- a/charts/tidb-cluster/values.yaml +++ b/charts/tidb-cluster/values.yaml @@ -175,6 +175,16 @@ tidb: exposeStatus: true # annotations: # cloud.google.com/load-balancer-type: Internal + # separateSlowLog: true + slowLogTailer: + image: busybox:1.26.2 + resources: + limits: {} + # cpu: 50m + # memory: 10Mi + requests: {} + # cpu: 50m + # memory: 10Mi # mysqlClient is used to set password for TiDB mysqlClient: diff --git a/images/tidb-operator-e2e/tidb-cluster-values.yaml b/images/tidb-operator-e2e/tidb-cluster-values.yaml index e0845060c0..0248eba487 100644 --- a/images/tidb-operator-e2e/tidb-cluster-values.yaml +++ b/images/tidb-operator-e2e/tidb-cluster-values.yaml @@ -143,6 +143,7 @@ tidb: exposeStatus: true # annotations: # cloud.google.com/load-balancer-type: Internal + separateSlowLog: true # mysqlClient is used to set password for TiDB mysqlClient: diff --git a/pkg/apis/pingcap.com/v1alpha1/types.go b/pkg/apis/pingcap.com/v1alpha1/types.go index 78cc5de6c7..030fc634d4 100644 --- a/pkg/apis/pingcap.com/v1alpha1/types.go +++ b/pkg/apis/pingcap.com/v1alpha1/types.go @@ -42,8 +42,10 @@ const ( TiDBMemberType MemberType = "tidb" // TiKVMemberType is tikv container type TiKVMemberType MemberType = "tikv" - //PushGatewayMemberType is pushgateway container type + // PushGatewayMemberType is pushgateway container type PushGatewayMemberType MemberType = "pushgateway" + // TiDBLogTailerMemberType is tidb log tailer container type + SlowLogTailerMemberType MemberType = "slowlog-tailer" // UnknownMemberType is unknown container type UnknownMemberType MemberType = "unknown" ) @@ -117,13 +119,20 @@ type PDSpec struct { // TiDBSpec contains details of PD member type TiDBSpec struct { ContainerSpec - Replicas int32 `json:"replicas"` - NodeSelector map[string]string `json:"nodeSelector,omitempty"` - NodeSelectorRequired bool `json:"nodeSelectorRequired,omitempty"` - StorageClassName string `json:"storageClassName,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - BinlogEnabled bool `json:"binlogEnabled,omitempty"` - MaxFailoverCount int32 `json:"maxFailoverCount,omitempty"` + Replicas int32 `json:"replicas"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + NodeSelectorRequired bool `json:"nodeSelectorRequired,omitempty"` + StorageClassName string `json:"storageClassName,omitempty"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + BinlogEnabled bool `json:"binlogEnabled,omitempty"` + MaxFailoverCount int32 `json:"maxFailoverCount,omitempty"` + SeparateSlowLog bool `json:"separateSlowLog,omitempty"` + SlowLogTailer TiDBSlowLogTailerSpec `json:"slowLogTailer,omitempty"` +} + +// TiDBSlowLogTailerSpec represents an optional log tailer sidecar with TiDB +type TiDBSlowLogTailerSpec struct { + ContainerSpec } // TiKVSpec contains details of PD member diff --git a/pkg/controller/controller_utils.go b/pkg/controller/controller_utils.go index 868117a228..ece3327da6 100644 --- a/pkg/controller/controller_utils.go +++ b/pkg/controller/controller_utils.go @@ -36,6 +36,8 @@ var ( const ( // defaultPushgatewayImage is default image of pushgateway defaultPushgatewayImage = "prom/pushgateway:v0.3.1" + // defaultTiDBSlowLogImage is default image of tidb log tailer + defaultTiDBLogTailerImage = "busybox:1.26.2" ) // RequeueError is used to requeue the item, this error type should't be considered as a real error @@ -129,6 +131,13 @@ func GetPushgatewayImage(cluster *v1alpha1.TidbCluster) string { return defaultPushgatewayImage } +func GetSlowLogTailerImage(cluster *v1alpha1.TidbCluster) string { + if img := cluster.Spec.TiDB.SlowLogTailer.Image; img != "" { + return img + } + return defaultTiDBLogTailerImage +} + // PDMemberName returns pd member name func PDMemberName(clusterName string) string { return fmt.Sprintf("%s-pd", clusterName) diff --git a/pkg/controller/controller_utils_test.go b/pkg/controller/controller_utils_test.go index 8bc52abe51..23a50340d7 100644 --- a/pkg/controller/controller_utils_test.go +++ b/pkg/controller/controller_utils_test.go @@ -157,6 +157,15 @@ func TestGetPushgatewayImage(t *testing.T) { g.Expect(GetPushgatewayImage(tc)).To(Equal("image-1")) } +func TestGetSlowLogTailerImage(t *testing.T) { + g := NewGomegaWithT(t) + + tc := &v1alpha1.TidbCluster{} + g.Expect(GetSlowLogTailerImage(tc)).To(Equal(defaultTiDBLogTailerImage)) + tc.Spec.TiDB.SlowLogTailer.Image = "image-1" + g.Expect(GetSlowLogTailerImage(tc)).To(Equal("image-1")) +} + func TestPDMemberName(t *testing.T) { g := NewGomegaWithT(t) g.Expect(PDMemberName("demo")).To(Equal("demo-pd")) diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index 3b74381dbd..e0688b8253 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -14,6 +14,7 @@ package member import ( + "fmt" "strconv" "github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1" @@ -30,6 +31,12 @@ import ( corelisters "k8s.io/client-go/listers/core/v1" ) +const ( + slowQueryLogVolumeName = "slowlog" + slowQueryLogDir = "/tmp/log/tidb" + slowQueryLogFile = slowQueryLogDir + "/slowlog" +) + type tidbMemberManager struct { setControl controller.StatefulSetControlInterface svcControl controller.ServiceControlInterface @@ -240,6 +247,76 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust }, } + var containers []corev1.Container + if tc.Spec.TiDB.SeparateSlowLog { + // mount a shared volume and tail the slow log to STDOUT using a sidecar. + vols = append(vols, corev1.Volume{ + Name: slowQueryLogVolumeName, + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }) + volMounts = append(volMounts, corev1.VolumeMount{Name: slowQueryLogVolumeName, MountPath: slowQueryLogDir}) + containers = append(containers, corev1.Container{ + Name: v1alpha1.SlowLogTailerMemberType.String(), + Image: controller.GetSlowLogTailerImage(tc), + ImagePullPolicy: tc.Spec.TiDB.SlowLogTailer.ImagePullPolicy, + Resources: util.ResourceRequirement(tc.Spec.TiDB.SlowLogTailer.ContainerSpec), + VolumeMounts: []corev1.VolumeMount{ + {Name: slowQueryLogVolumeName, MountPath: slowQueryLogDir}, + }, + Command: []string{ + "sh", + "-c", + fmt.Sprintf("touch %s; tail -n0 -f %s;", slowQueryLogFile, slowQueryLogFile), + }, + }) + } + + containers = append(containers, corev1.Container{ + Name: v1alpha1.TiDBMemberType.String(), + Image: tc.Spec.TiDB.Image, + Command: []string{"/bin/sh", "/usr/local/bin/tidb_start_script.sh"}, + ImagePullPolicy: tc.Spec.TiDB.ImagePullPolicy, + Ports: []corev1.ContainerPort{ + { + Name: "server", + ContainerPort: int32(4000), + Protocol: corev1.ProtocolTCP, + }, + { + Name: "status", // pprof, status, metrics + ContainerPort: int32(10080), + Protocol: corev1.ProtocolTCP, + }, + }, + VolumeMounts: volMounts, + Resources: util.ResourceRequirement(tc.Spec.TiDB.ContainerSpec), + Env: []corev1.EnvVar{ + { + Name: "CLUSTER_NAME", + Value: tc.GetName(), + }, + { + Name: "TZ", + Value: tc.Spec.Timezone, + }, + { + Name: "BINLOG_ENABLED", + Value: strconv.FormatBool(tc.Spec.TiDB.BinlogEnabled), + }, + }, + ReadinessProbe: &corev1.Probe{ + Handler: corev1.Handler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/status", + Port: intstr.FromInt(10080), + }, + }, + InitialDelaySeconds: int32(10), + }, + }) + tidbLabel := label.New().Instance(instanceName).TiDB() tidbSet := &apps.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ @@ -264,51 +341,7 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust label.New().Instance(instanceName).TiDB(), tc.Spec.TiDB.NodeSelector, ), - Containers: []corev1.Container{ - { - Name: v1alpha1.TiDBMemberType.String(), - Image: tc.Spec.TiDB.Image, - Command: []string{"/bin/sh", "/usr/local/bin/tidb_start_script.sh"}, - ImagePullPolicy: tc.Spec.TiDB.ImagePullPolicy, - Ports: []corev1.ContainerPort{ - { - Name: "server", - ContainerPort: int32(4000), - Protocol: corev1.ProtocolTCP, - }, - { - Name: "status", // pprof, status, metrics - ContainerPort: int32(10080), - Protocol: corev1.ProtocolTCP, - }, - }, - VolumeMounts: volMounts, - Resources: util.ResourceRequirement(tc.Spec.TiDB.ContainerSpec), - Env: []corev1.EnvVar{ - { - Name: "CLUSTER_NAME", - Value: tc.GetName(), - }, - { - Name: "TZ", - Value: tc.Spec.Timezone, - }, - { - Name: "BINLOG_ENABLED", - Value: strconv.FormatBool(tc.Spec.TiDB.BinlogEnabled), - }, - }, - ReadinessProbe: &corev1.Probe{ - Handler: corev1.Handler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: "/status", - Port: intstr.FromInt(10080), - }, - }, - InitialDelaySeconds: int32(10), - }, - }, - }, + Containers: containers, RestartPolicy: corev1.RestartPolicyAlways, Tolerations: tc.Spec.TiDB.Tolerations, Volumes: vols, diff --git a/pkg/manager/member/tidb_member_manager_test.go b/pkg/manager/member/tidb_member_manager_test.go index e75288a265..2c2bdd59ea 100644 --- a/pkg/manager/member/tidb_member_manager_test.go +++ b/pkg/manager/member/tidb_member_manager_test.go @@ -558,6 +558,7 @@ func newTidbClusterForTiDB() *v1alpha1.TidbCluster { }, }, Replicas: 3, + SeparateSlowLog: true, }, }, } diff --git a/values.yml b/values.yml new file mode 100644 index 0000000000..0ddd5a1275 --- /dev/null +++ b/values.yml @@ -0,0 +1,3 @@ +scheduler: + kubeSchedulerImage: gcr.io/google-containers/hyperkube:v1.12.0 +operatorImage: aylei/tidb-operator:latest From 7b29f41fdc155f5254d7f1436e6465ef30423612 Mon Sep 17 00:00:00 2001 From: Yeh-lei Wu Date: Wed, 27 Feb 2019 12:51:13 +0800 Subject: [PATCH 2/7] Refine code and document slow-query-log operation guide Signed-off-by: Yeh-lei Wu --- .../tidb-cluster/templates/tidb-cluster.yaml | 6 ++--- docs/operation-guide.md | 27 +++++++++++++++++++ pkg/apis/pingcap.com/v1alpha1/types.go | 2 +- .../v1alpha1/zz_generated.deepcopy.go | 18 +++++++++++++ .../member/tidb_member_manager_test.go | 13 ++++++++- 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/charts/tidb-cluster/templates/tidb-cluster.yaml b/charts/tidb-cluster/templates/tidb-cluster.yaml index 444be9f4a1..beb93718a0 100644 --- a/charts/tidb-cluster/templates/tidb-cluster.yaml +++ b/charts/tidb-cluster/templates/tidb-cluster.yaml @@ -76,12 +76,10 @@ spec: {{- end }} binlogEnabled: {{ .Values.binlog.pump.create | default false }} maxFailoverCount: {{ .Values.tidb.maxFailoverCount | default 3 }} - separateSlowLog: {{ .Values.separateSlowLog | default false }} -{{- if .Values.separateSlowLog }} + separateSlowLog: {{ .Values.tidb.separateSlowLog | default false }} slowLogTailer: image: {{ .Values.tidb.slowLogTailer.image }} imagePullPolicy: {{ .Values.tidb.slowLogTailer.imagePullPolicy | default "IfNotPresent" }} {{- if .Values.tidb.slowLogTailer.resources }} - {{ toYaml .Values.tidb.slowLogTailer.resources | indent 6 }} +{{ toYaml .Values.tidb.slowLogTailer.resources | indent 6 }} {{- end }} -{{- end }} diff --git a/docs/operation-guide.md b/docs/operation-guide.md index 973367fc8f..883b5bcc46 100644 --- a/docs/operation-guide.md +++ b/docs/operation-guide.md @@ -131,6 +131,33 @@ Then open your browser at http://localhost:3000 The default username and passwor The Grafana service is exposed as `NodePort` by default, you can change it to `LoadBalancer` if the underlining Kubernetes has load balancer support. And then view the dashboard via load balancer endpoint. +### View TiDB Slow Query Log + +For default setup, tidb is configured to export slow query log to STDOUT along with normal server logs. You can obtain the slow query log by `grep` the keyword `SLOW_QUERY`: + +```shell +$ kubectl logs -n ${namespace} ${tidbPodName} | grep SLOW_QUERY +``` + +Optionally, you can output slow query log in a separate sidecar by enabling `separateSlowLog`: + +```yaml +# Uncomment the following line to enable separate output of the slow query log + # separateSlowLog: true +``` + +Run `helm upgrade` to apply the change, then you can obtain the slow query log from the sidecar named `slowlog`: + +```shell +$ kubectl logs -n ${namespace} ${tidbPodName} -c slowlog +``` + +To retrieve logs from multiple pods, [`stern`](https://github.com/wercker/stern) is recommended. + +```shell +$ stern -n ${namespace} tidb -c slowlog +``` + ## Backup Currently, TiDB Operator supports two kinds of backup: incremental backup via binlog and full backup(scheduled or ad-hoc) via [Mydumper](https://github.com/maxbube/mydumper). diff --git a/pkg/apis/pingcap.com/v1alpha1/types.go b/pkg/apis/pingcap.com/v1alpha1/types.go index 030fc634d4..ae717ef56e 100644 --- a/pkg/apis/pingcap.com/v1alpha1/types.go +++ b/pkg/apis/pingcap.com/v1alpha1/types.go @@ -45,7 +45,7 @@ const ( // PushGatewayMemberType is pushgateway container type PushGatewayMemberType MemberType = "pushgateway" // TiDBLogTailerMemberType is tidb log tailer container type - SlowLogTailerMemberType MemberType = "slowlog-tailer" + SlowLogTailerMemberType MemberType = "slowlog" // UnknownMemberType is unknown container type UnknownMemberType MemberType = "unknown" ) diff --git a/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go index 66070042d2..9ae44e85c5 100644 --- a/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pingcap.com/v1alpha1/zz_generated.deepcopy.go @@ -217,6 +217,23 @@ func (in *TiDBMember) DeepCopy() *TiDBMember { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TiDBSlowLogTailerSpec) DeepCopyInto(out *TiDBSlowLogTailerSpec) { + *out = *in + in.ContainerSpec.DeepCopyInto(&out.ContainerSpec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TiDBSlowLogTailerSpec. +func (in *TiDBSlowLogTailerSpec) DeepCopy() *TiDBSlowLogTailerSpec { + if in == nil { + return nil + } + out := new(TiDBSlowLogTailerSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TiDBSpec) DeepCopyInto(out *TiDBSpec) { *out = *in @@ -235,6 +252,7 @@ func (in *TiDBSpec) DeepCopyInto(out *TiDBSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + in.SlowLogTailer.DeepCopyInto(&out.SlowLogTailer) return } diff --git a/pkg/manager/member/tidb_member_manager_test.go b/pkg/manager/member/tidb_member_manager_test.go index 2c2bdd59ea..611ab7d475 100644 --- a/pkg/manager/member/tidb_member_manager_test.go +++ b/pkg/manager/member/tidb_member_manager_test.go @@ -209,6 +209,18 @@ func TestTiDBMemberManagerSyncUpdate(t *testing.T) { g.Expect(err).NotTo(HaveOccurred()) }, }, + { + name: "enable separate slowlog on the fly", + modify: func(tc *v1alpha1.TidbCluster) { + tc.Spec.TiDB.SeparateSlowLog = true + }, + errWhenUpdateStatefulSet: false, + err: false, + expectStatefulSetFn: func(g *GomegaWithT, set *apps.StatefulSet, err error) { + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(set.Spec.Template.Spec.Containers).To(HaveLen(2)) + }, + }, } for i := range tests { @@ -558,7 +570,6 @@ func newTidbClusterForTiDB() *v1alpha1.TidbCluster { }, }, Replicas: 3, - SeparateSlowLog: true, }, }, } From 7a7fbac3777be5ac1d9170dfb1e12180c4e057bd Mon Sep 17 00:00:00 2001 From: Yeh-lei Wu Date: Wed, 27 Feb 2019 13:02:52 +0800 Subject: [PATCH 3/7] Delete unwanted file --- values.yml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 values.yml diff --git a/values.yml b/values.yml deleted file mode 100644 index 0ddd5a1275..0000000000 --- a/values.yml +++ /dev/null @@ -1,3 +0,0 @@ -scheduler: - kubeSchedulerImage: gcr.io/google-containers/hyperkube:v1.12.0 -operatorImage: aylei/tidb-operator:latest From 970c06bba92f96d13e0143adb74f9fbd6c617a14 Mon Sep 17 00:00:00 2001 From: Yeh-lei Wu Date: Wed, 27 Feb 2019 20:02:08 +0800 Subject: [PATCH 4/7] Change log dir to /var/log/tidb --- pkg/apis/pingcap.com/v1alpha1/types.go | 2 +- pkg/manager/member/tidb_member_manager.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/apis/pingcap.com/v1alpha1/types.go b/pkg/apis/pingcap.com/v1alpha1/types.go index ae717ef56e..458543df41 100644 --- a/pkg/apis/pingcap.com/v1alpha1/types.go +++ b/pkg/apis/pingcap.com/v1alpha1/types.go @@ -44,7 +44,7 @@ const ( TiKVMemberType MemberType = "tikv" // PushGatewayMemberType is pushgateway container type PushGatewayMemberType MemberType = "pushgateway" - // TiDBLogTailerMemberType is tidb log tailer container type + // SlowLogTailerMemberType is tidb log tailer container type SlowLogTailerMemberType MemberType = "slowlog" // UnknownMemberType is unknown container type UnknownMemberType MemberType = "unknown" diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index e0688b8253..356d936bc0 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -33,7 +33,7 @@ import ( const ( slowQueryLogVolumeName = "slowlog" - slowQueryLogDir = "/tmp/log/tidb" + slowQueryLogDir = "/var/log/tidb" slowQueryLogFile = slowQueryLogDir + "/slowlog" ) From cd0fec89fcf04156f9a7d8ddc42f716e378e8b86 Mon Sep 17 00:00:00 2001 From: Yeh-lei Wu Date: Thu, 28 Feb 2019 10:20:43 +0800 Subject: [PATCH 5/7] tail with -F to handle log rotating --- pkg/manager/member/tidb_member_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index 356d936bc0..42c4779b6a 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -268,7 +268,7 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust Command: []string{ "sh", "-c", - fmt.Sprintf("touch %s; tail -n0 -f %s;", slowQueryLogFile, slowQueryLogFile), + fmt.Sprintf("touch %s; tail -n0 -F %s;", slowQueryLogFile, slowQueryLogFile), }, }) } From 7b12348561353e6dbd62bc76b6078f459ade2558 Mon Sep 17 00:00:00 2001 From: Yeh-lei Wu Date: Fri, 1 Mar 2019 23:12:39 +0800 Subject: [PATCH 6/7] Specify resources request; using command line flag to control slow log file --- .../templates/config/_tidb-config.tpl | 4 --- .../templates/scripts/_start_tidb.sh.tpl | 5 +++ charts/tidb-cluster/values.yaml | 12 +++---- pkg/manager/member/tidb_member_manager.go | 35 +++++++++++-------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/charts/tidb-cluster/templates/config/_tidb-config.tpl b/charts/tidb-cluster/templates/config/_tidb-config.tpl index 10e43636bd..56525ec41f 100644 --- a/charts/tidb-cluster/templates/config/_tidb-config.tpl +++ b/charts/tidb-cluster/templates/config/_tidb-config.tpl @@ -59,11 +59,7 @@ format = "text" disable-timestamp = false # Stores slow query log into separated files. -{{- if .Values.tidb.separateSlowLog }} -slow-query-file = "/tmp/log/tidb/slowlog" -{{- else }} slow-query-file = "" -{{- end }} # Queries with execution time greater than this value will be logged. (Milliseconds) slow-threshold = 300 diff --git a/charts/tidb-cluster/templates/scripts/_start_tidb.sh.tpl b/charts/tidb-cluster/templates/scripts/_start_tidb.sh.tpl index 06b60e58c8..f223992c4f 100644 --- a/charts/tidb-cluster/templates/scripts/_start_tidb.sh.tpl +++ b/charts/tidb-cluster/templates/scripts/_start_tidb.sh.tpl @@ -34,6 +34,11 @@ then ARGS="${ARGS} --enable-binlog=true" fi +if [[ ! -z "${SLOW_LOG_FILE}" ]] +then + ARGS="${ARGS} --log-slow-query=${SLOW_LOG_FILE:-}" +fi + echo "start tidb-server ..." echo "/tidb-server ${ARGS}" exec /tidb-server ${ARGS} diff --git a/charts/tidb-cluster/values.yaml b/charts/tidb-cluster/values.yaml index 59d909804b..a9b007becf 100644 --- a/charts/tidb-cluster/values.yaml +++ b/charts/tidb-cluster/values.yaml @@ -179,12 +179,12 @@ tidb: slowLogTailer: image: busybox:1.26.2 resources: - limits: {} - # cpu: 50m - # memory: 10Mi - requests: {} - # cpu: 50m - # memory: 10Mi + limits: + cpu: 100m + memory: 50Mi + requests: + cpu: 20m + memory: 5Mi # mysqlClient is used to set password for TiDB mysqlClient: diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index 42c4779b6a..dd0b7a49a0 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -273,6 +273,26 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust }) } + envs := []corev1.EnvVar{ + { + Name: "CLUSTER_NAME", + Value: tc.GetName(), + }, + { + Name: "TZ", + Value: tc.Spec.Timezone, + }, + { + Name: "BINLOG_ENABLED", + Value: strconv.FormatBool(tc.Spec.TiDB.BinlogEnabled), + }, + }; + if tc.Spec.TiDB.SeparateSlowLog { + envs = append(envs, corev1.EnvVar{ + Name: "SLOW_LOG_FILE", + Value: slowQueryLogFile, + }) + } containers = append(containers, corev1.Container{ Name: v1alpha1.TiDBMemberType.String(), Image: tc.Spec.TiDB.Image, @@ -292,20 +312,7 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust }, VolumeMounts: volMounts, Resources: util.ResourceRequirement(tc.Spec.TiDB.ContainerSpec), - Env: []corev1.EnvVar{ - { - Name: "CLUSTER_NAME", - Value: tc.GetName(), - }, - { - Name: "TZ", - Value: tc.Spec.Timezone, - }, - { - Name: "BINLOG_ENABLED", - Value: strconv.FormatBool(tc.Spec.TiDB.BinlogEnabled), - }, - }, + Env: envs, ReadinessProbe: &corev1.Probe{ Handler: corev1.Handler{ HTTPGet: &corev1.HTTPGetAction{ From de0f511c4866b32e3a7cceb13fe47f7cadddca59 Mon Sep 17 00:00:00 2001 From: Yeh-lei Wu Date: Sat, 2 Mar 2019 15:31:01 +0800 Subject: [PATCH 7/7] Code format --- pkg/manager/member/tidb_member_manager.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/manager/member/tidb_member_manager.go b/pkg/manager/member/tidb_member_manager.go index dd0b7a49a0..f2e713dee3 100644 --- a/pkg/manager/member/tidb_member_manager.go +++ b/pkg/manager/member/tidb_member_manager.go @@ -286,10 +286,10 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust Name: "BINLOG_ENABLED", Value: strconv.FormatBool(tc.Spec.TiDB.BinlogEnabled), }, - }; + } if tc.Spec.TiDB.SeparateSlowLog { envs = append(envs, corev1.EnvVar{ - Name: "SLOW_LOG_FILE", + Name: "SLOW_LOG_FILE", Value: slowQueryLogFile, }) } @@ -312,7 +312,7 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust }, VolumeMounts: volMounts, Resources: util.ResourceRequirement(tc.Spec.TiDB.ContainerSpec), - Env: envs, + Env: envs, ReadinessProbe: &corev1.Probe{ Handler: corev1.Handler{ HTTPGet: &corev1.HTTPGetAction{