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

Refine the error message of monitor port conflict #966

Merged
merged 4 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
AstroProfundis marked this conversation as resolved.
Show resolved Hide resolved
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