Skip to content

Commit

Permalink
[prometheus-mysql-exporter] Manual credentials specification for mult… (
Browse files Browse the repository at this point in the history
#4485)

* [prometheus-mysql-exporter] Manual credentials specification for multuple targets

Signed-off-by: alit-by <litasov.o@gmail.com>

* [prometheus-mysql-exporter] Fix linting.

Signed-off-by: alit-by <litasov.o@gmail.com>

---------

Signed-off-by: alit-by <litasov.o@gmail.com>
  • Loading branch information
bylit committed Apr 25, 2024
1 parent dff13d5 commit ee961be
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 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:
Expand Down
36 changes: 22 additions & 14 deletions charts/prometheus-mysql-exporter/README.md
Expand Up @@ -43,37 +43,45 @@ 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
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
Expand Down
13 changes: 13 additions & 0 deletions charts/prometheus-mysql-exporter/templates/_helpers.tpl
Expand Up @@ -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
*/}}
Expand Down
3 changes: 3 additions & 0 deletions charts/prometheus-mysql-exporter/templates/secret-config.yaml
Expand Up @@ -25,4 +25,7 @@ stringData:
{{- range $param := .Values.mysql.additionalConfig}}
{{ $param }}
{{- end }}
{{- if .Values.serviceMonitor.multipleTarget.enabled -}}
{{- template "render_mysql_targets" . -}}
{{- end -}}
{{- end }}
7 changes: 5 additions & 2 deletions charts/prometheus-mysql-exporter/values.yaml
Expand Up @@ -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
Expand Down

0 comments on commit ee961be

Please sign in to comment.