Skip to content

Commit

Permalink
[prometheus] Apply templating to remote_read & remote_write config (p…
Browse files Browse the repository at this point in the history
…rometheus-community#3777)

* Apply templating to remote_read & remote_write config

Signed-off-by: Garry O'Donnell <garry.o'[email protected]>

* Add migration instructions for prometheus 25.0

Signed-off-by: Garry O'Donnell <garry.o'[email protected]>
Signed-off-by: Garry O'Donnell <[email protected]>

* Only template URLs

Signed-off-by: Garry O'Donnell <garry.o'[email protected]>
Signed-off-by: Garry O'Donnell <[email protected]>

* Fix whitespace

Co-authored-by: zeritti <[email protected]>
Signed-off-by: Garry O'Donnell <[email protected]>

---------

Signed-off-by: Garry O'Donnell <garry.o'[email protected]>
Signed-off-by: Garry O'Donnell <[email protected]>
Co-authored-by: zeritti <[email protected]>
  • Loading branch information
garryod and zeritti authored Sep 19, 2023
1 parent c48edfd commit b8b561e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/prometheus/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
6 changes: 6 additions & 0 deletions charts/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
23 changes: 23 additions & 0 deletions charts/prometheus/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

4 changes: 2 additions & 2 deletions charts/prometheus/templates/cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b8b561e

Please sign in to comment.