diff --git a/pkg/cluster/spec/validate.go b/pkg/cluster/spec/validate.go index 109153b18e..e6ac3a346e 100644 --- a/pkg/cluster/spec/validate.go +++ b/pkg/cluster/spec/validate.go @@ -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{} @@ -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, }) } }) @@ -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, }) } @@ -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, }) } }) @@ -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)) diff --git a/pkg/cluster/spec/validate_test.go b/pkg/cluster/spec/validate_test.go index 53067e8138..e36f2921a6 100644 --- a/pkg/cluster/spec/validate_test.go +++ b/pkg/cluster/spec/validate_test.go @@ -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.`)