Skip to content

Commit

Permalink
Support external alertmanager target (#1149)
Browse files Browse the repository at this point in the history
* Support external alertmanager target

Close #1025

* Fix test

Co-authored-by: Allen Zhong <[email protected]>
  • Loading branch information
lucklove and AstroProfundis authored Feb 24, 2021
1 parent 3d00875 commit 4607799
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions pkg/cluster/ansible/test-data/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 25 additions & 14 deletions pkg/cluster/spec/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4607799

Please sign in to comment.