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

feature(helm): Added template support for config and collector files #642

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: sql-exporter
description: Database-agnostic SQL exporter for Prometheus
type: application
version: 0.10.2
version: 0.11.0
appVersion: 0.17.0
keywords:
- exporter
Expand Down
9 changes: 8 additions & 1 deletion helm/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# sql-exporter

![Version: 0.10.2](https://img.shields.io/badge/Version-0.10.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.17.0](https://img.shields.io/badge/AppVersion-0.17.0-informational?style=flat-square)


![Version: 0.11.0](https://img.shields.io/badge/Version-0.11.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.17.0](https://img.shields.io/badge/AppVersion-0.17.0-informational?style=flat-square)

Database-agnostic SQL exporter for Prometheus

Expand All @@ -14,6 +16,9 @@ Database-agnostic SQL exporter for Prometheus
| ---- | ------ | --- |
| Nikolai Rodionov | <[email protected]> | <https://badhouseplants.net> |




## Installing the Chart

To install the chart with the release name `sql-exporter`:
Expand Down Expand Up @@ -86,6 +91,7 @@ as an example.
| logFormat | string | `"logfmt"` | Set log format (logfmt if unset) |
| reloadEnabled | bool | `false` | Enable reload collector data handler (endpoint /reload) |


### Prometheus ServiceMonitor

| Key | Type | Default | Description |
Expand All @@ -101,6 +107,7 @@ as an example.

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| config | object | `{"global":{"max_connections":3,"max_idle_connections":3,"min_interval":"0s","scrape_error_drop_interval":"0s","scrape_timeout":"10s","scrape_timeout_offset":"500ms"}}` | SQL Exporter configuration, can be a dictionary, or a template yaml string. |
| config.global.scrape_timeout | string | `"10s"` | Scrape timeout |
| config.global.scrape_timeout_offset | string | `"500ms"` | Scrape timeout offset. Must be strictly positive. |
| config.global.scrape_error_drop_interval | string | `"0s"` | Interval between dropping scrape_errors_total metric: by default the metric is persistent. |
Expand Down
5 changes: 3 additions & 2 deletions helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{- $conf := include "sql_exporter.config.yaml" . | fromYaml -}}
------------------------------
Hello there!

{{- if and (not .Values.config.target ) (not .Values.config.jobs)}}
{{- if and (not $conf.target ) (not $conf.jobs)}}
------------------------------

It seems like you haven't configured the target, please check the example here:
Expand All @@ -14,7 +15,7 @@ In case you need to have multiple targets, you can confiure jobs instead, have a

{{- end}}

{{- if and (not .Values.config.collectors) (not .Values.config.collectorFiles)}}
{{- if and (not $conf.collectors) (not $conf.collectorFiles)}}

------------------------------
You need to configure either collectors or collectorFiles (or both), please have a look at the example here:
Expand Down
14 changes: 14 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ Create the name of the service account to use
{{- false | quote -}}
{{- end -}}
{{- end -}}

{{- define "sql_exporter.config.yaml" -}}
{{- $conf := "" -}}
{{- if typeIsLike "string" .Values.config -}}
{{- $conf = (tpl .Values.config .) | fromYaml -}}
{{- else -}}
{{- $conf = .Values.config -}}
{{- end -}}
{{- /*
Do the wired "fromYaml | toYaml" to reformat the config.
Reformat '100s' to 100s for example.
*/ -}}
{{- tpl ($conf | toYaml ) . | fromYaml | toYaml -}}
{{- end -}}
9 changes: 8 additions & 1 deletion helm/templates/configmap.collectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ metadata:
data:
{{- range $k, $v := .Values.collectorFiles }}
{{ $k }}: |-
{{- toYaml $v | nindent 4}}
{{- if typeIsLike "string" $v -}}
{{- $v = (tpl $v $ | fromYaml) -}}
{{- end -}}
{{- /*
Do the wired "fromYaml | toYaml" to reformat the config.
Reformat '100s' to 100s for example.
*/ -}}
{{- tpl (toYaml $v) $ | fromYaml | toYaml | nindent 4}}
{{- end}}
{{- end }}
2 changes: 1 addition & 1 deletion helm/templates/secret.configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ metadata:
type: Opaque
stringData:
sql_exporter.yml: |-
{{- toYaml .Values.config | nindent 4 }}
{{- include "sql_exporter.config.yaml" . | nindent 4 }}
{{- end }}
2 changes: 2 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ logLevel: debug
logFormat: logfmt
# -- Enable reload collector data handler (endpoint /reload)
reloadEnabled: false
# -- SQL Exporter configuration, can be a dictionary, or a template yaml string.
config:
global:
# -- Scrape timeout
Expand Down Expand Up @@ -192,6 +193,7 @@ config:
# - "*.collector.yml"
# ---------------------------------------------------------------------
# -- Collector Files
# (can be dictionaries or yaml string templates)
# ---------------------------------------------------------------------
# -- Collector files are mounted to /etc/sql_exporter/collectors dir
# ---------------------------------------------------------------------
Expand Down
Loading