diff --git a/components/dm/command/prune.go b/components/dm/command/prune.go index c6bb13b97d..6b7c50cbc7 100644 --- a/components/dm/command/prune.go +++ b/components/dm/command/prune.go @@ -76,7 +76,7 @@ func clearOutDatedEtcdInfo(clusterName string, metadata *spec.Metadata, opt oper if err != nil { return err } - dmMasterClient := api.NewDMMasterClient(topo.GetMasterList(), 10*time.Second, tlsCfg) + dmMasterClient := api.NewDMMasterClient(topo.GetMasterListWithManageHost(), 10*time.Second, tlsCfg) registeredMasters, registeredWorkers, err := dmMasterClient.GetRegisteredMembers() if err != nil { return err diff --git a/components/dm/spec/topology_dm.go b/components/dm/spec/topology_dm.go index 4e5de5327c..a188b05a72 100644 --- a/components/dm/spec/topology_dm.go +++ b/components/dm/spec/topology_dm.go @@ -675,7 +675,7 @@ func (s *Specification) BaseTopo() *spec.BaseTopo { return &spec.BaseTopo{ GlobalOptions: &s.GlobalOptions, MonitoredOptions: s.GetMonitoredOptions(), - MasterList: s.GetMasterList(), + MasterList: s.GetMasterListWithManageHost(), Monitors: s.Monitors, Grafanas: s.Grafanas, Alertmanagers: s.Alertmanagers, @@ -701,12 +701,16 @@ func (s *Specification) MergeTopo(rhs spec.Topology) spec.Topology { return s.Merge(other) } -// GetMasterList returns a list of Master API hosts of the current cluster -func (s *Specification) GetMasterList() []string { +// GetMasterListWithManageHost returns a list of Master API hosts of the current cluster +func (s *Specification) GetMasterListWithManageHost() []string { var masterList []string for _, master := range s.Masters { - masterList = append(masterList, utils.JoinHostPort(master.Host, master.Port)) + host := master.Host + if master.ManageHost != "" { + host = master.ManageHost + } + masterList = append(masterList, utils.JoinHostPort(host, master.Port)) } return masterList diff --git a/pkg/cluster/manager/check.go b/pkg/cluster/manager/check.go index 75b5776fd6..9790adc302 100644 --- a/pkg/cluster/manager/check.go +++ b/pkg/cluster/manager/check.go @@ -695,7 +695,7 @@ func (m *Manager) checkRegionsInfo(clusterName string, topo *spec.Specification, } pdClient := api.NewPDClient( context.WithValue(context.TODO(), logprinter.ContextKeyLogger, m.logger), - topo.GetPDList(), + topo.GetPDListWithManageHost(), time.Second*time.Duration(gOpt.APITimeout), tlsConfig, ) diff --git a/pkg/cluster/manager/display.go b/pkg/cluster/manager/display.go index 6b9981a8bf..1441b6039e 100644 --- a/pkg/cluster/manager/display.go +++ b/pkg/cluster/manager/display.go @@ -233,7 +233,7 @@ func (m *Manager) Display(dopt DisplayOption, opt operator.Options) error { continue } if strings.HasPrefix(v.Status, "Up") || strings.HasPrefix(v.Status, "Healthy") { - instAddr := utils.JoinHostPort(v.Host, v.Port) + instAddr := utils.JoinHostPort(v.ManageHost, v.Port) masterActive = append(masterActive, instAddr) } } diff --git a/pkg/cluster/operation/destroy.go b/pkg/cluster/operation/destroy.go index 0d44613bf3..aeae040e3a 100644 --- a/pkg/cluster/operation/destroy.go +++ b/pkg/cluster/operation/destroy.go @@ -497,7 +497,7 @@ func DestroyClusterTombstone( pdEndpoints = strings.Split(forcePDEndpoints, ",") logger.Warnf("%s is set, using %s as PD endpoints", EnvNamePDEndpointOverwrite, pdEndpoints) } else { - pdEndpoints = cluster.GetPDList() + pdEndpoints = cluster.GetPDListWithManageHost() } var pdClient = api.NewPDClient(ctx, pdEndpoints, 10*time.Second, tlsCfg) diff --git a/pkg/cluster/operation/upgrade.go b/pkg/cluster/operation/upgrade.go index bf72673c1b..7976635d38 100644 --- a/pkg/cluster/operation/upgrade.go +++ b/pkg/cluster/operation/upgrade.go @@ -79,7 +79,7 @@ func Upgrade( pdEndpoints = strings.Split(forcePDEndpoints, ",") logger.Warnf("%s is set, using %s as PD endpoints", EnvNamePDEndpointOverwrite, pdEndpoints) } else { - pdEndpoints = topo.(*spec.Specification).GetPDList() + pdEndpoints = topo.(*spec.Specification).GetPDListWithManageHost() } pdClient := api.NewPDClient(ctx, pdEndpoints, 10*time.Second, tlsCfg) origLeaderScheduleLimit, origRegionScheduleLimit, err = increaseScheduleLimit(ctx, pdClient) diff --git a/pkg/cluster/spec/alertmanager.go b/pkg/cluster/spec/alertmanager.go index 527bb21927..eb46b4f9a2 100644 --- a/pkg/cluster/spec/alertmanager.go +++ b/pkg/cluster/spec/alertmanager.go @@ -67,6 +67,14 @@ func (s *AlertmanagerSpec) GetMainPort() int { return s.WebPort } +// GetManageHost returns the manage host of the instance +func (s *AlertmanagerSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *AlertmanagerSpec) IsImported() bool { return s.Imported @@ -117,10 +125,10 @@ func (c *AlertManagerComponent) Instances() []Instance { s.DataDir, }, StatusFn: func(_ context.Context, timeout time.Duration, _ *tls.Config, _ ...string) string { - return statusByHost(s.Host, s.WebPort, "/-/ready", timeout, nil) + return statusByHost(s.GetManageHost(), s.WebPort, "/-/ready", timeout, nil) }, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.WebPort, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.WebPort, timeout, tlsCfg) }, }, topo: c.Topology, diff --git a/pkg/cluster/spec/cdc.go b/pkg/cluster/spec/cdc.go index 3c75fbdbb0..36560bce3e 100644 --- a/pkg/cluster/spec/cdc.go +++ b/pkg/cluster/spec/cdc.go @@ -73,6 +73,14 @@ func (s *CDCSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *CDCSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *CDCSpec) IsImported() bool { return s.Imported @@ -116,10 +124,10 @@ func (c *CDCComponent) Instances() []Instance { s.DeployDir, }, StatusFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config, _ ...string) string { - return statusByHost(s.Host, s.Port, "/status", timeout, tlsCfg) + return statusByHost(s.GetManageHost(), s.Port, "/status", timeout, tlsCfg) }, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.Port, timeout, tlsCfg) }, }, c.Topology} if s.DataDir != "" { diff --git a/pkg/cluster/spec/dashboard.go b/pkg/cluster/spec/dashboard.go index e415227164..e1cbbd8e40 100644 --- a/pkg/cluster/spec/dashboard.go +++ b/pkg/cluster/spec/dashboard.go @@ -51,7 +51,7 @@ func (s *DashboardSpec) Status(ctx context.Context, timeout time.Duration, tlsCf timeout = statusQueryTimeout } - state := statusByHost(s.Host, s.Port, "/status", timeout, tlsCfg) + state := statusByHost(s.GetManageHost(), s.Port, "/status", timeout, tlsCfg) return state } @@ -75,6 +75,14 @@ func (s *DashboardSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *DashboardSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *DashboardSpec) IsImported() bool { // TiDB-Ansible do not support dashboard @@ -121,7 +129,7 @@ func (c *DashboardComponent) Instances() []Instance { }, StatusFn: s.Status, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.Port, timeout, tlsCfg) }, }, c.Topology}) } diff --git a/pkg/cluster/spec/drainer.go b/pkg/cluster/spec/drainer.go index 347e2fd7c0..e574ff4343 100644 --- a/pkg/cluster/spec/drainer.go +++ b/pkg/cluster/spec/drainer.go @@ -56,7 +56,7 @@ func (s *DrainerSpec) Status(ctx context.Context, timeout time.Duration, tlsCfg timeout = statusQueryTimeout } - state := statusByHost(s.Host, s.Port, "/status", timeout, tlsCfg) + state := statusByHost(s.GetManageHost(), s.Port, "/status", timeout, tlsCfg) if s.Offline { binlogClient, err := api.NewBinlogClient(pdList, timeout, tlsCfg) @@ -94,6 +94,14 @@ func (s *DrainerSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *DrainerSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *DrainerSpec) IsImported() bool { return s.Imported @@ -139,7 +147,7 @@ func (c *DrainerComponent) Instances() []Instance { }, StatusFn: s.Status, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.Port, timeout, tlsCfg) }, }, c.Topology}) } diff --git a/pkg/cluster/spec/grafana.go b/pkg/cluster/spec/grafana.go index 7284bf1d54..e3fe480396 100644 --- a/pkg/cluster/spec/grafana.go +++ b/pkg/cluster/spec/grafana.go @@ -76,6 +76,14 @@ func (s *GrafanaSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *GrafanaSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *GrafanaSpec) IsImported() bool { return s.Imported @@ -122,10 +130,10 @@ func (c *GrafanaComponent) Instances() []Instance { s.DeployDir, }, StatusFn: func(_ context.Context, timeout time.Duration, _ *tls.Config, _ ...string) string { - return statusByHost(s.Host, s.Port, "/login", timeout, nil) + return statusByHost(s.GetManageHost(), s.Port, "/login", timeout, nil) }, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.Port, timeout, tlsCfg) }, }, topo: c.Topology, diff --git a/pkg/cluster/spec/monitoring.go b/pkg/cluster/spec/monitoring.go index 3698d1d998..629f6973fd 100644 --- a/pkg/cluster/spec/monitoring.go +++ b/pkg/cluster/spec/monitoring.go @@ -93,6 +93,14 @@ func (s *PrometheusSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *PrometheusSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *PrometheusSpec) IsImported() bool { return s.Imported @@ -139,10 +147,10 @@ func (c *MonitorComponent) Instances() []Instance { s.DataDir, }, StatusFn: func(_ context.Context, timeout time.Duration, _ *tls.Config, _ ...string) string { - return statusByHost(s.Host, s.Port, "/-/ready", timeout, nil) + return statusByHost(s.GetManageHost(), s.Port, "/-/ready", timeout, nil) }, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.Port, timeout, tlsCfg) }, }, c.Topology} if s.NgPort > 0 { diff --git a/pkg/cluster/spec/pd.go b/pkg/cluster/spec/pd.go index 3c2972298b..6f4d085901 100644 --- a/pkg/cluster/spec/pd.go +++ b/pkg/cluster/spec/pd.go @@ -176,7 +176,7 @@ func (c *PDComponent) Instances() []Instance { }, StatusFn: s.Status, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.ClientPort, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.ClientPort, timeout, tlsCfg) }, }, topo: c.Topology, diff --git a/pkg/cluster/spec/pump.go b/pkg/cluster/spec/pump.go index 1844403fc7..c2e9fc54db 100644 --- a/pkg/cluster/spec/pump.go +++ b/pkg/cluster/spec/pump.go @@ -55,7 +55,7 @@ func (s *PumpSpec) Status(ctx context.Context, timeout time.Duration, tlsCfg *tl timeout = statusQueryTimeout } - state := statusByHost(s.Host, s.Port, "/status", timeout, tlsCfg) + state := statusByHost(s.GetManageHost(), s.Port, "/status", timeout, tlsCfg) if s.Offline { binlogClient, err := api.NewBinlogClient(pdList, timeout, tlsCfg) @@ -93,6 +93,14 @@ func (s *PumpSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *PumpSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *PumpSpec) IsImported() bool { return s.Imported @@ -138,7 +146,7 @@ func (c *PumpComponent) Instances() []Instance { }, StatusFn: s.Status, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.Port, timeout, tlsCfg) }, }, c.Topology}) } diff --git a/pkg/cluster/spec/spec.go b/pkg/cluster/spec/spec.go index 9a62d5897f..058c694101 100644 --- a/pkg/cluster/spec/spec.go +++ b/pkg/cluster/spec/spec.go @@ -254,7 +254,7 @@ func (s *Specification) BaseTopo() *BaseTopo { return &BaseTopo{ GlobalOptions: &s.GlobalOptions, MonitoredOptions: s.GetMonitoredOptions(), - MasterList: s.GetPDList(), + MasterList: s.GetPDListWithManageHost(), Monitors: s.Monitors, Grafanas: s.Grafanas, Alertmanagers: s.Alertmanagers, @@ -475,14 +475,14 @@ func (s *Specification) GetDashboardAddress(ctx context.Context, tlsCfg *tls.Con // GetEtcdClient loads EtcdClient of current cluster func (s *Specification) GetEtcdClient(tlsCfg *tls.Config) (*clientv3.Client, error) { return clientv3.New(clientv3.Config{ - Endpoints: s.GetPDList(), + Endpoints: s.GetPDListWithManageHost(), TLS: tlsCfg, }) } // GetEtcdProxyClient loads EtcdClient of current cluster with TCP proxy func (s *Specification) GetEtcdProxyClient(tlsCfg *tls.Config, tcpProxy *proxy.TCPProxy) (*clientv3.Client, chan struct{}, error) { - closeC := tcpProxy.Run(s.GetPDList()) + closeC := tcpProxy.Run(s.GetPDListWithManageHost()) cli, err := clientv3.New(clientv3.Config{ Endpoints: tcpProxy.GetEndpoints(), TLS: tlsCfg, diff --git a/pkg/cluster/spec/tidb.go b/pkg/cluster/spec/tidb.go index 45f00b5c9c..670df29986 100644 --- a/pkg/cluster/spec/tidb.go +++ b/pkg/cluster/spec/tidb.go @@ -70,6 +70,14 @@ func (s *TiDBSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *TiDBSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *TiDBSpec) IsImported() bool { return s.Imported @@ -115,10 +123,10 @@ func (c *TiDBComponent) Instances() []Instance { s.DeployDir, }, StatusFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config, _ ...string) string { - return statusByHost(s.Host, s.StatusPort, "/status", timeout, tlsCfg) + return statusByHost(s.GetManageHost(), s.StatusPort, "/status", timeout, tlsCfg) }, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.StatusPort, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.StatusPort, timeout, tlsCfg) }, }, c.Topology}) } diff --git a/pkg/cluster/spec/tiflash.go b/pkg/cluster/spec/tiflash.go index 654929bf35..fa4ea6fe22 100644 --- a/pkg/cluster/spec/tiflash.go +++ b/pkg/cluster/spec/tiflash.go @@ -143,6 +143,14 @@ func (s *TiFlashSpec) GetMainPort() int { return s.TCPPort } +// GetManageHost returns the manage host of the instance +func (s *TiFlashSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *TiFlashSpec) IsImported() bool { return s.Imported @@ -291,7 +299,7 @@ func (c *TiFlashComponent) Instances() []Instance { }, StatusFn: s.Status, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.StatusPort, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.StatusPort, timeout, tlsCfg) }, }, c.Topology}) } @@ -876,7 +884,7 @@ func (i *TiFlashInstance) Ready(ctx context.Context, e ctxt.Executor, timeout ui if i.topo.BaseTopo().GlobalOptions.TLSEnabled { scheme = "https" } - addr := fmt.Sprintf("%s://%s/tiflash/store-status", scheme, utils.JoinHostPort(i.Host, i.GetStatusPort())) + addr := fmt.Sprintf("%s://%s/tiflash/store-status", scheme, utils.JoinHostPort(i.GetManageHost(), i.GetStatusPort())) req, err := http.NewRequest("GET", addr, nil) if err != nil { return err diff --git a/pkg/cluster/spec/tikv.go b/pkg/cluster/spec/tikv.go index 6047bc4b9f..38ff14db7a 100644 --- a/pkg/cluster/spec/tikv.go +++ b/pkg/cluster/spec/tikv.go @@ -115,6 +115,14 @@ func (s *TiKVSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *TiKVSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *TiKVSpec) IsImported() bool { return s.Imported @@ -192,7 +200,7 @@ func (c *TiKVComponent) Instances() []Instance { }, StatusFn: s.Status, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.StatusPort, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.StatusPort, timeout, tlsCfg) }, }, c.Topology, 0}) } @@ -367,7 +375,7 @@ func (i *TiKVInstance) PreRestart(ctx context.Context, topo Topology, apiTimeout return nil } - pdClient := api.NewPDClient(ctx, tidbTopo.GetPDList(), 5*time.Second, tlsCfg) + pdClient := api.NewPDClient(ctx, tidbTopo.GetPDListWithManageHost(), 5*time.Second, tlsCfg) // Make sure there's leader of PD. // Although we evict pd leader when restart pd, @@ -405,7 +413,7 @@ func (i *TiKVInstance) PostRestart(ctx context.Context, topo Topology, tlsCfg *t return nil } - pdClient := api.NewPDClient(ctx, tidbTopo.GetPDList(), 5*time.Second, tlsCfg) + pdClient := api.NewPDClient(ctx, tidbTopo.GetPDListWithManageHost(), 5*time.Second, tlsCfg) // remove store leader evict scheduler after restart if err := pdClient.RemoveStoreEvict(addr(i.InstanceSpec.(*TiKVSpec))); err != nil { @@ -443,7 +451,7 @@ func genLeaderCounter(topo *Specification, tlsCfg *tls.Config) func(string) (int for _, kv := range topo.TiKVServers { kvid := utils.JoinHostPort(kv.Host, kv.Port) if id == kvid { - statusAddress = utils.JoinHostPort(kv.Host, kv.StatusPort) + statusAddress = utils.JoinHostPort(kv.GetManageHost(), kv.StatusPort) break } foundIds = append(foundIds, kvid) diff --git a/pkg/cluster/spec/tikv_cdc.go b/pkg/cluster/spec/tikv_cdc.go index c2eca361bc..b843deb323 100644 --- a/pkg/cluster/spec/tikv_cdc.go +++ b/pkg/cluster/spec/tikv_cdc.go @@ -72,6 +72,14 @@ func (s *TiKVCDCSpec) GetMainPort() int { return s.Port } +// GetManageHost returns the manage host of the instance +func (s *TiKVCDCSpec) GetManageHost() string { + if s.ManageHost != "" { + return s.ManageHost + } + return s.Host +} + // IsImported returns if the node is imported from TiDB-Ansible func (s *TiKVCDCSpec) IsImported() bool { // TiDB-Ansible do not support TiKV-CDC @@ -116,10 +124,10 @@ func (c *TiKVCDCComponent) Instances() []Instance { s.DeployDir, }, StatusFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config, _ ...string) string { - return statusByHost(s.Host, s.Port, "/status", timeout, tlsCfg) + return statusByHost(s.GetManageHost(), s.Port, "/status", timeout, tlsCfg) }, UptimeFn: func(_ context.Context, timeout time.Duration, tlsCfg *tls.Config) time.Duration { - return UptimeByHost(s.Host, s.Port, timeout, tlsCfg) + return UptimeByHost(s.GetManageHost(), s.Port, timeout, tlsCfg) }, }, c.Topology} if s.DataDir != "" {