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

Support metrics relabelings in service monitor #10095

Merged

Conversation

rohanag12
Copy link
Contributor

The service monitor CRD allows configuring metric relabeling rules which are applied when the metrics are scraped. Support configuring metric relabeling configs in the helm chart.

The service monitor CRD allows configuring metric relabeling rules
which are applied when the metrics are scraped. Support configuring
metric relabeling configs in the helm chart.
@snazy snazy requested a review from adutra December 16, 2024 11:22
Copy link
Contributor

@adutra adutra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rohanag12 do you mind adding a unit test as well? Could be a new file, servicemonitor_test.yaml, with e.g. the below contents:

release:
  name: nessie
  namespace: nessie-ns

capabilities:
  apiVersions:
    - monitoring.coreos.com/v1

templates:
  - servicemonitor.yaml

tests:
  - it: should create ServiceMonitor if enabled
    set: { serviceMonitor: { enabled: true } }
    asserts: [ { containsDocument: { kind: ServiceMonitor, apiVersion: monitoring.coreos.com/v1, name: nessie, namespace: nessie-ns } } ]
  - it: should not create ServiceMonitor if disabled
    set: { serviceMonitor: { enabled: false } }
    asserts: [ { containsDocument: { kind: ServiceMonitor, apiVersion: monitoring.coreos.com/v1, name: nessie, namespace: nessie-ns }, not: true } ]
  - it: should add metrics relabelings
    set:
      serviceMonitor:
        enabled: true
        metricRelabelings:
          - source_labels: [ __meta_kubernetes_namespace ]
            separator: ;
            regex: (.*)
            target_label: namespace
            replacement: $1
            action: replace
    asserts:
      - equal:
          path: spec.endpoints[ 0].metricRelabelings
          value:
            - source_labels: [ __meta_kubernetes_namespace ]
              separator: ;
              regex: (.*)
              target_label: namespace
              replacement: $1
              action: replace

Thanks!

@@ -713,6 +713,8 @@ serviceMonitor:
labels:
{}
# release: prometheus
# -- Relabeling rules to apply to metrics. Ref https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config.
metricRelabelings: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an example here to help users understand the syntax:

Suggested change
metricRelabelings: []
metricRelabelings: []
# - source_labels: [ __meta_kubernetes_namespace ]
# separator: ;
# regex: (.*)
# target_label: namespace
# replacement: $1
# action: replace

@adutra adutra enabled auto-merge (squash) December 27, 2024 10:15
@adutra
Copy link
Contributor

adutra commented Dec 27, 2024

@rohanag12 I went ahead and pushed my suggestions. Thanks for your contribution!

@adutra adutra merged commit 80c3316 into projectnessie:main Dec 27, 2024
16 checks passed
@rohanag12
Copy link
Contributor Author

@rohanag12 I went ahead and pushed my suggestions. Thanks for your contribution!

Thank you!

@rohanag12 rohanag12 deleted the feature/service-monitor-metric-relabelings branch January 15, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants