Skip to content

Commit

Permalink
Merge c9516d9 into 52e24c2
Browse files Browse the repository at this point in the history
  • Loading branch information
lucklove authored Apr 7, 2021
2 parents 52e24c2 + c9516d9 commit 3d94ad4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions components/dm/ansible/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin
case "dm_master_servers":
for _, host := range group.Hosts {
srv := &spec.MasterSpec{
Host: host.Vars["ansible_host"],
SSHPort: ansible.GetHostPort(host, cfg),
Host: host.Vars["ansible_host"],
SSHPort: ansible.GetHostPort(host, cfg),
Imported: true,
}

runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_dm-master.sh")
Expand Down Expand Up @@ -380,6 +381,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin
Host: host.Vars["ansible_host"],
SSHPort: ansible.GetHostPort(host, cfg),
DeployDir: firstNonEmpty(host.Vars["deploy_dir"], topo.GlobalOptions.DeployDir),
Imported: true,
}

runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_dm-worker.sh")
Expand Down Expand Up @@ -441,6 +443,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin
Host: host.Vars["ansible_host"],
SSHPort: ansible.GetHostPort(host, cfg),
DeployDir: firstNonEmpty(host.Vars["deploy_dir"], topo.GlobalOptions.DeployDir),
Imported: true,
}

runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_prometheus.sh")
Expand Down Expand Up @@ -489,6 +492,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin
Host: host.Vars["ansible_host"],
SSHPort: ansible.GetHostPort(host, cfg),
DeployDir: firstNonEmpty(host.Vars["deploy_dir"], topo.GlobalOptions.DeployDir),
Imported: true,
}

runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_alertmanager.sh")
Expand Down Expand Up @@ -546,6 +550,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin
Port: port,
Username: grafanaUser,
Password: grafanaPass,
Imported: true,
}

runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_grafana.sh")
Expand Down
5 changes: 5 additions & 0 deletions components/dm/ansible/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func TestImportFromAnsible(t *testing.T) {
DeployDir: "",
LogDir: "/home/tidb/deploy/log",
Config: map[string]interface{}{"log-level": "info"},
Imported: true,
}
assert.Equal(expectedMaster, master)

Expand All @@ -180,6 +181,7 @@ func TestImportFromAnsible(t *testing.T) {
DeployDir: "/home/tidb/deploy",
LogDir: "/home/tidb/deploy/log",
Config: map[string]interface{}{"log-level": "info"},
Imported: true,
}

worker := topo.Workers[0]
Expand All @@ -199,6 +201,7 @@ func TestImportFromAnsible(t *testing.T) {
DeployDir: "",
DataDir: "/home/tidb/deploy/data.alertmanager",
LogDir: "/home/tidb/deploy/log",
Imported: true,
}
assert.Equal(expectedAlter, aler)

Expand All @@ -212,6 +215,7 @@ func TestImportFromAnsible(t *testing.T) {
Port: 3001,
Username: "foo",
Password: "bar",
Imported: true,
}
assert.Equal(expectedGrafana, grafana)

Expand All @@ -225,6 +229,7 @@ func TestImportFromAnsible(t *testing.T) {
DataDir: "/home/tidb/deploy/prometheus.data.metrics",
LogDir: "/home/tidb/deploy/log",
Port: 9090,
Imported: true,
}
assert.Equal(expectedMonitor, monitor)

Expand Down
5 changes: 3 additions & 2 deletions pkg/cluster/manager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ func (m *Manager) Deploy(
iterErr = nil
topo.IterInstance(func(inst spec.Instance) {
if _, found := uniqueHosts[inst.GetHost()]; !found {
// check for "imported" parameter, it can not be true when scaling out
if inst.IsImported() {
// check for "imported" parameter, it can not be true when deploying and scaling out
// only for tidb now, need to support dm
if inst.IsImported() && m.sysName == "tidb" {
iterErr = errors.New(
"'imported' is set to 'true' for new instance, this is only used " +
"for instances imported from tidb-ansible and make no sense when " +
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/spec/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (i *MonitorInstance) initRules(ctx context.Context, e ctxt.Executor, spec *
"mkdir -p %[1]s/conf",
`find %[1]s/conf -type f -name "*.rules.yml" -delete`,
`find %[1]s/bin/prometheus -maxdepth 1 -type f -name "*.rules.yml" -exec cp {} %[1]s/conf/ \;`,
`find %[1]s/conf -maxdepth 1 -type f -name "*.rules.yml" -exec sed -i "s/ENV_LABELS_ENV/%[2]s/g" {} \;`,
`find %[1]s/conf -maxdepth 1 -type f -name "*.rules.yml" -exec sed -i -e "s/ENV_LABELS_ENV/%[2]s/g" {} \;`,
}
_, stderr, err := e.Execute(ctx, fmt.Sprintf(strings.Join(cmds, " && "), paths.Deploy, clusterName), false)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cluster/spec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func CheckClusterDirOverlap(entries []DirEntry) error {
}

if utils.IsSubDir(d1.dir, d2.dir) || utils.IsSubDir(d2.dir, d1.dir) {
if d1.instance.IsImported() && d2.instance.IsImported() {
continue
}
properties := map[string]string{
"ThisDirKind": d1.dirKind,
"ThisDir": d1.dir,
Expand Down

0 comments on commit 3d94ad4

Please sign in to comment.