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

Add servicemonitor relabelings #834

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions templates/prometheus-servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ spec:
- prometheus
tlsConfig:
insecureSkipVerify: true
{{- if .Values.serverTelemetry.serviceMonitor.metricRelabelings }}
metricRelabelings: {{- toYaml .Values.serverTelemetry.serviceMonitor.metricRelabelings | nindent 4 }}
{{- end }}
{{- if .Values.serverTelemetry.serviceMonitor.relabelings }}
relabelings: {{- toYaml .Values.serverTelemetry.serviceMonitor.relabelings | nindent 4 }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
Expand Down
54 changes: 54 additions & 0 deletions test/unit/prometheus-servicemonitor.bats
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,57 @@ load _helpers
[ "$(echo "$output" | yq -r '.spec.endpoints | length')" = "1" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0].port')" = "https" ]
}

@test "prometheus/ServiceMonitor-server: assertMetricRelabelings default" {
cd `chart_dir`
local output=$( (helm template \
--show-only templates/prometheus-servicemonitor.yaml \
--set 'serverTelemetry.serviceMonitor.enabled=true' \
. ) | tee /dev/stderr)

[ "$(echo "$output" | yq -r '.spec.endpoints | length')" = "1" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0] | has("metricRelabelings")')" = "false" ]
}

@test "prometheus/ServiceMonitor-server: assertMetricRelabelings override" {
cd `chart_dir`
local output=$( (helm template \
--show-only templates/prometheus-servicemonitor.yaml \
--set 'serverTelemetry.serviceMonitor.enabled=true' \
--set 'serverTelemetry.serviceMonitor.metricRelabelings[0]=foo' \
--set 'serverTelemetry.serviceMonitor.metricRelabelings[1]=foo' \
. ) | tee /dev/stderr)

[ "$(echo "$output" | yq -r '.spec.endpoints | length')" = "1" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0] | has("metricRelabelings")')" = "true" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0].metricRelabelings | length')" = "2" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0].metricRelabelings[0]')" = "foo" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0].metricRelabelings[1]')" = "foo" ]
}

@test "prometheus/ServiceMonitor-server: assertRelabelings default" {
cd `chart_dir`
local output=$( (helm template \
--show-only templates/prometheus-servicemonitor.yaml \
--set 'serverTelemetry.serviceMonitor.enabled=true' \
. ) | tee /dev/stderr)

[ "$(echo "$output" | yq -r '.spec.endpoints | length')" = "1" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0] | has("relabelings")')" = "false" ]
}

@test "prometheus/ServiceMonitor-server: assertRelabelings override" {
cd `chart_dir`
local output=$( (helm template \
--show-only templates/prometheus-servicemonitor.yaml \
--set 'serverTelemetry.serviceMonitor.enabled=true' \
--set 'serverTelemetry.serviceMonitor.relabelings[0]=foo' \
--set 'serverTelemetry.serviceMonitor.relabelings[1]=foo' \
. ) | tee /dev/stderr)

[ "$(echo "$output" | yq -r '.spec.endpoints | length')" = "1" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0] | has("relabelings")')" = "true" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0].relabelings | length')" = "2" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0].relabelings[0]')" = "foo" ]
[ "$(echo "$output" | yq -r '.spec.endpoints[0].relabelings[1]')" = "foo" ]
}
18 changes: 18 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,24 @@ serverTelemetry:
# Timeout for Prometheus scrapes
scrapeTimeout: 10s

# MetricRelabelConfigs to apply to samples before ingestion.
metricRelabelings: []
# Some example metricRelabelings.
#- action: "replace"
# regex: "(.*)"
# sourceLabels:
# - "cluster"
# targetLabel: "vault_cluster"

# RelabelConfigs to apply to samples before scraping.
relabelings: []
# Some example relabelings.
#- action: "replace"
# regex: "(.*)"
# sourceLabels:
# - "cluster"
# targetLabel: "vault_cluster"

prometheusRules:
# The Prometheus operator *must* be installed before enabling this feature,
# if not the chart will fail to install due to missing CustomResourceDefinitions
Expand Down