feat(ruler): support alert relabeling (#6220)

pull/6255/head
Aditya C S 4 years ago committed by GitHub
parent 0b947d956f
commit 410c1a0d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      docs/sources/configuration/_index.md
  2. 1
      pkg/ruler/base/notifier.go
  3. 49
      pkg/ruler/base/notifier_test.go
  4. 3
      pkg/ruler/base/ruler.go

@ -677,6 +677,10 @@ alertmanager_client:
# CLI flag: -ruler.alertmanager-use-v2
[enable_alertmanager_v2: <boolean> | default = false]
# List of alert relabel configs
alert_relabel_configs:
[- <relabel_config> ...]
# Capacity of the queue for notifications to be sent to the Alertmanager.
# CLI flag: -ruler.notification-queue-capacity
[notification_queue_capacity: <int> | default = 10000]

@ -134,6 +134,7 @@ func buildNotifierConfig(rulerConfig *Config) (*config.Config, error) {
ExternalLabels: rulerConfig.ExternalLabels,
},
AlertingConfig: config.AlertingConfig{
AlertRelabelConfigs: rulerConfig.AlertRelabelConfigs,
AlertmanagerConfigs: amConfigs,
},
}

@ -11,6 +11,7 @@ import (
"github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/discovery/dns"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/require"
"github.com/grafana/loki/pkg/util"
@ -325,6 +326,54 @@ func TestBuildNotifierConfig(t *testing.T) {
},
},
},
{
name: "with alert relabel config",
cfg: &Config{
AlertmanagerURL: "http://alertmanager.default.svc.cluster.local/alertmanager",
ExternalLabels: []labels.Label{
{Name: "region", Value: "us-east-1"},
},
AlertRelabelConfigs: []*relabel.Config{
{
SourceLabels: model.LabelNames{"severity"},
Regex: relabel.MustNewRegexp("high"),
TargetLabel: "priority",
Replacement: "p1",
},
},
},
ncfg: &config.Config{
AlertingConfig: config.AlertingConfig{
AlertmanagerConfigs: []*config.AlertmanagerConfig{
{
APIVersion: "v1",
Scheme: "http",
PathPrefix: "/alertmanager",
ServiceDiscoveryConfigs: discovery.Configs{
discovery.StaticConfig{
{
Targets: []model.LabelSet{{"__address__": "alertmanager.default.svc.cluster.local"}},
},
},
},
},
},
AlertRelabelConfigs: []*relabel.Config{
{
SourceLabels: model.LabelNames{"severity"},
Regex: relabel.MustNewRegexp("high"),
TargetLabel: "priority",
Replacement: "p1",
},
},
},
GlobalConfig: config.GlobalConfig{
ExternalLabels: []labels.Label{
{Name: "region", Value: "us-east-1"},
},
},
},
},
}
for _, tt := range tests {

@ -24,6 +24,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel"
"github.com/prometheus/prometheus/model/rulefmt"
"github.com/prometheus/prometheus/notifier"
promRules "github.com/prometheus/prometheus/rules"
@ -94,6 +95,8 @@ type Config struct {
AlertmanagerRefreshInterval time.Duration `yaml:"alertmanager_refresh_interval"`
// Enables the ruler notifier to use the Alertmananger V2 API.
AlertmanangerEnableV2API bool `yaml:"enable_alertmanager_v2"`
// Configuration for alert relabeling.
AlertRelabelConfigs []*relabel.Config `yaml:"alert_relabel_configs,omitempty"`
// Capacity of the queue for notifications to be sent to the Alertmanager.
NotificationQueueCapacity int `yaml:"notification_queue_capacity"`
// HTTP timeout duration when sending notifications to the Alertmanager.

Loading…
Cancel
Save