From 6d88e56b83503ef868e0e5a42991462882f76d46 Mon Sep 17 00:00:00 2001 From: 9547 Date: Thu, 1 Jul 2021 14:01:26 +0800 Subject: [PATCH] cluster/prometheus: tikv accelerate rules if version 3 (#1463) --- .github/workflows/integrate-cluster-cmd.yaml | 4 ++-- embed/templates/config/prometheus.yml.tpl | 2 ++ pkg/cluster/spec/prometheus.go | 2 +- pkg/cluster/template/config/prometheus.go | 14 +++++++++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/integrate-cluster-cmd.yaml b/.github/workflows/integrate-cluster-cmd.yaml index 557243cad5..00662e61fc 100644 --- a/.github/workflows/integrate-cluster-cmd.yaml +++ b/.github/workflows/integrate-cluster-cmd.yaml @@ -34,9 +34,9 @@ jobs: matrix: cases: - 'test_cmd' - # - "test_cmd_tls_native_ssh" + # - 'test_cmd_tls_native_ssh' - 'test_upgrade' - # - "test_upgrade_tls" + - 'test_upgrade_tls' env: working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }} steps: diff --git a/embed/templates/config/prometheus.yml.tpl b/embed/templates/config/prometheus.yml.tpl index 9102145779..6e780f4cc5 100644 --- a/embed/templates/config/prometheus.yml.tpl +++ b/embed/templates/config/prometheus.yml.tpl @@ -27,8 +27,10 @@ rule_files: {{- end}} {{- if .TiKVStatusAddrs}} - 'tikv.rules.yml' +{{- if .HasTiKVAccelerateRules}} - 'tikv.accelerate.rules.yml' {{- end}} +{{- end}} {{- if .TiFlashStatusAddrs}} - 'tiflash.rules.yml' {{- end}} diff --git a/pkg/cluster/spec/prometheus.go b/pkg/cluster/spec/prometheus.go index 258c6c3e9e..f573830db1 100644 --- a/pkg/cluster/spec/prometheus.go +++ b/pkg/cluster/spec/prometheus.go @@ -179,7 +179,7 @@ func (i *MonitorInstance) InitConfig( // transfer config fp = filepath.Join(paths.Cache, fmt.Sprintf("prometheus_%s_%d.yml", i.GetHost(), i.GetPort())) - cfig := config.NewPrometheusConfig(clusterName, enableTLS) + cfig := config.NewPrometheusConfig(clusterName, clusterVersion, enableTLS) if monitoredOptions != nil { cfig.AddBlackbox(i.GetHost(), uint64(monitoredOptions.BlackboxExporterPort)) } diff --git a/pkg/cluster/template/config/prometheus.go b/pkg/cluster/template/config/prometheus.go index a56b4da110..76e0611b00 100644 --- a/pkg/cluster/template/config/prometheus.go +++ b/pkg/cluster/template/config/prometheus.go @@ -21,6 +21,7 @@ import ( "text/template" "github.com/pingcap/tiup/embed" + "golang.org/x/mod/semver" ) // PrometheusConfig represent the data to generate Prometheus config @@ -46,6 +47,7 @@ type PrometheusConfig struct { BlackboxAddr string KafkaExporterAddr string GrafanaAddr string + HasTiKVAccelerateRules bool DMMasterAddrs []string DMWorkerAddrs []string @@ -55,11 +57,17 @@ type PrometheusConfig struct { } // NewPrometheusConfig returns a PrometheusConfig -func NewPrometheusConfig(cluster string, enableTLS bool) *PrometheusConfig { - return &PrometheusConfig{ - ClusterName: cluster, +func NewPrometheusConfig(clusterName, clusterVersion string, enableTLS bool) *PrometheusConfig { + cfg := &PrometheusConfig{ + ClusterName: clusterName, TLSEnabled: enableTLS, } + + // tikv.accelerate.rules.yml was first introduced in v4.0.0 + if semver.Compare(clusterVersion, "v4.0.0") >= 0 { + cfg.HasTiKVAccelerateRules = true + } + return cfg } // AddKafka add a kafka address