diff --git a/prometheus/templates/_helpers.tpl b/prometheus/templates/_helpers.tpl new file mode 100644 index 000000000..549762388 --- /dev/null +++ b/prometheus/templates/_helpers.tpl @@ -0,0 +1,48 @@ +{{/* +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 command line flags passed to Prometheus at time of +# execution. This allows the Prometheus service configuration to be flexible, as +# the only way to define Prometheus's configuration is via command line flags. +# The yaml definition for these flags uses the full yaml path as the key, and +# replaces underscores with hyphens to match the syntax required for the flags +# generated (This is required due to Go's yaml parsing capabilities). +# For example: +# +# conf: +# prometheus: +# command_line_flags: +# storage.tsdb.max_block_duration: 2h +# +# Will generate the following flag: +# --storage.tsdb.max-block-duration=2h +# +# Prometheus's command flags can be found by either running 'prometheus -h' or +# 'prometheus --help-man' + +{{- define "prometheus.utils.command_line_flags" -}} +{{- range $flag, $value := . }} +{{- $flag := $flag | replace "_" "-" -}} +{{- if eq $flag "web.enable-admin-api" -}} +{{- if $value -}} +{{- printf "--%s" $flag }} +{{- end -}} +{{- else -}} +{{- $value := $value | toString }} +{{- printf "--%s=%s " $flag $value }} +{{- end -}} +{{- end -}} +{{- end -}} diff --git a/prometheus/templates/bin/_prometheus.sh.tpl b/prometheus/templates/bin/_prometheus.sh.tpl index ad0d75c1e..bbdf28038 100644 --- a/prometheus/templates/bin/_prometheus.sh.tpl +++ b/prometheus/templates/bin/_prometheus.sh.tpl @@ -20,18 +20,8 @@ set -ex COMMAND="${@:-start}" function start () { - exec /bin/prometheus \ - --config.file=/etc/config/prometheus.yml \ - --log.level={{ .Values.conf.prometheus.log.level | quote }} \ - --query.max-concurrency={{ .Values.conf.prometheus.query.max_concurrency }} \ - --storage.tsdb.path={{ .Values.conf.prometheus.storage.tsdb.path }} \ - --storage.tsdb.retention={{ .Values.conf.prometheus.storage.tsdb.retention }} \ - --storage.tsdb.min-block-duration={{ .Values.conf.prometheus.storage.tsdb.min_block_duration }} \ - --storage.tsdb.max-block-duration={{ .Values.conf.prometheus.storage.tsdb.max_block_duration }} \ - {{ if .Values.conf.prometheus.web_admin_api.enabled }} - --web.enable-admin-api \ - {{ end }} - --query.timeout={{ .Values.conf.prometheus.query.timeout }} +{{ $flags := include "prometheus.utils.command_line_flags" .Values.conf.prometheus.command_line_flags }} + exec /bin/prometheus --config.file=/etc/config/prometheus.yml {{ $flags }} } function stop () { diff --git a/prometheus/values.yaml b/prometheus/values.yaml index 14e41f894..e31e46933 100644 --- a/prometheus/values.yaml +++ b/prometheus/values.yaml @@ -182,20 +182,17 @@ manifests: conf: prometheus: - storage: - tsdb: - path: /var/lib/prometheus/data - retention: 7d - min_block_duration: 2h - max_block_duration: 6h - log: - format: logger:stdout?json=true - level: info - query: - max_concurrency: 20 - timeout: 2m - web_admin_api: - enabled: false + # Consumed by a prometheus helper function to generate the command line flags + # for configuring the prometheus service + command_line_flags: + log.level: info + query.max_concurrency: 20 + query.timeout: 2m + storage.tsdb.path: /var/lib/prometheus/data + storage.tsdb.retention: 7d + storage.tsdb.min_block_duration: 2h + storage.tsdb.max_block_duration: 2h + web.enable_admin_api: false scrape_configs: global: scrape_interval: 60s