Dynamically generate list of rules files for prometheus

This enables the dynamic generation of the list of rules files for
prometheus, driven by the rules added in the appropriate tree under
.Values.conf.prometheus.rules. This removes the necessity of adding
the file name manually in addition to defining the rules in the
rules tree, which should reduce overhead associated with adding
new rules for prometheus to evaluate

Change-Id: Ib768a252c5ea4f2d099df534c3ffcfb2949d7481
This commit is contained in:
Steve Wilkerson 2018-03-24 12:25:11 -05:00
parent 3c66523aab
commit 616c351fa7
2 changed files with 12 additions and 7 deletions

View File

@ -16,6 +16,18 @@ limitations under the License.
{{- if .Values.manifests.configmap_etc }}
{{- $envAll := . }}
{{- if empty $envAll.Values.conf.prometheus.scrape_configs.rule_files -}}
{{- $_ := set $envAll.Values "__rule_files" ( list ) }}
{{- $rulesKeys := keys $envAll.Values.conf.prometheus.rules -}}
{{- range $rule := $rulesKeys }}
{{- $rulesFile := printf "/etc/config/rules/%s.rules" $rule }}
{{- $__rule_files := append $envAll.Values.__rule_files $rulesFile }}
{{- $_ := set $envAll.Values "__rule_files" $__rule_files }}
{{ end }}
{{- set .Values.conf.prometheus.scrape_configs "rule_files" $envAll.Values.__rule_files | quote | trunc 0 -}}
{{- end -}}
---
apiVersion: v1
kind: ConfigMap

View File

@ -200,13 +200,6 @@ conf:
global:
scrape_interval: 60s
evaluation_interval: 60s
rule_files:
- /etc/config/rules/alertmanager.rules
- /etc/config/rules/etcd3.rules
- /etc/config/rules/kubernetes.rules
- /etc/config/rules/kube_apiserver.rules
- /etc/config/rules/kube_controller_manager.rules
- /etc/config/rules/kubelet.rules
scrape_configs:
- job_name: kubelet
scheme: https