Skip to content

Commit

Permalink
cluster,tests: add test case of ENV_LABELS_ENV be replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
9547 committed Mar 23, 2021
1 parent b0e2436 commit 32108d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/cluster/spec/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestLocalRuleDirs(t *testing.T) {
assert.Nil(t, err)

ctx := checkpoint.NewContext(context.Background())
err = promInstance.initRules(ctx, e, promInstance.InstanceSpec.(*PrometheusSpec), meta.DirPaths{Deploy: deployDir})
err = promInstance.initRules(ctx, e, promInstance.InstanceSpec.(*PrometheusSpec), meta.DirPaths{Deploy: deployDir}, "dummy-cluster")
assert.Nil(t, err)

assert.NoFileExists(t, path.Join(deployDir, "conf", "dummy.rules.yml"))
Expand All @@ -78,7 +78,22 @@ func TestNoLocalRuleDirs(t *testing.T) {
localDir, err := filepath.Abs("./testdata/rules")
assert.Nil(t, err)

err = os.WriteFile(path.Join(deployDir, "bin/prometheus", "dummy.rules.yml"), []byte("dummy"), 0644)
err = os.WriteFile(path.Join(deployDir, "bin/prometheus", "dummy.rules.yml"), []byte(`
groups:
- name: alert.rules
rules:
- alert: TiDB_schema_error
expr: increase(tidb_session_schema_lease_error_total{type="outdated"}[15m]) > 0
for: 1m
labels:
env: ENV_LABELS_ENV
level: emergency
expr: increase(tidb_session_schema_lease_error_total{type="outdated"}[15m]) > 0
annotations:
description: "cluster: ENV_LABELS_ENV, instance: {{ $labels.instance }}, values:{{ $value }}"
value: "{{ $value }}"
summary: TiDB schema error
`), 0644)
assert.Nil(t, err)

topo := new(Specification)
Expand All @@ -99,8 +114,12 @@ func TestNoLocalRuleDirs(t *testing.T) {
assert.Nil(t, err)

ctx := checkpoint.NewContext(context.Background())
err = promInstance.initRules(ctx, e, promInstance.InstanceSpec.(*PrometheusSpec), meta.DirPaths{Deploy: deployDir})
err = promInstance.initRules(ctx, e, promInstance.InstanceSpec.(*PrometheusSpec), meta.DirPaths{Deploy: deployDir}, "dummy-cluster")
assert.Nil(t, err)
body, err := os.ReadFile(path.Join(deployDir, "conf", "dummy.rules.yml"))
assert.Nil(t, err)
assert.Contains(t, string(body), "dummy-cluster")
assert.NotContains(t, string(body), "ENV_LABELS_ENV")

assert.FileExists(t, path.Join(deployDir, "conf", "dummy.rules.yml"))
fs, err := os.ReadDir(localDir)
Expand Down
2 changes: 2 additions & 0 deletions tests/tiup-cluster/test_upgrade_tls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mkdir -p ~/.tiup/bin && cp -f ./root.json ~/.tiup/bin/
yes | tiup-cluster deploy $name $old_version $topo -i ~/.ssh/id_rsa

yes | tiup-cluster start $name
tiup-cluster exec $name -N n1 --command "grep -q ${name} /home/tidb/deploy/prometheus-9090/conf/*.rules.yml"
! tiup-cluster exec $name -N n1 --command "grep -q ENV_LABELS_ENV /home/tidb/deploy/prometheus-9090/conf/*.rules.yml"

tiup-cluster _test $name writable

Expand Down

0 comments on commit 32108d4

Please sign in to comment.