From c69599c84c67a92595f916612c25cf4bf29b7452 Mon Sep 17 00:00:00 2001 From: QuentinBisson Date: Tue, 3 Dec 2024 15:49:43 +0100 Subject: [PATCH 1/4] fix: support capitalized relabel actions to match with prometheus-operator behavior --- CHANGELOG.md | 3 + .../operator/configgen/config_gen.go | 2 + .../config_gen_servicemonitor_test.go | 76 +++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a912ad5e57..73fd3769e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Main (unreleased) - For sharding targets during clustering, `loki.source.podlogs` now only takes into account some labels. (@ptodev) ### Bugfixes + - Fixed an issue in the `pyroscope.write` component to prevent TLS connection churn to Pyroscope when the `pyroscope.receive_http` clients don't request keepalive (@madaraszg-tulip) - Fixed an issue in the `pyroscope.write` component with multiple endpoints not working correctly for forwarding profiles from `pyroscope.receive_http` (@madaraszg-tulip) @@ -74,6 +75,8 @@ Main (unreleased) - Fixed a crash when updating the configuration of `remote.http`. (@kinolaev) +- Fixed an issue in the `prometheus.operator.servicemonitors`, `prometheus.operator.podmonitors` and `prometheus.operator.probes` to support capitalized actions. (@QuentinBisson) + ### Other changes - Change the stability of the `livedebugging` feature from "experimental" to "generally available". (@wildum) diff --git a/internal/component/prometheus/operator/configgen/config_gen.go b/internal/component/prometheus/operator/configgen/config_gen.go index 7774640766..18324c7fa3 100644 --- a/internal/component/prometheus/operator/configgen/config_gen.go +++ b/internal/component/prometheus/operator/configgen/config_gen.go @@ -4,6 +4,7 @@ package configgen import ( "regexp" + "strings" promopv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" commonConfig "github.com/prometheus/common/config" @@ -197,6 +198,7 @@ func (r *relabeler) add(cfgs ...*relabel.Config) { if cfg.Action == "" { cfg.Action = relabel.DefaultRelabelConfig.Action } + cfg.Action = relabel.Action(strings.ToLower(string(cfg.Action))) if cfg.Separator == "" { cfg.Separator = relabel.DefaultRelabelConfig.Separator } diff --git a/internal/component/prometheus/operator/configgen/config_gen_servicemonitor_test.go b/internal/component/prometheus/operator/configgen/config_gen_servicemonitor_test.go index 2b772b3e3a..568c6c16b7 100644 --- a/internal/component/prometheus/operator/configgen/config_gen_servicemonitor_test.go +++ b/internal/component/prometheus/operator/configgen/config_gen_servicemonitor_test.go @@ -494,6 +494,82 @@ func TestGenerateServiceMonitorConfig(t *testing.T) { LabelValueLengthLimit: 105, }, }, + { + name: "invalid-relabelling-action", + m: &promopv1.ServiceMonitor{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "operator", + Name: "svcmonitor", + }, + }, + ep: promopv1.Endpoint{ + MetricRelabelConfigs: []*promopv1.RelabelConfig{ + { + SourceLabels: []promopv1.LabelName{"foo"}, + TargetLabel: "bar", + Action: "Replace", + }, + }, + }, + role: promk8s.RoleEndpoint, + expectedRelabels: util.Untab(` + - target_label: __meta_foo + replacement: bar + - source_labels: [job] + target_label: __tmp_prometheus_job_name + - source_labels: [__meta_kubernetes_endpoint_address_target_kind, __meta_kubernetes_endpoint_address_target_name] + regex: Node;(.*) + target_label: node + replacement: ${1} + - source_labels: [__meta_kubernetes_endpoint_address_target_kind, __meta_kubernetes_endpoint_address_target_name] + regex: Pod;(.*) + target_label: pod + action: replace + replacement: ${1} + - source_labels: [__meta_kubernetes_namespace] + target_label: namespace + - source_labels: [__meta_kubernetes_service_name] + target_label: service + - source_labels: [__meta_kubernetes_pod_container_name] + target_label: container + - source_labels: [__meta_kubernetes_pod_name] + target_label: pod + - source_labels: [__meta_kubernetes_pod_phase] + regex: (Failed|Succeeded) + action: drop + - source_labels: [__meta_kubernetes_service_name] + target_label: job + replacement: ${1} + `), + expectedMetricRelabels: util.Untab(` + - action: replace + source_labels: [foo] + target_label: bar + `), + expected: &config.ScrapeConfig{ + JobName: "serviceMonitor/operator/svcmonitor/1", + HonorTimestamps: true, + ScrapeInterval: model.Duration(time.Minute), + ScrapeTimeout: model.Duration(10 * time.Second), + ScrapeProtocols: config.DefaultScrapeProtocols, + EnableCompression: true, + MetricsPath: "/metrics", + Scheme: "http", + HTTPClientConfig: commonConfig.HTTPClientConfig{ + FollowRedirects: true, + EnableHTTP2: true, + }, + ServiceDiscoveryConfigs: discovery.Configs{ + &promk8s.SDConfig{ + Role: "endpoints", + NamespaceDiscovery: promk8s.NamespaceDiscovery{ + IncludeOwnNamespace: false, + Names: []string{"operator"}, + }, + }, + }, + }, + }, } for _, tc := range suite { t.Run(tc.name, func(t *testing.T) { From 39b358df61c97dc4011f933fd4273c4a9f25d32f Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Thu, 5 Dec 2024 18:59:42 +0100 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e585e1f78..275d8c67f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,19 +46,11 @@ Main (unreleased) ### Bugfixes -- Fixed an issue in the `pyroscope.write` component to prevent TLS connection churn to Pyroscope when the `pyroscope.receive_http` clients don't request keepalive (@madaraszg-tulip) - -- Fixed an issue in the `prometheus.operator.servicemonitors`, `prometheus.operator.podmonitors` and `prometheus.operator.probes` to support capitalized actions. (@QuentinBisson) - - Fixed issue with reloading configuration and prometheus metrics duplication in `prometheus.write.queue`. (@mattdurham) - Updated `prometheus.write.queue` to fix issue with TTL comparing different scales of time. (@mattdurham) -### Other changes - -- Change the stability of the `livedebugging` feature from "experimental" to "generally available". (@wildum) - -- Use Go 1.23.3 for builds. (@mattdurham) +- Fixed an issue in the `prometheus.operator.servicemonitors`, `prometheus.operator.podmonitors` and `prometheus.operator.probes` to support capitalized actions. (@QuentinBisson) v1.5.1 ----------------- From 2f744f560ae6e551e455fc668496942cb52f41c9 Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Thu, 5 Dec 2024 19:00:30 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 275d8c67f4..e60ac2e436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,12 @@ Main (unreleased) - Fixed an issue in the `prometheus.operator.servicemonitors`, `prometheus.operator.podmonitors` and `prometheus.operator.probes` to support capitalized actions. (@QuentinBisson) +### Other changes + +- Change the stability of the `livedebugging` feature from "experimental" to "generally available". (@wildum) + +- Use Go 1.23.3 for builds. (@mattdurham) + v1.5.1 ----------------- @@ -84,10 +90,6 @@ v1.5.1 ### Other changes -- Change the stability of the `livedebugging` feature from "experimental" to "generally available". (@wildum) - -- Use Go 1.23.3 for builds. (@mattdurham) - - Fixed an issue in the `otelcol.processor.attribute` component where the actions `delete` and `hash` could not be used with the `pattern` argument. (@wildum) - Fixed an issue in the `prometheus.exporter.postgres` component that would leak goroutines when the target was not reachable (@dehaansa) From 6faeb84ec38ef5279ff3a45936a60b63da79c22e Mon Sep 17 00:00:00 2001 From: Quentin Bisson Date: Thu, 5 Dec 2024 19:00:56 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e60ac2e436..750a40f3f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,8 +88,6 @@ v1.5.1 - Fixed a crash when updating the configuration of `remote.http`. (@kinolaev) -### Other changes - - Fixed an issue in the `otelcol.processor.attribute` component where the actions `delete` and `hash` could not be used with the `pattern` argument. (@wildum) - Fixed an issue in the `prometheus.exporter.postgres` component that would leak goroutines when the target was not reachable (@dehaansa)