Skip to content

Commit

Permalink
feat(helm): Added template support for config and collector files (#642)
Browse files Browse the repository at this point in the history
* Added the option to get the collector files from templates.

* Fixed typo.

* Added the option to use tpl in the sql exporter config.

* Created function to generate the config dict.

* Added and fixed the comment about the toYaml fromYaml stuff.

* Added docs on the config dict.

* Updated the docs.

* Bumped the version.

* Added newline at the values file.

* Updated the chart's version from patch to minor.

* Removed .Files reference.

* Made the config parameter optional.

* Updated the readme.

* Removed the this parameter is optional hint.

* Removed the optional hint from the actual docs.

* Updated the values for the dict.
  • Loading branch information
Avihais12344 authored Jan 1, 2025
1 parent c33a446 commit 2659a60
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
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 | <allanger@zohomail.com> | <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

0 comments on commit 2659a60

Please sign in to comment.