Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external alertmanager target #1149

Merged
merged 4 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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