Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion charts/prometheus-json-exporter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type: application
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
version: 0.19.2
version: 0.20.0
appVersion: "v0.7.0"
home: https://github.com/prometheus-community/json_exporter
maintainers:
Expand Down
11 changes: 9 additions & 2 deletions charts/prometheus-json-exporter/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ spec:
module:
- {{ .module }}
{{- end }}
{{- $additionalMetricsRelabels := .additionalMetricsRelabels | default $.Values.serviceMonitor.defaults.additionalMetricsRelabels }}
metricRelabelings:
- sourceLabels: [instance]
targetLabel: instance
Expand All @@ -34,11 +35,17 @@ spec:
targetLabel: target
replacement: {{ .name }}
action: replace
{{- range $targetLabel, $replacement := .additionalMetricsRelabels | default $.Values.serviceMonitor.defaults.additionalMetricsRelabels }}
{{- if kindIs "slice" $additionalMetricsRelabels }}
{{- with $additionalMetricsRelabels }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- else }}
{{- range $targetLabel, $replacement := $additionalMetricsRelabels }}
- targetLabel: {{ $targetLabel }}
replacement: {{ $replacement }}
action: replace
{{- end }}
{{- end }}
{{- end }}
{{- with .additionalRelabels | default $.Values.serviceMonitor.defaults.additionalRelabels }}
relabelings:
{{- toYaml . | nindent 6 }}
Expand Down
125 changes: 125 additions & 0 deletions charts/prometheus-json-exporter/unittests/servicemonitor_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
suite: test servicemonitor
templates:
- servicemonitor.yaml
tests:
- it: should not render when disabled
set:
serviceMonitor.enabled: false
asserts:
- hasDocuments:
count: 0

- it: should render the built-in instance and target relabelings
set:
serviceMonitor.enabled: true
serviceMonitor.targets:
- name: example
url: http://example.com/healthz
asserts:
- hasDocuments:
count: 1
- isKind:
of: ServiceMonitor
- equal:
path: spec.endpoints[0].metricRelabelings
value:
- sourceLabels: [instance]
targetLabel: instance
replacement: http://example.com/healthz
action: replace
- sourceLabels: [target]
targetLabel: target
replacement: example
action: replace

- it: should render the map form as replace relabelings after the built-ins
set:
serviceMonitor.enabled: true
serviceMonitor.targets:
- name: example
url: http://example.com/healthz
additionalMetricsRelabels:
team: backend
asserts:
- equal:
path: spec.endpoints[0].metricRelabelings[2]
value:
targetLabel: team
replacement: backend
action: replace

- it: should render the list form as full relabeling specs after the built-ins
set:
serviceMonitor.enabled: true
serviceMonitor.targets:
- name: example
url: http://example.com/healthz
additionalMetricsRelabels:
- sourceLabels: [__name__]
regex: 'go_.*'
action: drop
asserts:
- equal:
path: spec.endpoints[0].metricRelabelings[2]
value:
sourceLabels: [__name__]
regex: 'go_.*'
action: drop

- it: should render only the built-ins for an empty map
set:
serviceMonitor.enabled: true
serviceMonitor.targets:
- name: example
url: http://example.com/healthz
additionalMetricsRelabels: {}
asserts:
- lengthEqual:
path: spec.endpoints[0].metricRelabelings
count: 2

- it: should render only the built-ins for an empty list
set:
serviceMonitor.enabled: true
serviceMonitor.targets:
- name: example
url: http://example.com/healthz
additionalMetricsRelabels: []
asserts:
- lengthEqual:
path: spec.endpoints[0].metricRelabelings
count: 2

- it: should apply the list form from defaults when the target omits it
set:
serviceMonitor.enabled: true
serviceMonitor.defaults.additionalMetricsRelabels:
- sourceLabels: [__name__]
regex: 'go_.*'
action: drop
serviceMonitor.targets:
- name: example
url: http://example.com/healthz
asserts:
- equal:
path: spec.endpoints[0].metricRelabelings[2]
value:
sourceLabels: [__name__]
regex: 'go_.*'
action: drop

- it: should still render additionalRelabels as relabelings
set:
serviceMonitor.enabled: true
serviceMonitor.targets:
- name: example
url: http://example.com/healthz
additionalRelabels:
- sourceLabels: [__meta_kubernetes_pod_node_name]
targetLabel: node
asserts:
- equal:
path: spec.endpoints[0].relabelings
value:
- sourceLabels: [__meta_kubernetes_pod_node_name]
targetLabel: node
4 changes: 3 additions & 1 deletion charts/prometheus-json-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ serviceMonitor:

# Default values that will be used for all ServiceMonitors created by `targets`
defaults:
# Either a map of `targetLabel: replacement` pairs, each rendered as a
# `replace` metric relabeling, or a list of full Prometheus relabeling specs.
additionalMetricsRelabels: {}
additionalRelabels: []
interval: 10s
Expand All @@ -88,7 +90,7 @@ serviceMonitor:
# labels: {} # Map of labels for ServiceMonitor. Overrides value set in `defaults`
# interval: 60s # Scraping interval. Overrides value set in `defaults`
# scrapeTimeout: 60s # Scrape timeout. Overrides value set in `defaults`
# additionalMetricsRelabels: {} # Map of metric labels and values to add
# additionalMetricsRelabels: {} # Map of metric labels and values to add, or a list of full relabeling specs. Overrides value set in `defaults`
# additionalRelabels: [] # relabelings of metrics
# module: example_module # Name of the module to pick up from `config.yaml` for scraping this target. Optional. Default is `default` provided by the exporter itself.

Expand Down