Skip to content

Commit

Permalink
feat(cluster/spec): check alertmanager,prometheus's config
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvisa committed Jan 26, 2021
1 parent 7f94ef7 commit 8a53374
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
5 changes: 4 additions & 1 deletion pkg/cluster/spec/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ func (i *AlertManagerInstance) InitConfig(
if err := config.NewAlertManagerConfig().ConfigToFile(configPath); err != nil {
return err
}
return i.TransferLocalConfigFile(ctx, e, configPath, dst)
if err := i.TransferLocalConfigFile(ctx, e, configPath, dst); err != nil {
return err
}
return checkConfig(ctx, e, i.ComponentName(), clusterVersion, i.OS(), i.Arch(), i.ComponentName()+".yml", paths, nil)
}

// ScaleConfig deploy temporary config on scaling
Expand Down
6 changes: 5 additions & 1 deletion pkg/cluster/spec/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ func (i *MonitorInstance) InitConfig(
return err
}
dst = filepath.Join(paths.Deploy, "conf", "prometheus.yml")
return e.Transfer(ctx, fp, dst, false)
if err := e.Transfer(ctx, fp, dst, false); err != nil {
return err
}

return checkConfig(ctx, e, i.ComponentName(), clusterVersion, i.OS(), i.Arch(), i.ComponentName()+".yml", paths, nil)
}

// We only really installRules for dm cluster because the rules(*.rules.yml) packed with the prometheus
Expand Down
58 changes: 34 additions & 24 deletions pkg/cluster/spec/server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
"github.com/pingcap/tiup/pkg/cluster/ctxt"
"github.com/pingcap/tiup/pkg/cluster/executor"
"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/meta"
"github.com/pingcap/tiup/pkg/utils"
Expand Down Expand Up @@ -235,36 +236,45 @@ func mergeImported(importConfig []byte, specConfigs ...map[string]interface{}) (
// BindVersion map the cluster version to the third components binding version.
type BindVersion func(comp string, version string) (bindVersion string)

func checkConfig(ctx context.Context, e ctxt.Executor, componentName, clusterVersion, nodeOS, arch, config string, paths meta.DirPaths, bindVersion BindVersion) error {
repo, err := clusterutil.NewRepository(nodeOS, arch)
if err != nil {
return perrs.Annotate(ErrorCheckConfig, err.Error())
}
func checkConfig(ctx context.Context, e executor.Executor, componentName, clusterVersion, nodeOS, arch, config string, paths meta.DirPaths, bindVersion BindVersion) error {
var cmd string
configPath := path.Join(paths.Deploy, "conf", config)
switch componentName {
case ComponentPrometheus:
cmd = fmt.Sprintf("%s/bin/prometheus/promtool check config %s", paths.Deploy, configPath)
case ComponentAlertmanager:
cmd = fmt.Sprintf("%s/bin/alertmanager/amtool check-config %s", paths.Deploy, configPath)
default:
repo, err := clusterutil.NewRepository(nodeOS, arch)
if err != nil {
return perrs.Annotate(ErrorCheckConfig, err.Error())
}

ver := clusterVersion
if bindVersion != nil {
ver = bindVersion(componentName, clusterVersion)
}
ver := clusterVersion
if bindVersion != nil {
ver = bindVersion(componentName, clusterVersion)
}

entry, err := repo.ComponentBinEntry(componentName, ver)
if err != nil {
return perrs.Annotate(ErrorCheckConfig, err.Error())
}
entry, err := repo.ComponentBinEntry(componentName, ver)
if err != nil {
return perrs.Annotate(ErrorCheckConfig, err.Error())
}
binPath := path.Join(paths.Deploy, "bin", entry)

binPath := path.Join(paths.Deploy, "bin", entry)
// Skip old versions
if !hasConfigCheckFlag(ctx, e, binPath) {
return nil
}
// Skip old versions
if !hasConfigCheckFlag(ctx, e, binPath) {
return nil
}

// Hack tikv --pd flag
extra := ""
if componentName == ComponentTiKV {
extra = `--pd=""`
// Hack tikv --pd flag
extra := ""
if componentName == ComponentTiKV {
extra = `--pd=""`
}
cmd = fmt.Sprintf("%s --config-check --config=%s %s", binPath, configPath, extra)
}

configPath := path.Join(paths.Deploy, "conf", config)
_, _, err = e.Execute(ctx, fmt.Sprintf("%s --config-check --config=%s %s", binPath, configPath, extra), false)
_, _, err := e.Execute(cmd, false)
if err != nil {
return perrs.Annotate(ErrorCheckConfig, err.Error())
}
Expand Down

0 comments on commit 8a53374

Please sign in to comment.