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

Refresh monitor configs on reload #630

Merged
merged 3 commits into from
Jul 27, 2020
Merged
Changes from 1 commit
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
60 changes: 59 additions & 1 deletion components/cluster/command/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ package command

import (
"errors"
"fmt"
"path/filepath"
"strings"

"github.com/joomcode/errorx"
perrs "github.com/pingcap/errors"
Expand Down Expand Up @@ -100,8 +103,17 @@ func buildReloadTask(

topo := metadata.Topology
hasImported := false
uniqueHosts := make(map[string]hostInfo) // host -> ssh-port, os, arch

topo.IterInstance(func(inst spec.Instance) {
if _, found := uniqueHosts[inst.GetHost()]; !found {
uniqueHosts[inst.GetHost()] = hostInfo{
ssh: inst.GetSSHPort(),
os: inst.OS(),
arch: inst.Arch(),
}
}

deployDir := clusterutil.Abs(metadata.User, inst.DeployDir())
// data dir would be empty for components which don't need it
dataDirs := clusterutil.MultiDirAbs(metadata.User, inst.DataDir())
Expand Down Expand Up @@ -142,6 +154,8 @@ func buildReloadTask(
refreshConfigTasks = append(refreshConfigTasks, t)
})

monitorConfigTasks := refreshMonitoredConfigTask(clusterName, uniqueHosts, topo.GlobalOptions, topo.MonitoredOptions)

// handle dir scheme changes
if hasImported {
if err := spec.HandleImportPathMigration(clusterName); err != nil {
Expand All @@ -154,13 +168,57 @@ func buildReloadTask(
spec.ClusterPath(clusterName, "ssh", "id_rsa"),
spec.ClusterPath(clusterName, "ssh", "id_rsa.pub")).
ClusterSSH(metadata.Topology, metadata.User, gOpt.SSHTimeout).
Parallel(refreshConfigTasks...)
Parallel(refreshConfigTasks...).
lucklove marked this conversation as resolved.
Show resolved Hide resolved
ParallelStep("+ Refresh monitor configs", monitorConfigTasks...)
if !skipRestart {
tb = tb.ClusterOperate(metadata.Topology, operator.UpgradeOperation, options)
}
return tb.Build(), nil
}

func refreshMonitoredConfigTask(
clusterName string,
uniqueHosts map[string]hostInfo, // host -> ssh-port, os, arch
globalOptions spec.GlobalOptions,
monitoredOptions spec.MonitoredOptions,
) []*task.StepDisplay {
tasks := []*task.StepDisplay{}
// monitoring agents
for _, comp := range []string{spec.ComponentNodeExporter, spec.ComponentBlackboxExporter} {
for host, info := range uniqueHosts {
deployDir := clusterutil.Abs(globalOptions.User, monitoredOptions.DeployDir)
// data dir would be empty for components which don't need it
dataDir := monitoredOptions.DataDir
// the default data_dir is relative to deploy_dir
if dataDir != "" && !strings.HasPrefix(dataDir, "/") {
dataDir = filepath.Join(deployDir, dataDir)
}
// log dir will always be with values, but might not used by the component
logDir := clusterutil.Abs(globalOptions.User, monitoredOptions.LogDir)
// Deploy component
lucklove marked this conversation as resolved.
Show resolved Hide resolved
t := task.NewBuilder().
UserSSH(host, info.ssh, globalOptions.User, gOpt.SSHTimeout).
MonitoredConfig(
clusterName,
comp,
host,
globalOptions.ResourceControl,
monitoredOptions,
globalOptions.User,
meta.DirPaths{
Deploy: deployDir,
Data: []string{dataDir},
Log: logDir,
Cache: spec.ClusterPath(clusterName, spec.TempConfigPath),
},
).
BuildAsStep(fmt.Sprintf(" - Refresh config %s -> %s", comp, host))
tasks = append(tasks, t)
}
}
return tasks
}

func validRoles(roles []string) error {
for _, r := range roles {
match := false
Expand Down