Skip to content

Commit

Permalink
Refine the error message of monitor port conflict (#966)
Browse files Browse the repository at this point in the history
* Refine the error message

Signed-off-by: JaySon-Huang <tshent@qq.com>

* Address comments

Signed-off-by: JaySon-Huang <tshent@qq.com>

Co-authored-by: SIGSEGV <gnu.crazier@gmail.com>
  • Loading branch information
JaySon-Huang and lucklove authored Dec 8, 2020
1 parent 3bf3ba8 commit e534e62
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
47 changes: 27 additions & 20 deletions pkg/cluster/spec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ Please change to use another directory or another host.
// CheckClusterPortConflict checks cluster dir conflict
func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName string, topo Topology) error {
type Entry struct {
clusterName string
instance Instance
port int
clusterName string
componentName string
port int
instance Instance
}

currentEntries := []Entry{}
Expand All @@ -222,23 +223,26 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
blackboxExporterPort := mOpt.BlackboxExporterPort
for _, port := range inst.UsedPorts() {
existingEntries = append(existingEntries, Entry{
clusterName: name,
instance: inst,
port: port,
clusterName: name,
componentName: inst.ComponentName(),
port: port,
instance: inst,
})
}
if !uniqueHosts.Exist(inst.GetHost()) {
uniqueHosts.Insert(inst.GetHost())
existingEntries = append(existingEntries,
Entry{
clusterName: name,
instance: inst,
port: nodeExporterPort,
clusterName: name,
componentName: RoleMonitor,
port: nodeExporterPort,
instance: inst,
},
Entry{
clusterName: name,
instance: inst,
port: blackboxExporterPort,
clusterName: name,
componentName: RoleMonitor,
port: blackboxExporterPort,
instance: inst,
})
}
})
Expand All @@ -248,8 +252,9 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
topo.IterInstance(func(inst Instance) {
for _, port := range inst.UsedPorts() {
currentEntries = append(currentEntries, Entry{
instance: inst,
port: port,
componentName: inst.ComponentName(),
port: port,
instance: inst,
})
}

Expand All @@ -261,12 +266,14 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
uniqueHosts.Insert(inst.GetHost())
currentEntries = append(currentEntries,
Entry{
instance: inst,
port: mOpt.NodeExporterPort,
componentName: RoleMonitor,
port: mOpt.NodeExporterPort,
instance: inst,
},
Entry{
instance: inst,
port: mOpt.BlackboxExporterPort,
componentName: RoleMonitor,
port: mOpt.BlackboxExporterPort,
instance: inst,
})
}
})
Expand All @@ -280,11 +287,11 @@ func CheckClusterPortConflict(clusterList map[string]Metadata, clusterName strin
if p1.port == p2.port {
properties := map[string]string{
"ThisPort": strconv.Itoa(p1.port),
"ThisComponent": p1.instance.ComponentName(),
"ThisComponent": p1.componentName,
"ThisHost": p1.instance.GetHost(),
"ExistCluster": p2.clusterName,
"ExistPort": strconv.Itoa(p2.port),
"ExistComponent": p2.instance.ComponentName(),
"ExistComponent": p2.componentName,
"ExistHost": p2.instance.GetHost(),
}
zap.L().Info("Meet deploy port conflict", zap.Any("info", properties))
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/spec/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@ tidb_servers:
c.Assert(ok, IsTrue)
c.Assert(suggestion, Equals, `The port you specified in the topology file is:
Port: 9100
Component: tidb 172.16.5.138
Component: monitor 172.16.5.138
It conflicts to a port in the existing cluster:
Existing Cluster Name: topo1
Existing Port: 9100
Existing Component: pd 172.16.5.138
Existing Component: monitor 172.16.5.138
Please change to use another port or another host.`)

Expand Down

0 comments on commit e534e62

Please sign in to comment.