Grafana: Provision data sources via dynamic template in values

This moves to define the datasources provisioned by grafana via
a template defined in the values.yaml. This allows us to define
multiple datasource types that can be mapped directly to the
corresponding entries in endpoints, which enables us to generate
the data source urls via endpoint lookups rather than hardcoding
this. This is the first step to support multiple data sources in
a singular grafana deployment

Change-Id: Iac7f4b1e07aaf83ae4d2a0c923cd06817f0d8c0d
This commit is contained in:
Steve Wilkerson 2018-06-21 09:56:27 -05:00
parent 82aab87442
commit 68fa1d6fbe
3 changed files with 41 additions and 5 deletions

View File

@ -35,7 +35,7 @@ metadata:
name: grafana-etc
data:
datasources.yaml: |
{{ toYaml .Values.conf.provisioning.datasources | indent 4 }}
{{- include "grafana.utils.generate_datasources" (dict "envAll" $envAll "datasources" .Values.conf.provisioning.datasources) | indent 4 }}
dashboards.yaml: |
{{ toYaml .Values.conf.provisioning.dashboards | indent 4 }}
grafana.ini: |

View File

@ -0,0 +1,35 @@
{{/*
Copyright 2017 The Openstack-Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}
# This function generates the required datasource configuration for grafana.
# This allows us to generate an arbitrary number of datasources for grafana
{{- define "grafana.utils.generate_datasources" -}}
{{- $envAll := index . "envAll" -}}
{{- $datasources := index . "datasources" -}}
{{- $_ := set $envAll.Values "__datasources" ( list ) }}
{{- range $datasource, $config := $datasources -}}
{{- if empty $config.url -}}
{{- $datasource_url := tuple $datasource "internal" "api" $envAll | include "helm-toolkit.endpoints.keystone_endpoint_uri_lookup" }}
{{- $_ := set $config "url" $datasource_url }}
{{- end }}
{{- $__datasources := append $envAll.Values.__datasources $config }}
{{- $_ := set $envAll.Values "__datasources" $__datasources }}
{{- end }}
apiVersion: 1
datasources:
{{ toYaml $envAll.Values.__datasources }}
{{- end -}}

View File

@ -344,14 +344,15 @@ conf:
options:
path: /var/lib/grafana/dashboards
datasources:
apiVersion: 1
datasources:
- name: prometheus
#NOTE(srwilkers): The top key for each datasource (eg: monitoring) must
# map to the key name for the datasource's endpoint entry in the endpoints
# tree
monitoring:
name: prometheus
type: prometheus
access: proxy
orgId: 1
editable: true
url: 'http://prom-metrics.openstack.svc.cluster.local:9090'
grafana:
auth.ldap:
enabled: true