diff --git a/charts/prometheus-mysql-exporter/Chart.yaml b/charts/prometheus-mysql-exporter/Chart.yaml index 26f350bfa53..91e94e40d9d 100644 --- a/charts/prometheus-mysql-exporter/Chart.yaml +++ b/charts/prometheus-mysql-exporter/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 description: A Helm chart for prometheus mysql exporter with cloudsqlproxy name: prometheus-mysql-exporter -version: 2.5.1 +version: 2.5.2 home: https://github.com/prometheus/mysqld_exporter appVersion: v0.15.1 sources: diff --git a/charts/prometheus-mysql-exporter/README.md b/charts/prometheus-mysql-exporter/README.md index 8eca2387d27..1cc4a2792b1 100644 --- a/charts/prometheus-mysql-exporter/README.md +++ b/charts/prometheus-mysql-exporter/README.md @@ -43,8 +43,8 @@ helm upgrade [RELEASE_NAME] [CHART] --install ### Multiple-target probes -mysql_exporter now support multi-target probes using the `/probe` route. To enable this feature, set `serviecMonitor.multipleTarget.enabled` to `true` and define your targets in `serviceMonitor.multipleTarget.targets`. -Credentials for each target should be referenced in the associate config file. Target name should match the entry in the config file. +mysql_exporter now support multi-target probes using the `/probe` route. To enable this feature, set `serviceMonitor.multipleTarget.enabled` to `true` and define your targets in `serviceMonitor.multipleTarget.targets`. +Credentials for each target should be referenced either in targets section or in the associated config file. As an example, for a config file with two targets: ```yaml @@ -52,28 +52,36 @@ serviceMonitor: multipleTarget: enabled: true targets: - - name: localhost - endpoint: 127.0.0.1 - - name: remote - endpoint: 8.8.8.8 + - endpoint: mysql1.dns.local + name: mysql1 port: 3307 + user: user1 + password: password1 + - endpoint: mysql2.dns.local + name: mysql2 + user: user2 + password: password2 ``` -Config file should have the following entries: +In case of Config file Target name should match the entry in the config file. +Config file example for the above targets: ```cnf [client] user=NOT_USED password=NOT_USED -[client.localhost] -user=localhost_user -password=localhost_password -[client.remote] -user=remote_user -password=remote_password +[client.mysql1] +user=user1 +password=password1 +[client.mysql2] +user=user2 +password=password2 ``` -The configuration file can be referenced using `mysql.existingConfigSecret`. +The configuration file can be: + +- referenced using `mysql.existingConfigSecret`; +- created automatically in case user and password are specified for the target. If all your target use the same credentials, you can set `serviceMonitor.sharedSecret.enabled` to `true` and define the key name in `serviceMonitor.sharedSecret.name`. ### From 1.x to 2.x diff --git a/charts/prometheus-mysql-exporter/templates/_helpers.tpl b/charts/prometheus-mysql-exporter/templates/_helpers.tpl index 1428208b4bc..1f369c08196 100644 --- a/charts/prometheus-mysql-exporter/templates/_helpers.tpl +++ b/charts/prometheus-mysql-exporter/templates/_helpers.tpl @@ -91,6 +91,19 @@ Secret key for config {{- end -}} */}} +{{/* Define a function to iterate over multi scraping targets */}} +{{- define "render_mysql_targets" -}} + {{- if and (.Values.serviceMonitor.multipleTarget.targets) (not .Values.serviceMonitor.multipleTarget.sharedSecret.enabled) -}} + {{- range .Values.serviceMonitor.multipleTarget.targets }} + {{- if and (.user) (.password) }} + [client.{{ .name }}] + user={{ .user }} + password={{ .password }} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} + {{/* Define overriding namespace */}} diff --git a/charts/prometheus-mysql-exporter/templates/secret-config.yaml b/charts/prometheus-mysql-exporter/templates/secret-config.yaml index 2a0528e8c8f..28a5cf12e4c 100644 --- a/charts/prometheus-mysql-exporter/templates/secret-config.yaml +++ b/charts/prometheus-mysql-exporter/templates/secret-config.yaml @@ -25,4 +25,7 @@ stringData: {{- range $param := .Values.mysql.additionalConfig}} {{ $param }} {{- end }} + {{- if .Values.serviceMonitor.multipleTarget.enabled -}} + {{- template "render_mysql_targets" . -}} + {{- end -}} {{- end }} diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index 1c9b7daac1a..47768d0eb1b 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -50,13 +50,16 @@ serviceMonitor: multipleTarget: enabled: false targets: [] - # target connection information with name (required), endpoint (required) and port (optionnal) - # if sharedSecret is not enabled the name must match an entry client.{{ name }} existing in the secret + # target connection information with name (required), endpoint (required), port (optional), user(optional), password(optional) # - endpoint: mysql1.dns.local # name: mysql1 # port: 3307 + # user: user1 + # password: password1 # - endpoint: mysql2.dns.local # name: mysql2 + # user: user2 + # password: password2 # Enable shared credentials for all targets sharedSecret: enabled: false