From aaa91c9184284d209b1cbe5cf610036db28f4af2 Mon Sep 17 00:00:00 2001 From: Francisco Esteveira <56481538+festeveira@users.noreply.github.com> Date: Mon, 9 Dec 2024 19:01:09 +0000 Subject: [PATCH] [prometheus-postgres-exporter] Implement multiple target in service monitor (#5012) * [prometheus-postgres-exporter] Implement multiple target with /probe endpoint Signed-off-by: festeveira * Replace multipleTargets with multipleTarget Signed-off-by: festeveira * Improve values.yaml documentation Signed-off-by: festeveira * Remove /postgres path from target param in ServiceMonitor Signed-off-by: festeveira --------- Signed-off-by: festeveira Signed-off-by: Francisco Esteveira <56481538+festeveira@users.noreply.github.com> Co-authored-by: MH --- .../prometheus-postgres-exporter/Chart.yaml | 2 +- .../templates/servicemonitor.yaml | 47 +++++++++++++++++++ .../prometheus-postgres-exporter/values.yaml | 16 +++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/charts/prometheus-postgres-exporter/Chart.yaml b/charts/prometheus-postgres-exporter/Chart.yaml index 84e8c3be94d8..df1c78378907 100644 --- a/charts/prometheus-postgres-exporter/Chart.yaml +++ b/charts/prometheus-postgres-exporter/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: "v0.16.0" description: A Helm chart for prometheus postgres-exporter name: prometheus-postgres-exporter -version: 6.6.0 +version: 6.7.0 home: https://github.com/prometheus-community/postgres_exporter sources: - https://github.com/prometheus-community/postgres_exporter diff --git a/charts/prometheus-postgres-exporter/templates/servicemonitor.yaml b/charts/prometheus-postgres-exporter/templates/servicemonitor.yaml index ca31a24e0c2b..e8a51d9e586b 100644 --- a/charts/prometheus-postgres-exporter/templates/servicemonitor.yaml +++ b/charts/prometheus-postgres-exporter/templates/servicemonitor.yaml @@ -12,6 +12,52 @@ metadata: namespace: {{ .Values.serviceMonitor.namespace }} {{- end }} spec: +{{- if .Values.serviceMonitor.multipleTarget.enabled }} + endpoints: + {{- range .Values.serviceMonitor.multipleTarget.targets }} + - path: /probe + port: {{ $.Values.service.name }} + {{- if $.Values.serviceMonitor.interval }} + interval: {{ $.Values.serviceMonitor.interval }} + {{- end }} + {{- if $.Values.serviceMonitor.timeout }} + scrapeTimeout: {{ $.Values.serviceMonitor.timeout }} + {{- end }} + {{- if $.Values.serviceMonitor.scheme }} + scheme: {{ $.Values.serviceMonitor.scheme }} + {{- end }} + {{- with $.Values.serviceMonitor.tlsConfig }} + tlsConfig: + {{- toYaml . | nindent 6 }} + {{- end }} + metricRelabelings: + - action: replace + replacement: {{ .endpoint }} + sourceLabels: [instance] + targetLabel: instance + - action: replace + replacement: {{ .name }} + sourceLabels: [target] + targetLabel: target + {{- if $.Values.serviceMonitor.metricRelabelings -}} + {{ toYaml $.Values.serviceMonitor.metricRelabelings | nindent 8 }} + {{- end }} + {{- if $.Values.serviceMonitor.relabelings }} + relabelings: {{ toYaml $.Values.serviceMonitor.relabelings | nindent 8 }} + {{- end }} + params: + target: + - {{ .endpoint }}:{{ .port | default 5432 }} + {{- if $.Values.serviceMonitor.multipleTarget.sharedAuthModule.enabled }} + auth_module: + - {{ $.Values.serviceMonitor.multipleTarget.sharedAuthModule.name }} + {{- else }} + auth_module: + - client.{{ .name }} + {{- end }} + {{- end }} +{{- end }} +{{- if not .Values.serviceMonitor.multipleTarget.enabled -}} endpoints: - port: {{ .Values.service.name }} {{- if .Values.serviceMonitor.interval }} @@ -37,6 +83,7 @@ spec: {{- with .Values.serviceMonitor.tlsConfig }} tlsConfig: {{- toYaml . | nindent 6 }} +{{- end }} {{- end }} jobLabel: {{ template "prometheus-postgres-exporter.fullname" . }} namespaceSelector: diff --git a/charts/prometheus-postgres-exporter/values.yaml b/charts/prometheus-postgres-exporter/values.yaml index 8d718f0ce717..feb6a9aefff1 100644 --- a/charts/prometheus-postgres-exporter/values.yaml +++ b/charts/prometheus-postgres-exporter/values.yaml @@ -50,6 +50,22 @@ serviceMonitor: # TLS configuration to use when scraping the metric endpoint by Prometheus. # tlsConfig: {} + # Use multipleTarget mode + multipleTarget: + enabled: false + # Use the same auth module for every target + # The config file should have a section like [$name] + sharedAuthModule: + enabled: false + name: "" + + # Define each target's endpoint and name + # When not using sharedAuthModule the config file should have one authModule for each target with key "client.$name" + targets: [] + # - endpoint: pg01.local + # name: pg01 (there needs to exist an authModule with key "client.pg01" if not using sharedAuthModule) + # port: default 5432 + prometheusRule: enabled: false additionalLabels: {}