Skip to content

Commit

Permalink
fix: support capitalized relabel actions to match with prometheus-ope…
Browse files Browse the repository at this point in the history
…rator behavior
  • Loading branch information
QuentinBisson committed Dec 3, 2024
1 parent 1cc7861 commit c69599c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
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

0 comments on commit c69599c

Please sign in to comment.