-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cluster/spec): check alertmanager,prometheus's config (#1074)
* feat(cluster/spec): check alertmanager,prometheus's config * fix(cluster/spec): convert to ctxt.Executor * fix(cluster/spec): use find cp instead of cp *.json(zsh compatible) * enhance(cluster/spec): use find cp instead of cp for dm's grafana,prometheus * fix(cluster/spec): index error * feat(cluster/spec): add prometheus testcase * feat(*): rm not used dm/prometheus.yml.tpl * feat(cluster/spec): test Prometheus localDir * fix(template/prometheus): if local rules were given, system rules won't auto copyed * feat(clutster): make pkger * feat(tests/cluster): ensure tidb exists in prometheus.yml
- Loading branch information
Showing
10 changed files
with
182 additions
and
78 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// 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 spec | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"os" | ||
"os/user" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/pingcap/tiup/pkg/checkpoint" | ||
"github.com/pingcap/tiup/pkg/cluster/executor" | ||
"github.com/pingcap/tiup/pkg/meta" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLocalRuleDirs(t *testing.T) { | ||
deployDir, err := ioutil.TempDir("", "tiup-*") | ||
assert.Nil(t, err) | ||
defer os.RemoveAll(deployDir) | ||
err = os.MkdirAll(path.Join(deployDir, "bin/prometheus"), 0755) | ||
assert.Nil(t, err) | ||
localDir, err := filepath.Abs("./testdata/rules") | ||
assert.Nil(t, err) | ||
|
||
err = ioutil.WriteFile(path.Join(deployDir, "bin/prometheus", "dummy.rules.yml"), []byte("dummy"), 0644) | ||
assert.Nil(t, err) | ||
|
||
topo := new(Specification) | ||
topo.Monitors = append(topo.Monitors, PrometheusSpec{ | ||
Host: "127.0.0.1", | ||
Port: 9090, | ||
RuleDir: localDir, | ||
}) | ||
|
||
comp := MonitorComponent{topo} | ||
ints := comp.Instances() | ||
|
||
assert.Equal(t, len(ints), 1) | ||
promInstance := ints[0].(*MonitorInstance) | ||
|
||
user, err := user.Current() | ||
assert.Nil(t, err) | ||
e, err := executor.New(executor.SSHTypeNone, false, executor.SSHConfig{Host: "127.0.0.1", User: user.Username}) | ||
assert.Nil(t, err) | ||
|
||
ctx := checkpoint.NewContext(context.Background()) | ||
err = promInstance.initRules(ctx, e, promInstance.InstanceSpec.(PrometheusSpec), meta.DirPaths{Deploy: deployDir}) | ||
assert.Nil(t, err) | ||
|
||
assert.NoFileExists(t, path.Join(deployDir, "conf", "dummy.rules.yml")) | ||
fs, err := ioutil.ReadDir(localDir) | ||
assert.Nil(t, err) | ||
for _, f := range fs { | ||
assert.FileExists(t, path.Join(deployDir, "conf", f.Name())) | ||
} | ||
} | ||
|
||
func TestNoLocalRuleDirs(t *testing.T) { | ||
deployDir, err := ioutil.TempDir("", "tiup-*") | ||
assert.Nil(t, err) | ||
defer os.RemoveAll(deployDir) | ||
err = os.MkdirAll(path.Join(deployDir, "bin/prometheus"), 0755) | ||
assert.Nil(t, err) | ||
localDir, err := filepath.Abs("./testdata/rules") | ||
assert.Nil(t, err) | ||
|
||
err = ioutil.WriteFile(path.Join(deployDir, "bin/prometheus", "dummy.rules.yml"), []byte("dummy"), 0644) | ||
assert.Nil(t, err) | ||
|
||
topo := new(Specification) | ||
topo.Monitors = append(topo.Monitors, PrometheusSpec{ | ||
Host: "127.0.0.1", | ||
Port: 9090, | ||
}) | ||
|
||
comp := MonitorComponent{topo} | ||
ints := comp.Instances() | ||
|
||
assert.Equal(t, len(ints), 1) | ||
promInstance := ints[0].(*MonitorInstance) | ||
|
||
user, err := user.Current() | ||
assert.Nil(t, err) | ||
e, err := executor.New(executor.SSHTypeNone, false, executor.SSHConfig{Host: "127.0.0.1", User: user.Username}) | ||
assert.Nil(t, err) | ||
|
||
ctx := checkpoint.NewContext(context.Background()) | ||
err = promInstance.initRules(ctx, e, promInstance.InstanceSpec.(PrometheusSpec), meta.DirPaths{Deploy: deployDir}) | ||
assert.Nil(t, err) | ||
|
||
assert.FileExists(t, path.Join(deployDir, "conf", "dummy.rules.yml")) | ||
fs, err := ioutil.ReadDir(localDir) | ||
assert.Nil(t, err) | ||
for _, f := range fs { | ||
assert.NoFileExists(t, path.Join(deployDir, "conf", f.Name())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# magic-string-for-test | ||
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters