Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure SLOW_LOG_FILE env variable is always set #298

Merged
merged 5 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion images/tidb-operator-e2e/tidb-cluster-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ tidb:
exposeStatus: true
# annotations:
# cloud.google.com/load-balancer-type: Internal
separateSlowLog: true

# mysqlClient is used to set password for TiDB
# it must has Python MySQL client installed
Expand Down
13 changes: 8 additions & 5 deletions pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust
})
}

slowLogFileEnvVal := ""
if tc.Spec.TiDB.SeparateSlowLog {
slowLogFileEnvVal = slowQueryLogFile
}
envs := []corev1.EnvVar{
{
Name: "CLUSTER_NAME",
Expand All @@ -286,13 +290,12 @@ 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",
Value: slowQueryLogFile,
})
Value: slowLogFileEnvVal,
},
}

containers = append(containers, corev1.Container{
Name: v1alpha1.TiDBMemberType.String(),
Image: tc.Spec.TiDB.Image,
Expand Down
7 changes: 4 additions & 3 deletions tests/e2e/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ type Response struct {
}
}

func testCreate(ns, clusterName string) {
func testCreate(spec clusterSpec) {
ns, clusterName := spec.ns, spec.clusterName
By(fmt.Sprintf("When create the TiDB cluster: %s/%s", ns, clusterName))
instanceName := getInstanceName(ns, clusterName)

cmdStr := fmt.Sprintf("helm install /charts/tidb-cluster -f /tidb-cluster-values.yaml"+
" -n %s --namespace=%s --set clusterName=%s,tidb.passwordSecretName=%s",
instanceName, ns, clusterName, ns+"-"+clusterName)
" -n %s --namespace=%s --set %s",
instanceName, ns, buildSetFlag(spec))
_, err := execCmd(cmdStr)
Expect(err).NotTo(HaveOccurred())

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var _ = Describe("Smoke", func() {
fixture := fixtures[i]
It(fmt.Sprintf("Namespace: %s, clusterName: %s", fixture.ns, fixture.clusterName), func() {
for _, testCase := range fixture.cases {
testCase(fixture.ns, fixture.clusterName)
testCase(fixture.clusterSpec)
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const (

var podUIDsBeforeScale map[string]types.UID

func testScale(ns, clusterName string) {
func testScale(spec clusterSpec) {
ns, clusterName := spec.ns, spec.clusterName
instanceName := getInstanceName(ns, clusterName)
By(fmt.Sprintf("When scale out TiDB cluster: pd ==> [%d], tikv ==> [%d], tidb ==> [%d]", pdScaleOutTo, tikvScaleOutTo, tidbScaleOutTo))
err := wait.Poll(5*time.Second, 5*time.Minute, func() (bool, error) {
Expand Down
48 changes: 39 additions & 9 deletions tests/e2e/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package e2e

import (
"bytes"
"fmt"
"os/exec"
"sort"
Expand Down Expand Up @@ -42,36 +43,56 @@ var (
kubeCli kubernetes.Interface
)

type clusterFixture struct {
type clusterSpec struct {
ns string
clusterName string
cases []testCase

// values override the specified helm values
values map[string]string
}

type clusterFixture struct {
clusterSpec

cases []testCase
}

type testCase func(ns, name string)
type testCase func(cluster clusterSpec)

var fixtures = []clusterFixture{
{
ns: "ns-1",
clusterName: "cluster-name-1",
clusterSpec: clusterSpec{
ns: "ns-1",
clusterName: "cluster-name-1",
},
cases: []testCase{
testCreate,
testScale,
testUpgrade,
},
},
{
ns: "ns-1",
clusterName: "cluster-name-2",
clusterSpec: clusterSpec{
ns: "ns-1",
clusterName: "cluster-name-2",
values: map[string]string{
"tidb.separateSlowLog": "true",
aylei marked this conversation as resolved.
Show resolved Hide resolved
},
},
cases: []testCase{
testCreate,
testUpgrade,
testScale,
},
},
{
ns: "ns-2",
clusterName: "cluster-name-1",
clusterSpec: clusterSpec{
ns: "ns-2",
clusterName: "cluster-name-1",
values: map[string]string{
"tidb.separateSlowLog": "false",
},
},
cases: []testCase{
testCreate,
testScale,
Expand All @@ -89,6 +110,15 @@ var fixtures = []clusterFixture{
// },
}

func buildSetFlag(spec clusterSpec) string {
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintf("clusterName=%s,tidb.passwordSecretName=%s", spec.clusterName, spec.ns+"-"+spec.clusterName))
for k, v := range spec.values {
buffer.WriteString(fmt.Sprintf(",%s=%s", k, v))
}
return buffer.String()
}

func clearOperator() error {
for _, fixture := range fixtures {
_, err := execCmd(fmt.Sprintf("helm del --purge %s", fmt.Sprintf("%s-%s", fixture.ns, fixture.clusterName)))
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const (
upgradeVersion = "v2.1.0"
)

func testUpgrade(ns, clusterName string) {
func testUpgrade(spec clusterSpec) {
ns, clusterName := spec.ns, spec.clusterName
pdNodeMap, err := getNodeMap(ns, clusterName, label.PDLabelVal)
Expect(err).NotTo(HaveOccurred())
tikvNodeMap, err := getNodeMap(ns, clusterName, label.TiKVLabelVal)
Expand Down