From 8c5b8c08d2bec09451305786d65f5ad093cac7b0 Mon Sep 17 00:00:00 2001 From: Garry O'Donnell Date: Tue, 19 Sep 2023 03:02:54 +0100 Subject: [PATCH] [prometheus] Apply templating to remote_read & remote_write config (#3777) * Apply templating to remote_read & remote_write config Signed-off-by: Garry O'Donnell * Add migration instructions for prometheus 25.0 Signed-off-by: Garry O'Donnell Signed-off-by: Garry O'Donnell * Only template URLs Signed-off-by: Garry O'Donnell Signed-off-by: Garry O'Donnell * Fix whitespace Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Garry O'Donnell --------- Signed-off-by: Garry O'Donnell Signed-off-by: Garry O'Donnell Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> --- charts/prometheus/Chart.yaml | 2 +- charts/prometheus/README.md | 6 ++++++ charts/prometheus/templates/_helpers.tpl | 23 +++++++++++++++++++++++ charts/prometheus/templates/cm.yaml | 4 ++-- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/charts/prometheus/Chart.yaml b/charts/prometheus/Chart.yaml index 53571bbfab10..7c5e61eccfb5 100644 --- a/charts/prometheus/Chart.yaml +++ b/charts/prometheus/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: prometheus appVersion: v2.47.0 -version: 24.5.0 +version: 25.0.0 kubeVersion: ">=1.19.0-0" description: Prometheus is a monitoring system and time series database. home: https://prometheus.io/ diff --git a/charts/prometheus/README.md b/charts/prometheus/README.md index 3246e3712b86..2cb744ce8f52 100644 --- a/charts/prometheus/README.md +++ b/charts/prometheus/README.md @@ -65,6 +65,12 @@ helm upgrade [RELEASE_NAME] prometheus-community/prometheus --install _See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._ +### To 25.0 + +The `server.remoteRead[].url` and `server.remoteWrite[].url` fields now support templating. Allowing for `url` values such as `https://{{ .Release.Name }}.example.com`. + +Any entries in these which previously included `{{` or `}}` must be escaped with `{{ "{{" }}` and `{{ "}}" }}` respectively. Entries which did not previously include the template-like syntax will not be affected. + ### To 24.0 Require Kubernetes 1.19+ diff --git a/charts/prometheus/templates/_helpers.tpl b/charts/prometheus/templates/_helpers.tpl index 0f4c631867bd..daec18e28052 100644 --- a/charts/prometheus/templates/_helpers.tpl +++ b/charts/prometheus/templates/_helpers.tpl @@ -211,3 +211,26 @@ Define template prometheus.namespaces producing a list of namespaces to monitor {{- end -}} {{ mustToJson $namespaces }} {{- end -}} + +{{/* +Define prometheus.server.remoteWrite producing a list of remoteWrite configurations with URL templating +*/}} +{{- define "prometheus.server.remoteWrite" -}} +{{- $remoteWrites := list }} +{{- range $remoteWrite := .Values.server.remoteWrite }} + {{- $remoteWrites = tpl $remoteWrite.url $ | set $remoteWrite "url" | append $remoteWrites }} +{{- end -}} +{{ toYaml $remoteWrites }} +{{- end -}} + +{{/* +Define prometheus.server.remoteRead producing a list of remoteRead configurations with URL templating +*/}} +{{- define "prometheus.server.remoteRead" -}} +{{- $remoteReads := list }} +{{- range $remoteRead := .Values.server.remoteRead }} + {{- $remoteReads = tpl $remoteRead.url $ | set $remoteRead "url" | append $remoteReads }} +{{- end -}} +{{ toYaml $remoteReads }} +{{- end -}} + diff --git a/charts/prometheus/templates/cm.yaml b/charts/prometheus/templates/cm.yaml index a702b527ee32..4e1ba70b84d1 100644 --- a/charts/prometheus/templates/cm.yaml +++ b/charts/prometheus/templates/cm.yaml @@ -22,11 +22,11 @@ data: {{ $root.Values.server.global | toYaml | trimSuffix "\n" | indent 6 }} {{- if $root.Values.server.remoteWrite }} remote_write: -{{ $root.Values.server.remoteWrite | toYaml | indent 4 }} +{{- include "prometheus.server.remoteWrite" $root | nindent 4 }} {{- end }} {{- if $root.Values.server.remoteRead }} remote_read: -{{ $root.Values.server.remoteRead | toYaml | indent 4 }} +{{- include "prometheus.server.remoteRead" $root | nindent 4 }} {{- end }} {{- if or $root.Values.server.tsdb $root.Values.server.exemplars }} storage: