From 1358da17264263e93fdb6cea01f30379b4bb05fc Mon Sep 17 00:00:00 2001 From: mviswanathsai Date: Sat, 30 Mar 2024 19:32:28 +0530 Subject: [PATCH] add alertRelabelingConfigs to AlertmanagerEndpoints --- Documentation/api.md | 15 +++ bundle.yaml | 96 +++++++++++++++++++ .../monitoring.coreos.com_prometheuses.yaml | 96 +++++++++++++++++++ .../monitoring.coreos.com_prometheuses.yaml | 96 +++++++++++++++++++ .../prometheus-operator/prometheuses-crd.json | 69 +++++++++++++ pkg/apis/monitoring/v1/prometheus_types.go | 6 ++ .../monitoring/v1/zz_generated.deepcopy.go | 7 ++ .../monitoring/v1/alertmanagerendpoints.go | 42 +++++--- pkg/prometheus/operator.go | 7 +- pkg/prometheus/promcfg.go | 6 +- pkg/prometheus/promcfg_test.go | 64 ++++++++++++- pkg/prometheus/store.go | 16 ++-- ...tmangerAlertRelabel_Invalid_Version.golden | 29 ++++++ ...ertmangerAlertRelabel_Valid_Version.golden | 32 +++++++ 14 files changed, 556 insertions(+), 25 deletions(-) create mode 100644 pkg/prometheus/testdata/AlertmangerAlertRelabel_Invalid_Version.golden create mode 100644 pkg/prometheus/testdata/AlertmangerAlertRelabel_Valid_Version.golden diff --git a/Documentation/api.md b/Documentation/api.md index 1783b5136ea..1f494d94328 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -4665,6 +4665,21 @@ bool

Relabel configuration applied to the discovered Alertmanagers.

+ + +alertRelabelings
+ + +[]RelabelConfig + + + + +(Optional) +

Relabeling configs applied before sending alerts to a specific Alertmanager.. +It requires Prometheus >= v2.51.0.

+ +

