-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[kube-prometheus-stack] Grafana crd datasources #5240
base: main
Are you sure you want to change the base?
[kube-prometheus-stack] Grafana crd datasources #5240
Conversation
Signed-off-by: Oleg Tsymbal <[email protected]>
Signed-off-by: Oleg Tsymbal <[email protected]>
Signed-off-by: Oleg Tsymbal <[email protected]>
Signed-off-by: Oleg Tsymbal <[email protected]>
Signed-off-by: Oleg Tsymbal <[email protected]>
Signed-off-by: Oleg Tsymbal <[email protected]>
Signed-off-by: Oleg Tsymbal <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for split this help. It help at least me to review this with a bit more focus.
To go through the files and leave comments that I have in my mind.
charts/kube-prometheus-stack/templates/grafana/crd-datasources.yaml
Outdated
Show resolved
Hide resolved
charts/kube-prometheus-stack/templates/grafana/configmaps-datasources.yaml
Show resolved
Hide resolved
charts/kube-prometheus-stack/templates/grafana/configmaps-datasources.yaml
Outdated
Show resolved
Hide resolved
{{- $defaultDS := dict -}} | ||
{{- $_ := set $defaultDS "name" .Values.grafana.sidecar.datasources.name -}} | ||
{{- $_ := set $defaultDS "type" "prometheus" -}} | ||
{{- $_ := set $defaultDS "uid" .Values.grafana.sidecar.datasources.uid -}} | ||
{{- $_ := set $defaultDS "url" (default (printf "http://%s-prometheus.%s:%v/%s" | ||
(include "kube-prometheus-stack.fullname" .) | ||
(include "kube-prometheus-stack.namespace" .) | ||
.Values.prometheus.service.port | ||
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | ||
) .Values.grafana.sidecar.datasources.url) -}} | ||
{{- $_ := set $defaultDS "access" "proxy" -}} | ||
{{- $_ := set $defaultDS "isDefault" .Values.grafana.sidecar.datasources.isDefaultDatasource -}} | ||
{{- $_ := set $defaultDS "jsonData" $jsonData -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a suggestion which can be considered as alternative. It's just an option to discuss about if possible and it's not indented as "please use this".
{{- $defaultDS := dict -}} | |
{{- $_ := set $defaultDS "name" .Values.grafana.sidecar.datasources.name -}} | |
{{- $_ := set $defaultDS "type" "prometheus" -}} | |
{{- $_ := set $defaultDS "uid" .Values.grafana.sidecar.datasources.uid -}} | |
{{- $_ := set $defaultDS "url" (default (printf "http://%s-prometheus.%s:%v/%s" | |
(include "kube-prometheus-stack.fullname" .) | |
(include "kube-prometheus-stack.namespace" .) | |
.Values.prometheus.service.port | |
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | |
) .Values.grafana.sidecar.datasources.url) -}} | |
{{- $_ := set $defaultDS "access" "proxy" -}} | |
{{- $_ := set $defaultDS "isDefault" .Values.grafana.sidecar.datasources.isDefaultDatasource -}} | |
{{- $_ := set $defaultDS "jsonData" $jsonData -}} | |
{{- $defaultDS := (dict | |
"name" .Values.grafana.sidecar.datasources.name | |
"type" "prometheus" | |
"uid" .Values.grafana.sidecar.datasources.uid | |
"url" (default (printf "http://%s-prometheus.%s:%v/%s" | |
(include "kube-prometheus-stack.fullname" .) | |
(include "kube-prometheus-stack.namespace" .) | |
.Values.prometheus.service.port | |
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | |
) .Values.grafana.sidecar.datasources.url) | |
"access" "proxy" | |
"isDefault" .Values.grafana.sidecar.datasources.isDefaultDatasource | |
"jsonData" $jsonData | |
) -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkroepke the main problem here, that if we take your approach we loose the possibility to add comments, because any comments between dict keys break the formatting. At the beginning I implemented it in a way you suggested but later I realized that I cannot make nice conditionals with comments, so I switched to this version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dzirg44 what the downside of just using plain templating instead put everything logic into the templating syntax?
I still feel not happy, it feel like an unnatural helm template.
{{- $defaultDS := dict -}} | |
{{- $_ := set $defaultDS "name" .Values.grafana.sidecar.datasources.name -}} | |
{{- $_ := set $defaultDS "type" "prometheus" -}} | |
{{- $_ := set $defaultDS "uid" .Values.grafana.sidecar.datasources.uid -}} | |
{{- $_ := set $defaultDS "url" (default (printf "http://%s-prometheus.%s:%v/%s" | |
(include "kube-prometheus-stack.fullname" .) | |
(include "kube-prometheus-stack.namespace" .) | |
.Values.prometheus.service.port | |
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | |
) .Values.grafana.sidecar.datasources.url) -}} | |
{{- $_ := set $defaultDS "access" "proxy" -}} | |
{{- $_ := set $defaultDS "isDefault" .Values.grafana.sidecar.datasources.isDefaultDatasource -}} | |
{{- $_ := set $defaultDS "jsonData" $jsonData -}} | |
name: {{ .Values.grafana.sidecar.datasources.name }} | |
type: prometheus | |
uid: {{ .Values.grafana.sidecar.datasources.uid }} | |
url: {{ (default (printf "http://%s-prometheus.%s:%v/%s" | |
(include "kube-prometheus-stack.fullname" .) | |
(include "kube-prometheus-stack.namespace" .) | |
.Values.prometheus.service.port | |
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | |
) .Values.grafana.sidecar.datasources.url) }} | |
access: proxy | |
isDefault: {{ .Values.grafana.sidecar.datasources.isDefaultDatasource }} | |
{{- with $jsonData }} | |
jsonData: | |
{{ . | nindent 2 }} | |
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkroepke Can you take a look at the refactored version?
In essence I:
created 3 functions
kube-prometheus-stack.grafana.datasourceUrl.defaultPrometheus
kube-prometheus-stack.grafana.datasourceUrl.replica
kube-prometheus-stack.grafana.datasourceUrl.alertmanager
Converted urlDisplayLabel in exemplarTraceIdDestinations
used coalesce instead of default (can be reverted back) in some cases
timeout
- removed (i don't see this parameter in the values or in grafana prometheus datasource api)
Some potential issues:
- exemplarTraceIdDestinations, if I am not mistaken this parameter cannot be omitted so probably the code can be unsafe.
- this code is really weird
{{- $scrapeInterval := .Values.grafana.sidecar.datasources.defaultDatasourceScrapeInterval | default .Values.prometheus.prometheusSpec.scrapeInterval | default "30s" }}
would it be better to set scrapeInterval to 30s in values and remove default?
Signed-off-by: Oleg Tsymbal <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it looks good, but I'm not happy how the yaml is generated within the new helper
{{- $defaultDS := dict -}} | ||
{{- $_ := set $defaultDS "name" .Values.grafana.sidecar.datasources.name -}} | ||
{{- $_ := set $defaultDS "type" "prometheus" -}} | ||
{{- $_ := set $defaultDS "uid" .Values.grafana.sidecar.datasources.uid -}} | ||
{{- $_ := set $defaultDS "url" (default (printf "http://%s-prometheus.%s:%v/%s" | ||
(include "kube-prometheus-stack.fullname" .) | ||
(include "kube-prometheus-stack.namespace" .) | ||
.Values.prometheus.service.port | ||
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | ||
) .Values.grafana.sidecar.datasources.url) -}} | ||
{{- $_ := set $defaultDS "access" "proxy" -}} | ||
{{- $_ := set $defaultDS "isDefault" .Values.grafana.sidecar.datasources.isDefaultDatasource -}} | ||
{{- $_ := set $defaultDS "jsonData" $jsonData -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dzirg44 what the downside of just using plain templating instead put everything logic into the templating syntax?
I still feel not happy, it feel like an unnatural helm template.
{{- $defaultDS := dict -}} | |
{{- $_ := set $defaultDS "name" .Values.grafana.sidecar.datasources.name -}} | |
{{- $_ := set $defaultDS "type" "prometheus" -}} | |
{{- $_ := set $defaultDS "uid" .Values.grafana.sidecar.datasources.uid -}} | |
{{- $_ := set $defaultDS "url" (default (printf "http://%s-prometheus.%s:%v/%s" | |
(include "kube-prometheus-stack.fullname" .) | |
(include "kube-prometheus-stack.namespace" .) | |
.Values.prometheus.service.port | |
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | |
) .Values.grafana.sidecar.datasources.url) -}} | |
{{- $_ := set $defaultDS "access" "proxy" -}} | |
{{- $_ := set $defaultDS "isDefault" .Values.grafana.sidecar.datasources.isDefaultDatasource -}} | |
{{- $_ := set $defaultDS "jsonData" $jsonData -}} | |
name: {{ .Values.grafana.sidecar.datasources.name }} | |
type: prometheus | |
uid: {{ .Values.grafana.sidecar.datasources.uid }} | |
url: {{ (default (printf "http://%s-prometheus.%s:%v/%s" | |
(include "kube-prometheus-stack.fullname" .) | |
(include "kube-prometheus-stack.namespace" .) | |
.Values.prometheus.service.port | |
(trimPrefix "/" .Values.prometheus.prometheusSpec.routePrefix) | |
) .Values.grafana.sidecar.datasources.url) }} | |
access: proxy | |
isDefault: {{ .Values.grafana.sidecar.datasources.isDefaultDatasource }} | |
{{- with $jsonData }} | |
jsonData: | |
{{ . | nindent 2 }} | |
{{- end }} |
Signed-off-by: Oleg Tsymbal <[email protected]>
Signed-off-by: Oleg Tsymbal <[email protected]>
Introducing Grafana Datasources as CRDs
Special notes for your reviewer
this PR is a result of #5216
I essence I don't expect any problems but you have to pay attention to 3 things
Details
the name of
name: {{ include "kube-prometheus-stack.fullname" $ }}-{{ include "kube-prometheus-stack.grafana.sanitizeName" $ds.name }}
, probably you have a better idea or conventions to name it.default values for
I have them in 2 places (values, and the resource), but I often do like this in my charts, but idk if it is appropriate here.
@jkroepke
Also, if I have to mention about it in the documentation - let me know.
Checklist
[prometheus-couchdb-exporter]
)