-
Notifications
You must be signed in to change notification settings - Fork 145
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
Support metrics relabelings in service monitor #10095
Conversation
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.
There was a problem hiding this 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: [] |
There was a problem hiding this comment.
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:
metricRelabelings: [] | |
metricRelabelings: [] | |
# - source_labels: [ __meta_kubernetes_namespace ] | |
# separator: ; | |
# regex: (.*) | |
# target_label: namespace | |
# replacement: $1 | |
# action: replace |
@rohanag12 I went ahead and pushed my suggestions. Thanks for your contribution! |
Thank you! |
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.