AlertmanagerGlobalConfig diff --git a/bundle.yaml b/bundle.yaml index a53c643f415..2592c872b94 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -26104,6 +26104,102 @@ spec: AlertmanagerEndpoints defines a selection of a single Endpoints object containing Alertmanager IPs to fire alerts against. properties: + alertRelabelings: + description: |- + Relabeling configs applied before sending alerts to a specific Alertmanager.. + It requires Prometheus >= v2.51.0. + items: + description: |- + RelabelConfig allows dynamic rewriting of the label set for targets, alerts, + scraped samples and remote write samples. + + + More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config + properties: + action: + default: replace + description: |- + Action to perform based on the regex matching. + + + `Uppercase` and `Lowercase` actions require Prometheus >= v2.36.0. + `DropEqual` and `KeepEqual` actions require Prometheus >= v2.41.0. + + + Default: "Replace" + enum: + - replace + - Replace + - keep + - Keep + - drop + - Drop + - hashmod + - HashMod + - labelmap + - LabelMap + - labeldrop + - LabelDrop + - labelkeep + - LabelKeep + - lowercase + - Lowercase + - uppercase + - Uppercase + - keepequal + - KeepEqual + - dropequal + - DropEqual + type: string + modulus: + description: |- + Modulus to take of the hash of the source label values. + + + Only applicable when the action is `HashMod`. + format: int64 + type: integer + regex: + description: Regular expression against which the + extracted value is matched. + type: string + replacement: + description: |- + Replacement value against which a Replace action is performed if the + regular expression matches. + + + Regex capture groups are available. + type: string + separator: + description: Separator is the string between concatenated + SourceLabels. + type: string + sourceLabels: + description: |- + The source labels select values from existing labels. Their content is + concatenated using the configured Separator and matched against the + configured regular expression. + items: + description: |- + LabelName is a valid Prometheus label name which may only contain ASCII + letters, numbers, as well as underscores. + pattern: ^[a-zA-Z_][a-zA-Z0-9_]*$ + type: string + type: array + targetLabel: + description: |- + Label to which the resulting string is written in a replacement. + + + It is mandatory for `Replace`, `HashMod`, `Lowercase`, `Uppercase`, + `KeepEqual` and `DropEqual` actions. + + + Regex capture groups are available. + type: string + type: object + type: array apiVersion: description: |- Version of the Alertmanager API that Prometheus uses to send alerts. diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml index 1698cadbc4e..d15930a8bac 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml @@ -1103,6 +1103,102 @@ spec: AlertmanagerEndpoints defines a selection of a single Endpoints object containing Alertmanager IPs to fire alerts against. properties: + alertRelabelings: + description: |- + Relabeling configs applied before sending alerts to a specific Alertmanager.. + It requires Prometheus >= v2.51.0. + items: + description: |- + RelabelConfig allows dynamic rewriting of the label set for targets, alerts, + scraped samples and remote write samples. + + + More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config + properties: + action: + default: replace + description: |- + Action to perform based on the regex matching. + + + `Uppercase` and `Lowercase` actions require Prometheus >= v2.36.0. + `DropEqual` and `KeepEqual` actions require Prometheus >= v2.41.0. + + + Default: "Replace" + enum: + - replace + - Replace + - keep + - Keep + - drop + - Drop + - hashmod + - HashMod + - labelmap + - LabelMap + - labeldrop + - LabelDrop + - labelkeep + - LabelKeep + - lowercase + - Lowercase + - uppercase + - Uppercase + - keepequal + - KeepEqual + - dropequal + - DropEqual + type: string + modulus: + description: |- + Modulus to take of the hash of the source label values. + + + Only applicable when the action is `HashMod`. + format: int64 + type: integer + regex: + description: Regular expression against which the + extracted value is matched. + type: string + replacement: + description: |- + Replacement value against which a Replace action is performed if the + regular expression matches. + + + Regex capture groups are available. + type: string + separator: + description: Separator is the string between concatenated + SourceLabels. + type: string + sourceLabels: + description: |- + The source labels select values from existing labels. Their content is + concatenated using the configured Separator and matched against the + configured regular expression. + items: + description: |- + LabelName is a valid Prometheus label name which may only contain ASCII + letters, numbers, as well as underscores. + pattern: ^[a-zA-Z_][a-zA-Z0-9_]*$ + type: string + type: array + targetLabel: + description: |- + Label to which the resulting string is written in a replacement. + + + It is mandatory for `Replace`, `HashMod`, `Lowercase`, `Uppercase`, + `KeepEqual` and `DropEqual` actions. + + + Regex capture groups are available. + type: string + type: object + type: array apiVersion: description: |- Version of the Alertmanager API that Prometheus uses to send alerts. diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index a1ae28e2e62..7da190dc2a5 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -1104,6 +1104,102 @@ spec: AlertmanagerEndpoints defines a selection of a single Endpoints object containing Alertmanager IPs to fire alerts against. properties: + alertRelabelings: + description: |- + Relabeling configs applied before sending alerts to a specific Alertmanager.. + It requires Prometheus >= v2.51.0. + items: + description: |- + RelabelConfig allows dynamic rewriting of the label set for targets, alerts, + scraped samples and remote write samples. + + + More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config + properties: + action: + default: replace + description: |- + Action to perform based on the regex matching. + + + `Uppercase` and `Lowercase` actions require Prometheus >= v2.36.0. + `DropEqual` and `KeepEqual` actions require Prometheus >= v2.41.0. + + + Default: "Replace" + enum: + - replace + - Replace + - keep + - Keep + - drop + - Drop + - hashmod + - HashMod + - labelmap + - LabelMap + - labeldrop + - LabelDrop + - labelkeep + - LabelKeep + - lowercase + - Lowercase + - uppercase + - Uppercase + - keepequal + - KeepEqual + - dropequal + - DropEqual + type: string + modulus: + description: |- + Modulus to take of the hash of the source label values. + + + Only applicable when the action is `HashMod`. + format: int64 + type: integer + regex: + description: Regular expression against which the + extracted value is matched. + type: string + replacement: + description: |- + Replacement value against which a Replace action is performed if the + regular expression matches. + + + Regex capture groups are available. + type: string + separator: + description: Separator is the string between concatenated + SourceLabels. + type: string + sourceLabels: + description: |- + The source labels select values from existing labels. Their content is + concatenated using the configured Separator and matched against the + configured regular expression. + items: + description: |- + LabelName is a valid Prometheus label name which may only contain ASCII + letters, numbers, as well as underscores. + pattern: ^[a-zA-Z_][a-zA-Z0-9_]*$ + type: string + type: array + targetLabel: + description: |- + Label to which the resulting string is written in a replacement. + + + It is mandatory for `Replace`, `HashMod`, `Lowercase`, `Uppercase`, + `KeepEqual` and `DropEqual` actions. + + + Regex capture groups are available. + type: string + type: object + type: array apiVersion: description: |- Version of the Alertmanager API that Prometheus uses to send alerts. diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index be0b9a9fd51..7e2d41b3b31 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -903,6 +903,75 @@ "items": { "description": "AlertmanagerEndpoints defines a selection of a single Endpoints object\ncontaining Alertmanager IPs to fire alerts against.", "properties": { + "alertRelabelings": { + "description": "Relabeling configs applied before sending alerts to a specific Alertmanager..\nIt requires Prometheus >= v2.51.0.", + "items": { + "description": "RelabelConfig allows dynamic rewriting of the label set for targets, alerts,\nscraped samples and remote write samples.\n\n\nMore info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config", + "properties": { + "action": { + "default": "replace", + "description": "Action to perform based on the regex matching.\n\n\n`Uppercase` and `Lowercase` actions require Prometheus >= v2.36.0.\n`DropEqual` and `KeepEqual` actions require Prometheus >= v2.41.0.\n\n\nDefault: \"Replace\"", + "enum": [ + "replace", + "Replace", + "keep", + "Keep", + "drop", + "Drop", + "hashmod", + "HashMod", + "labelmap", + "LabelMap", + "labeldrop", + "LabelDrop", + "labelkeep", + "LabelKeep", + "lowercase", + "Lowercase", + "uppercase", + "Uppercase", + "keepequal", + "KeepEqual", + "dropequal", + "DropEqual" + ], + "type": "string" + }, + "modulus": { + "description": "Modulus to take of the hash of the source label values.\n\n\nOnly applicable when the action is `HashMod`.", + "format": "int64", + "type": "integer" + }, + "regex": { + "description": "Regular expression against which the extracted value is matched.", + "type": "string" + }, + "replacement": { + "description": "Replacement value against which a Replace action is performed if the\nregular expression matches.\n\n\nRegex capture groups are available.", + "type": "string" + }, + "separator": { + "description": "Separator is the string between concatenated SourceLabels.", + "type": "string" + }, + "sourceLabels": { + "description": "The source labels select values from existing labels. Their content is\nconcatenated using the configured Separator and matched against the\nconfigured regular expression.", + "items": { + "description": "LabelName is a valid Prometheus label name which may only contain ASCII\nletters, numbers, as well as underscores.", + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$", + "type": "string" + }, + "type": "array" + }, + "targetLabel": { + "description": "Label to which the resulting string is written in a replacement.\n\n\nIt is mandatory for `Replace`, `HashMod`, `Lowercase`, `Uppercase`,\n`KeepEqual` and `DropEqual` actions.\n\n\nRegex capture groups are available.", + "type": "string" + } + }, + "type": "object" + }, + "type": "array" + }, "apiVersion": { "description": "Version of the Alertmanager API that Prometheus uses to send alerts.\nIt can be \"v1\" or \"v2\".", "type": "string" diff --git a/pkg/apis/monitoring/v1/prometheus_types.go b/pkg/apis/monitoring/v1/prometheus_types.go index 6d3c445ebd4..732493a63fc 100644 --- a/pkg/apis/monitoring/v1/prometheus_types.go +++ b/pkg/apis/monitoring/v1/prometheus_types.go @@ -1676,6 +1676,12 @@ type AlertmanagerEndpoints struct { // // +optional RelabelConfigs []RelabelConfig `json:"relabelings,omitempty"` + + // Relabeling configs applied before sending alerts to a specific Alertmanager.. + // It requires Prometheus >= v2.51.0. + // + // +optional + AlertRelabelConfigs []RelabelConfig `json:"alertRelabelings,omitempty"` } // +k8s:openapi-gen=true diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index 1667523f765..73572eed6ec 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -179,6 +179,13 @@ func (in *AlertmanagerEndpoints) DeepCopyInto(out *AlertmanagerEndpoints) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.AlertRelabelConfigs != nil { + in, out := &in.AlertRelabelConfigs, &out.AlertRelabelConfigs + *out = make([]RelabelConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AlertmanagerEndpoints. diff --git a/pkg/client/applyconfiguration/monitoring/v1/alertmanagerendpoints.go b/pkg/client/applyconfiguration/monitoring/v1/alertmanagerendpoints.go index 2c9e987c2f8..8a351e4de89 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/alertmanagerendpoints.go +++ b/pkg/client/applyconfiguration/monitoring/v1/alertmanagerendpoints.go @@ -24,20 +24,21 @@ import ( // AlertmanagerEndpointsApplyConfiguration represents an declarative configuration of the AlertmanagerEndpoints type for use // with apply. type AlertmanagerEndpointsApplyConfiguration struct { - Namespace *string `json:"namespace,omitempty"` - Name *string `json:"name,omitempty"` - Port *intstr.IntOrString `json:"port,omitempty"` - Scheme *string `json:"scheme,omitempty"` - PathPrefix *string `json:"pathPrefix,omitempty"` - TLSConfig *TLSConfigApplyConfiguration `json:"tlsConfig,omitempty"` - BasicAuth *BasicAuthApplyConfiguration `json:"basicAuth,omitempty"` - BearerTokenFile *string `json:"bearerTokenFile,omitempty"` - Authorization *SafeAuthorizationApplyConfiguration `json:"authorization,omitempty"` - Sigv4 *Sigv4ApplyConfiguration `json:"sigv4,omitempty"` - APIVersion *string `json:"apiVersion,omitempty"` - Timeout *monitoringv1.Duration `json:"timeout,omitempty"` - EnableHttp2 *bool `json:"enableHttp2,omitempty"` - RelabelConfigs []RelabelConfigApplyConfiguration `json:"relabelings,omitempty"` + Namespace *string `json:"namespace,omitempty"` + Name *string `json:"name,omitempty"` + Port *intstr.IntOrString `json:"port,omitempty"` + Scheme *string `json:"scheme,omitempty"` + PathPrefix *string `json:"pathPrefix,omitempty"` + TLSConfig *TLSConfigApplyConfiguration `json:"tlsConfig,omitempty"` + BasicAuth *BasicAuthApplyConfiguration `json:"basicAuth,omitempty"` + BearerTokenFile *string `json:"bearerTokenFile,omitempty"` + Authorization *SafeAuthorizationApplyConfiguration `json:"authorization,omitempty"` + Sigv4 *Sigv4ApplyConfiguration `json:"sigv4,omitempty"` + APIVersion *string `json:"apiVersion,omitempty"` + Timeout *monitoringv1.Duration `json:"timeout,omitempty"` + EnableHttp2 *bool `json:"enableHttp2,omitempty"` + RelabelConfigs []RelabelConfigApplyConfiguration `json:"relabelings,omitempty"` + AlertRelabelConfigs []RelabelConfigApplyConfiguration `json:"alertRelabelings,omitempty"` } // AlertmanagerEndpointsApplyConfiguration constructs an declarative configuration of the AlertmanagerEndpoints type for use with @@ -162,3 +163,16 @@ func (b *AlertmanagerEndpointsApplyConfiguration) WithRelabelConfigs(values ...* } return b } + +// WithAlertRelabelConfigs adds the given value to the AlertRelabelConfigs field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the AlertRelabelConfigs field. +func (b *AlertmanagerEndpointsApplyConfiguration) WithAlertRelabelConfigs(values ...*RelabelConfigApplyConfiguration) *AlertmanagerEndpointsApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithAlertRelabelConfigs") + } + b.AlertRelabelConfigs = append(b.AlertRelabelConfigs, *values[i]) + } + return b +} diff --git a/pkg/prometheus/operator.go b/pkg/prometheus/operator.go index f4672f35318..6c254cabdc1 100644 --- a/pkg/prometheus/operator.go +++ b/pkg/prometheus/operator.go @@ -169,11 +169,14 @@ func ValidateAlertmanagerEndpoints(am monitoringv1.AlertmanagerEndpoints, p *mon return fmt.Errorf("%s can't be set at the same time, at most one of them must be defined", strings.Join(nonNilFields, " and ")) } - err := validateRelabelConfigs(p, am.RelabelConfigs) - if err != nil { + if err := validateRelabelConfigs(p, am.RelabelConfigs); err != nil { return fmt.Errorf("invalid relabelings: %w", err) } + if err := validateRelabelConfigs(p, am.AlertRelabelConfigs); err != nil { + return err + } + return nil } diff --git a/pkg/prometheus/promcfg.go b/pkg/prometheus/promcfg.go index 294c191b49c..08ea3ea31cd 100644 --- a/pkg/prometheus/promcfg.go +++ b/pkg/prometheus/promcfg.go @@ -1841,9 +1841,13 @@ func (cg *ConfigGenerator) generateAlertmanagerConfig(alerting *monitoringv1.Ale } cfg = append(cfg, yaml.MapItem{Key: "relabel_configs", Value: relabelings}) + + // Append alert_relabel_configs, if any, to the config + if len(am.AlertRelabelConfigs) > 0 { + cfg = cg.WithMinimumVersion("2.51.0").AppendMapItem(cfg, "alert_relabel_configs", generateRelabelConfig(am.AlertRelabelConfigs)) + } alertmanagerConfigs = append(alertmanagerConfigs, cfg) } - return alertmanagerConfigs } diff --git a/pkg/prometheus/promcfg_test.go b/pkg/prometheus/promcfg_test.go index 167cdff9136..60bee82f0e3 100644 --- a/pkg/prometheus/promcfg_test.go +++ b/pkg/prometheus/promcfg_test.go @@ -1196,7 +1196,6 @@ func TestAlertmanagerTimeoutConfig(t *testing.T) { require.NoError(t, err) golden.Assert(t, string(cfg), "AlertmanagerTimeoutConfig.golden") } - func TestAlertmanagerEnableHttp2(t *testing.T) { for _, tc := range []struct { version string @@ -1322,6 +1321,69 @@ func TestAlertmanagerRelabelConfigs(t *testing.T) { }) } +func TestAlertmanagerAlertRelabelConfigs(t *testing.T) { + for _, tc := range []struct { + name string + version string + golden string + }{ + { + name: "Invalid Prometheus Version", + version: "2.40.1", + golden: "AlertmangerAlertRelabel_Invalid_Version.golden", + }, + { + name: "Valid Prometheus Version", + version: "2.51.0", + golden: "AlertmangerAlertRelabel_Valid_Version.golden", + }, + } { + t.Run(fmt.Sprintf("AlertmanagerAlertRelabelConfigs: %s", tc.name), func(t *testing.T) { + p := defaultPrometheus() + p.Spec.Version = tc.version + p.Spec.Alerting = &monitoringv1.AlertingSpec{ + Alertmanagers: []monitoringv1.AlertmanagerEndpoints{ + { + Name: "alertmanager-main", + Namespace: "default", + Port: intstr.FromString("web"), + APIVersion: "v2", + AlertRelabelConfigs: []monitoringv1.RelabelConfig{ + { + TargetLabel: "namespace", + Replacement: ptr.To("ns1"), + }, + }, + }, + }, + } + + cg := mustNewConfigGenerator(t, p) + cfg, err := cg.GenerateServerConfiguration( + context.Background(), + p.Spec.EvaluationInterval, + p.Spec.QueryLogFile, + p.Spec.RuleSelector, + p.Spec.Exemplars, + p.Spec.TSDB, + p.Spec.Alerting, + p.Spec.RemoteRead, + nil, + nil, + nil, + nil, + &assets.StoreBuilder{}, + nil, + nil, + nil, + nil, + ) + require.NoError(t, err) + golden.Assert(t, string(cfg), tc.golden) + }) + } +} + func TestAdditionalScrapeConfigs(t *testing.T) { getCfg := func(shards *int32) string { p := defaultPrometheus() diff --git a/pkg/prometheus/store.go b/pkg/prometheus/store.go index ee0a232e356..2b446a93075 100644 --- a/pkg/prometheus/store.go +++ b/pkg/prometheus/store.go @@ -83,13 +83,15 @@ func AddRemoteReadsToStore(ctx context.Context, store *assets.StoreBuilder, name func AddAlertmanagerEndpointsToStore(ctx context.Context, store *assets.StoreBuilder, namespace string, ams []monv1.AlertmanagerEndpoints) error { for i, am := range ams { if err := store.AddBasicAuth(ctx, namespace, am.BasicAuth); err != nil { - return fmt.Errorf("alertmanager %d: %w", i, err) - } - if err := store.AddSafeAuthorizationCredentials(ctx, namespace, am.Authorization, fmt.Sprintf("alertmanager/auth/%d", i)); err != nil { - return fmt.Errorf("alertmanager %d: %w", i, err) - } - if err := store.AddSigV4(ctx, namespace, am.Sigv4, fmt.Sprintf("alertmanager/auth/%d", i)); err != nil { - return fmt.Errorf("alertmanager %d: %w", i, err) + if err := store.AddBasicAuth(ctx, namespace, am.BasicAuth); err != nil { + return fmt.Errorf("alertmanager %d: %w", i, err) + } + if err := store.AddSafeAuthorizationCredentials(ctx, namespace, am.Authorization, fmt.Sprintf("alertmanager/auth/%d", i)); err != nil { + return fmt.Errorf("alertmanager %d: %w", i, err) + } + if err := store.AddSigV4(ctx, namespace, am.Sigv4, fmt.Sprintf("alertmanager/auth/%d", i)); err != nil { + return fmt.Errorf("alertmanager %d: %w", i, err) + } } } diff --git a/pkg/prometheus/testdata/AlertmangerAlertRelabel_Invalid_Version.golden b/pkg/prometheus/testdata/AlertmangerAlertRelabel_Invalid_Version.golden new file mode 100644 index 00000000000..34cce4dca41 --- /dev/null +++ b/pkg/prometheus/testdata/AlertmangerAlertRelabel_Invalid_Version.golden @@ -0,0 +1,29 @@ +global: + evaluation_interval: 30s + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: [] +alerting: + alert_relabel_configs: + - action: labeldrop + regex: prometheus_replica + alertmanagers: + - path_prefix: / + scheme: http + kubernetes_sd_configs: + - role: endpoints + namespaces: + names: + - default + api_version: v2 + relabel_configs: + - action: keep + source_labels: + - __meta_kubernetes_service_name + regex: alertmanager-main + - action: keep + source_labels: + - __meta_kubernetes_endpoint_port_name + regex: web diff --git a/pkg/prometheus/testdata/AlertmangerAlertRelabel_Valid_Version.golden b/pkg/prometheus/testdata/AlertmangerAlertRelabel_Valid_Version.golden new file mode 100644 index 00000000000..82912912246 --- /dev/null +++ b/pkg/prometheus/testdata/AlertmangerAlertRelabel_Valid_Version.golden @@ -0,0 +1,32 @@ +global: + evaluation_interval: 30s + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: [] +alerting: + alert_relabel_configs: + - action: labeldrop + regex: prometheus_replica + alertmanagers: + - path_prefix: / + scheme: http + kubernetes_sd_configs: + - role: endpoints + namespaces: + names: + - default + api_version: v2 + relabel_configs: + - action: keep + source_labels: + - __meta_kubernetes_service_name + regex: alertmanager-main + - action: keep + source_labels: + - __meta_kubernetes_endpoint_port_name + regex: web + alert_relabel_configs: + - target_label: namespace + replacement: ns1