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

[prometheus] Add support for external_labels #3892

Closed
Closed
6 changes: 6 additions & 0 deletions charts/prometheus/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -232,3 +232,9 @@ Define prometheus.server.remoteRead producing a list of remoteRead configuration
{{ toYaml $remoteReads }}
{{- end -}}

{{/*
Define prometheus.server.global.externalLabels producing a list of externalLabels
*/}}
{{- define "prometheus.server.global.externalLabels" -}}
{{ toYaml .Values.server.global.externalLabels }}
{{- end -}}
Comment on lines +235 to +240
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helper template is unnecessary.

Suggested change
{{/*
Define prometheus.server.global.externalLabels producing a list of externalLabels
*/}}
{{- define "prometheus.server.global.externalLabels" -}}
{{ toYaml .Values.server.global.externalLabels }}
{{- end -}}

4 changes: 4 additions & 0 deletions charts/prometheus/templates/cm.yaml
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@ data:
{{- if eq $key "prometheus.yml" }}
global:
{{ $root.Values.server.global | toYaml | trimSuffix "\n" | indent 6 }}
{{- if $root.Values.server.global.externalLabels }}
external_labels:
{{- include "prometheus.server.global.externalLabels" $root | nindent 8 }}
{{- end }}
Comment on lines +23 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The managed field externalLabels cannot be present in server.global as the latter gets inserted in Prometheus' config file as is and can therefore only include valid configuration parameters (the change won't pass CI). This is why external_labels and any other Prometheus' global configuration parameter can currently be set directly through this field.

Suggested change
{{- if $root.Values.server.global.externalLabels }}
external_labels:
{{- include "prometheus.server.global.externalLabels" $root | nindent 8 }}
{{- end }}
{{- with $root.Values.server.externalLabels }}
external_labels: {{ toYaml . | nindent 8 }}
{{- end }}

{{- if $root.Values.server.remoteWrite }}
remote_write:
{{- include "prometheus.server.remoteWrite" $root | nindent 4 }}
3 changes: 3 additions & 0 deletions charts/prometheus/values.schema.json
Original file line number Diff line number Diff line change
@@ -271,6 +271,9 @@
"global": {
"type": "object",
"properties": {
"external_labels": {
"type": "object"
},
Comment on lines +274 to +276
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As shown above, you are setting the field nested in server, not in global. The schema has to include server.externalLabels instead. Please, remember to insert the new field in values.yaml as well with a short comment/reference as seen e.g. at server.remoteRead.

"evaluation_interval": {
"type": "string"
},
3 changes: 3 additions & 0 deletions charts/prometheus/values.yaml
Original file line number Diff line number Diff line change
@@ -245,6 +245,9 @@ server:
## How frequently to evaluate rules
##
evaluation_interval: 1m
## https://prometheus.io/docs/prometheus/latest/configuration/configuration/
##
externalLabels: {}
Comment on lines +248 to +250
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in the comment above, needs to be moved out of server.global in server.

Suggested change
## https://prometheus.io/docs/prometheus/latest/configuration/configuration/
##
externalLabels: {}
## https://prometheus.io/docs/prometheus/latest/configuration/configuration/
##
externalLabels: {}

## https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write
##
remoteWrite: []