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

fix: support capitalized relabel actions to match with prometheus-operator behavior #2209

Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ 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)
Expand Down Expand Up @@ -86,6 +90,12 @@ v1.5.1

- Fixed a crash when updating the configuration of `remote.http`. (@kinolaev)

### 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading