diff --git a/embed/examples/cluster/minimal.yaml b/embed/examples/cluster/minimal.yaml index b8c11ff335..447f7943d9 100644 --- a/embed/examples/cluster/minimal.yaml +++ b/embed/examples/cluster/minimal.yaml @@ -224,6 +224,8 @@ monitoring_servers: # ssh_port: 22 # # Prometheus Service communication port. # port: 9090 + # # ng-monitoring servive communication port + # ng_port: 12020 # # Prometheus deployment file, startup script, configuration file storage directory. # deploy_dir: "/tidb-deploy/prometheus-8249" # # Prometheus data storage directory. diff --git a/embed/examples/cluster/multi-dc.yaml b/embed/examples/cluster/multi-dc.yaml index 05013d42e6..37e8ded064 100644 --- a/embed/examples/cluster/multi-dc.yaml +++ b/embed/examples/cluster/multi-dc.yaml @@ -276,6 +276,8 @@ monitoring_servers: # ssh_port: 22 # # Prometheus Service communication port. # port: 9090 + # # ng-monitoring servive communication port + # ng_port: 12020 # # Prometheus deployment file, startup script, configuration file storage directory. # deploy_dir: "/tidb-deploy/prometheus-8249" # # Prometheus data storage directory. diff --git a/embed/examples/cluster/topology.example.yaml b/embed/examples/cluster/topology.example.yaml index b2cf3d301c..bebc7f7487 100644 --- a/embed/examples/cluster/topology.example.yaml +++ b/embed/examples/cluster/topology.example.yaml @@ -286,6 +286,8 @@ monitoring_servers: # ssh_port: 22 # # Prometheus Service communication port. # port: 9090 + # # ng-monitoring servive communication port + # ng_port: 12020 # # Prometheus deployment file, startup script, configuration file storage directory. # deploy_dir: "/tidb-deploy/prometheus-8249" # # Prometheus data storage directory. diff --git a/pkg/cluster/manager/upgrade.go b/pkg/cluster/manager/upgrade.go index a6e259c29d..f3f4de863d 100644 --- a/pkg/cluster/manager/upgrade.go +++ b/pkg/cluster/manager/upgrade.go @@ -53,6 +53,11 @@ func (m *Manager) Upgrade(name string, clusterVersion string, opt operator.Optio topo := metadata.GetTopology() base := metadata.GetBaseMeta() + // Adjust topo by new version + if clusterTopo, ok := topo.(*spec.Specification); ok { + clusterTopo.AdjustByVersion(clusterVersion) + } + var ( downloadCompTasks []task.Task // tasks which are used to download components copyCompTasks []task.Task // tasks which are used to copy components to remote host diff --git a/pkg/cluster/spec/monitoring.go b/pkg/cluster/spec/monitoring.go index dcde45027b..da01b25c44 100644 --- a/pkg/cluster/spec/monitoring.go +++ b/pkg/cluster/spec/monitoring.go @@ -41,7 +41,7 @@ type PrometheusSpec struct { Patched bool `yaml:"patched,omitempty"` IgnoreExporter bool `yaml:"ignore_exporter,omitempty"` Port int `yaml:"port" default:"9090"` - NgPort int `yaml:"ng_port,omitempty" validate:"ng_port:editable"` + NgPort int `yaml:"ng_port,omitempty" validate:"ng_port:editable"` // ng_port is usable since v5.3.0 and default as 12020 since v5.4.0, so the default value is set in spec.go/AdjustByVersion DeployDir string `yaml:"deploy_dir,omitempty"` DataDir string `yaml:"data_dir,omitempty"` LogDir string `yaml:"log_dir,omitempty"` diff --git a/pkg/cluster/spec/spec.go b/pkg/cluster/spec/spec.go index 985e8c3887..4337efe188 100644 --- a/pkg/cluster/spec/spec.go +++ b/pkg/cluster/spec/spec.go @@ -403,6 +403,13 @@ func (s *Specification) AdjustByVersion(clusterVersion string) { server.DataDir = "" } } + if semver.Compare(clusterVersion, "v5.4.0") >= 0 { + for _, m := range s.Monitors { + if m.NgPort == 0 { + m.NgPort = 12020 + } + } + } } // GetDashboardAddress returns the cluster's dashboard addr diff --git a/pkg/cluster/spec/validate.go b/pkg/cluster/spec/validate.go index e751903366..4c289d4674 100644 --- a/pkg/cluster/spec/validate.go +++ b/pkg/cluster/spec/validate.go @@ -568,9 +568,8 @@ func (s *Specification) portInvalidDetect() error { for i := 0; i < compSpec.NumField(); i++ { if strings.HasSuffix(compSpec.Type().Field(i).Name, "Port") { port := int(compSpec.Field(i).Int()) - portTags := strings.Split(compSpec.Type().Field(i).Tag.Get("yaml"), ",") - // when use not specify ng_port, its default value is 0 - if port == 0 && len(portTags) > 1 && portTags[1] == "omitempty" { + // for NgPort, 0 means default and -1 means disable + if compSpec.Type().Field(i).Name == "NgPort" && (port == -1 || port == 0) { continue } if port < 1 || port > 65535 {