From 4607799268240899a34b7e296617d8f131d863b5 Mon Sep 17 00:00:00 2001 From: SIGSEGV Date: Wed, 24 Feb 2021 12:00:48 +0800 Subject: [PATCH] Support external alertmanager target (#1149) * Support external alertmanager target Close https://github.com/pingcap/tiup/issues/1025 * Fix test Co-authored-by: Allen Zhong --- pkg/cluster/ansible/test-data/meta.yaml | 1 + pkg/cluster/spec/prometheus.go | 39 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pkg/cluster/ansible/test-data/meta.yaml b/pkg/cluster/ansible/test-data/meta.yaml index 2601577bd7..2239b5b4d3 100644 --- a/pkg/cluster/ansible/test-data/meta.yaml +++ b/pkg/cluster/ansible/test-data/meta.yaml @@ -169,6 +169,7 @@ topology: deploy_dir: /home/tiopsimport/ansible-deploy/prometheus-9090 data_dir: data/prometheus-9090 storage_retention: 30d + external_alertmanagers: [] arch: amd64 os: linux grafana_servers: diff --git a/pkg/cluster/spec/prometheus.go b/pkg/cluster/spec/prometheus.go index bc5810f644..d7629c3ece 100644 --- a/pkg/cluster/spec/prometheus.go +++ b/pkg/cluster/spec/prometheus.go @@ -32,20 +32,21 @@ import ( // PrometheusSpec represents the Prometheus Server topology specification in topology.yaml type PrometheusSpec struct { - Host string `yaml:"host"` - SSHPort int `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"` - Imported bool `yaml:"imported,omitempty"` - Port int `yaml:"port" default:"9090"` - DeployDir string `yaml:"deploy_dir,omitempty"` - DataDir string `yaml:"data_dir,omitempty"` - LogDir string `yaml:"log_dir,omitempty"` - NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` - RemoteConfig Remote `yaml:"remote_config,omitempty" validate:"remote_config:ignore"` - Retention string `yaml:"storage_retention,omitempty" validate:"storage_retention:editable"` - ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"` - Arch string `yaml:"arch,omitempty"` - OS string `yaml:"os,omitempty"` - RuleDir string `yaml:"rule_dir,omitempty" validate:"rule_dir:editable"` + Host string `yaml:"host"` + SSHPort int `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"` + Imported bool `yaml:"imported,omitempty"` + Port int `yaml:"port" default:"9090"` + DeployDir string `yaml:"deploy_dir,omitempty"` + DataDir string `yaml:"data_dir,omitempty"` + LogDir string `yaml:"log_dir,omitempty"` + NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` + RemoteConfig Remote `yaml:"remote_config,omitempty" validate:"remote_config:ignore"` + ExternalAlertmanagers []ExternalAlertmanager `yaml:"external_alertmanagers" validate:"external_alertmanagers:ignore"` + Retention string `yaml:"storage_retention,omitempty" validate:"storage_retention:editable"` + ResourceControl meta.ResourceControl `yaml:"resource_control,omitempty" validate:"resource_control:editable"` + Arch string `yaml:"arch,omitempty"` + OS string `yaml:"os,omitempty"` + RuleDir string `yaml:"rule_dir,omitempty" validate:"rule_dir:editable"` } // Remote prometheus remote config @@ -54,6 +55,12 @@ type Remote struct { RemoteRead []map[string]interface{} `yaml:"remote_read,omitempty" validate:"remote_read:ignore"` } +// ExternalAlertmanager configs prometheus to include alertmanagers not deployed in current cluster +type ExternalAlertmanager struct { + Host string `yaml:"host"` + WebPort int `yaml:"web_port" default:"9093"` +} + // Role returns the component role of the instance func (s PrometheusSpec) Role() string { return ComponentPrometheus @@ -267,6 +274,10 @@ func (i *MonitorInstance) InitConfig( } cfig.SetRemoteConfig(string(remoteCfg)) + for _, alertmanager := range spec.ExternalAlertmanagers { + cfig.AddAlertmanager(alertmanager.Host, uint64(alertmanager.WebPort)) + } + if spec.RuleDir != "" { filter := func(name string) bool { return strings.HasSuffix(name, ".rules.yml") } err := i.IteratorLocalConfigDir(ctx, spec.RuleDir, filter, func(name string) error {