From d7ac797083577865c69771492688c511a5bd4ceb Mon Sep 17 00:00:00 2001 From: Remy Mollandin Date: Sun, 3 Sep 2023 16:55:52 +0200 Subject: [PATCH 1/9] [prometheus-mysql-exporter]: multi-target probe support Signed-off-by: Remy Mollandin --- charts/prometheus-mysql-exporter/README.md | 34 +++++++++++++++++++ .../templates/servicemonitor.yaml | 24 +++++++++++++ charts/prometheus-mysql-exporter/values.yaml | 5 +++ 3 files changed, 63 insertions(+) diff --git a/charts/prometheus-mysql-exporter/README.md b/charts/prometheus-mysql-exporter/README.md index 2023ad9642de..7227f3f56c05 100644 --- a/charts/prometheus-mysql-exporter/README.md +++ b/charts/prometheus-mysql-exporter/README.md @@ -41,6 +41,40 @@ _See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documen 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. +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 + port: 3307 +``` + +Config file should have the following entries: + +```cnf +[client] +user=NOT_USED +password=NOT_USED +[client.localhost] +user=localhost_user +password=localhost_password +[client.remote] +user=remote_user +password=remote_password +``` + +The configuration file can be referenced using `mysql.existingConfigSecret`. + ### From 1.x to 2.x mysqld_exporter has been updated to [v0.15.0](https://github.com/prometheus/mysqld_exporter/releases/tag/v0.15.0), removing support for `DATA_SOURCE_NAME`. Configuration for exporter use `--config.my-cnf` with a custom cnf file (secret). diff --git a/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml index dba2bfdd6359..5da3eccb7b51 100644 --- a/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml +++ b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml @@ -30,6 +30,29 @@ spec: {{ toYaml . | trim | indent 4 -}} {{- end }} endpoints: + {{- if .Values.serviceMonitor.multipleTarget }} + {{- range .Values.serviceMonitor.targets }} + - path: /probe + port: {{ $.Values.service.name }} + {{- if $.Values.serviceMonitor.interval }} + interval: {{ $.Values.serviceMonitor.interval }} + {{- end }} + {{- if $.Values.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ $.Values.serviceMonitor.scrapeTimeout }} + {{- end }} + {{- if $.Values.serviceMonitor.metricRelabelings }} + metricRelabelings: {{ toYaml $.Values.serviceMonitor.metricRelabelings | nindent 8 }} + {{- end }} + {{- if $.Values.serviceMonitor.relabelings }} + relabelings: {{ toYaml $.Values.serviceMonitor.relabelings | nindent 8 }} + {{- end }} + params: + target: + - {{ .endpoint }}:{{ .port | default 3306 }} + auth_module: + - client.{{ .name }} + {{- end }} + {{- else }} - path: /metrics port: {{ .Values.service.name }} {{- if .Values.serviceMonitor.interval }} @@ -44,4 +67,5 @@ spec: {{- if .Values.serviceMonitor.relabelings }} relabelings: {{ toYaml .Values.serviceMonitor.relabelings | nindent 8 }} {{- end }} + {{- end }} {{- end }} diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index b0011bf47b18..baaa386b85b6 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -45,6 +45,11 @@ serviceMonitor: metricRelabelings: [] # Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config relabelings: [] + # Enable multi target scraping. + multipleTarget: false + # target connection information with name (required), endpoint (required) and port (optionnal) + # the name must match an entry client.{{ name }} existing in the secret + targets: [] serviceAccount: # Specifies whether a ServiceAccount should be created From d039d96177a26c1343789ed6c52a4a936fcab288 Mon Sep 17 00:00:00 2001 From: Remy Mollandin Date: Sun, 3 Sep 2023 17:09:25 +0200 Subject: [PATCH 2/9] [prometheus-mysql-exporter]: updating value comments for targets structure Signed-off-by: Remy Mollandin --- charts/prometheus-mysql-exporter/values.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index baaa386b85b6..ce92e65ae8e8 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -47,9 +47,14 @@ serviceMonitor: relabelings: [] # Enable multi target scraping. multipleTarget: false + targets: [] # target connection information with name (required), endpoint (required) and port (optionnal) # the name must match an entry client.{{ name }} existing in the secret - targets: [] + # - endpoint: mysql1.dns.local + # name: mysql1 + # port: 3307 + # - endpoint: mysql2.dns.local + # name: mysql2 serviceAccount: # Specifies whether a ServiceAccount should be created From 76fa4ddc78a3c202cc98230f5c5dfaafe3b20820 Mon Sep 17 00:00:00 2001 From: Remy Mollandin Date: Mon, 4 Sep 2023 20:25:28 +0200 Subject: [PATCH 3/9] [prometheus-mysql-exporter]: add default relabeling for multiple target Signed-off-by: Remy Mollandin --- .../templates/servicemonitor.yaml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml index 5da3eccb7b51..be5bbb5d3dc5 100644 --- a/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml +++ b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml @@ -40,9 +40,18 @@ spec: {{- if $.Values.serviceMonitor.scrapeTimeout }} scrapeTimeout: {{ $.Values.serviceMonitor.scrapeTimeout }} {{- end }} - {{- if $.Values.serviceMonitor.metricRelabelings }} - metricRelabelings: {{ toYaml $.Values.serviceMonitor.metricRelabelings | nindent 8 }} - {{- end }} + metricRelabelings: + - action: replace + replacement: {{ .endpoint }} + sourceLabels: [instance] + targetLabel: instance + - action: replace + replacement: {{ .name }} + sourceLabels: [target] + targetLabel: target + {{- if $.Values.serviceMonitor.metricRelabelings -}} + {{ toYaml $.Values.serviceMonitor.metricRelabelings | nindent 8 }} + {{- end }} {{- if $.Values.serviceMonitor.relabelings }} relabelings: {{ toYaml $.Values.serviceMonitor.relabelings | nindent 8 }} {{- end }} From 1f57b64704943b15e3fe7164e491e6bea50d7b49 Mon Sep 17 00:00:00 2001 From: Remy Mollandin Date: Mon, 16 Oct 2023 09:14:49 +0200 Subject: [PATCH 4/9] feat(prometheus-mysql-exporter): modify values structure and now support shared credentials pattern Signed-off-by: Remy Mollandin --- charts/prometheus-mysql-exporter/README.md | 1 + .../templates/servicemonitor.yaml | 9 +++++++-- charts/prometheus-mysql-exporter/values.yaml | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/charts/prometheus-mysql-exporter/README.md b/charts/prometheus-mysql-exporter/README.md index 7227f3f56c05..8eca2387d276 100644 --- a/charts/prometheus-mysql-exporter/README.md +++ b/charts/prometheus-mysql-exporter/README.md @@ -74,6 +74,7 @@ password=remote_password ``` The configuration file can be referenced using `mysql.existingConfigSecret`. +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/servicemonitor.yaml b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml index be5bbb5d3dc5..f241c4c514e2 100644 --- a/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml +++ b/charts/prometheus-mysql-exporter/templates/servicemonitor.yaml @@ -30,8 +30,8 @@ spec: {{ toYaml . | trim | indent 4 -}} {{- end }} endpoints: - {{- if .Values.serviceMonitor.multipleTarget }} - {{- range .Values.serviceMonitor.targets }} + {{- if .Values.serviceMonitor.multipleTarget.enabled }} + {{- range .Values.serviceMonitor.multipleTarget.targets }} - path: /probe port: {{ $.Values.service.name }} {{- if $.Values.serviceMonitor.interval }} @@ -58,8 +58,13 @@ spec: params: target: - {{ .endpoint }}:{{ .port | default 3306 }} + {{- if $.Values.serviceMonitor.multipleTarget.sharedSecret.enabled }} + auth_module: + - client.{{ $.Values.serviceMonitor.multipleTarget.sharedSecret.name }} + {{- else }} auth_module: - client.{{ .name }} + {{- end }} {{- end }} {{- else }} - path: /metrics diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index ce92e65ae8e8..027ea45c364b 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -46,8 +46,9 @@ serviceMonitor: # Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config relabelings: [] # Enable multi target scraping. - multipleTarget: false - targets: [] + multipleTarget: + enabled: false + targets: [] # target connection information with name (required), endpoint (required) and port (optionnal) # the name must match an entry client.{{ name }} existing in the secret # - endpoint: mysql1.dns.local @@ -55,6 +56,10 @@ serviceMonitor: # port: 3307 # - endpoint: mysql2.dns.local # name: mysql2 + # Enable shared credentials for all targets + sharedSecret: + enabled: false + name: "" serviceAccount: # Specifies whether a ServiceAccount should be created From 98441ca92e6a8b74800262bb03b868de26bc21dc Mon Sep 17 00:00:00 2001 From: Remy Mollandin Date: Mon, 16 Oct 2023 09:17:18 +0200 Subject: [PATCH 5/9] [prometheus-mysql-exporter]: modify values comment Signed-off-by: Remy Mollandin --- charts/prometheus-mysql-exporter/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index 027ea45c364b..38b7c45eba7e 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -50,7 +50,7 @@ serviceMonitor: enabled: false targets: [] # target connection information with name (required), endpoint (required) and port (optionnal) - # the name must match an entry client.{{ name }} existing in the secret + # if sharedSecret is not enabled the name must match an entry client.{{ name }} existing in the secret # - endpoint: mysql1.dns.local # name: mysql1 # port: 3307 From 53c32bff6cccd7fc25cee609fa4eb34cc50e52eb Mon Sep 17 00:00:00 2001 From: Remy Mollandin Date: Tue, 17 Oct 2023 17:33:10 +0200 Subject: [PATCH 6/9] chore: bump chart version to 2.2.0 Signed-off-by: Remy Mollandin --- charts/prometheus-mysql-exporter/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/prometheus-mysql-exporter/Chart.yaml b/charts/prometheus-mysql-exporter/Chart.yaml index a8cab66c58a6..fdbb4bba85dd 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.1.0 +version: 2.2.0 home: https://github.com/prometheus/mysqld_exporter appVersion: v0.15.0 sources: From 0d2c32dee5e815f0539449e09a3bbdc08afb4074 Mon Sep 17 00:00:00 2001 From: Remy Mollandin Date: Tue, 17 Oct 2023 17:33:35 +0200 Subject: [PATCH 7/9] docs: indent targets doc string Signed-off-by: Remy Mollandin --- charts/prometheus-mysql-exporter/values.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index 38b7c45eba7e..86369eb18567 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -49,13 +49,13 @@ 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 - # - endpoint: mysql1.dns.local - # name: mysql1 - # port: 3307 - # - endpoint: mysql2.dns.local - # name: mysql2 + # 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 + # - endpoint: mysql1.dns.local + # name: mysql1 + # port: 3307 + # - endpoint: mysql2.dns.local + # name: mysql2 # Enable shared credentials for all targets sharedSecret: enabled: false From 583ba0576f4328796f8ecb594b6f385350e984d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Tue, 17 Oct 2023 18:02:05 +0200 Subject: [PATCH 8/9] Update charts/prometheus-mysql-exporter/values.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Bauer --- charts/prometheus-mysql-exporter/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index 86369eb18567..b7ab57a1cce4 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -56,7 +56,7 @@ serviceMonitor: # port: 3307 # - endpoint: mysql2.dns.local # name: mysql2 - # Enable shared credentials for all targets + # Enable shared credentials for all targets sharedSecret: enabled: false name: "" From d3a9b54dae12a981f8e0a2aadbfc98776e3fde3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Tue, 17 Oct 2023 18:03:23 +0200 Subject: [PATCH 9/9] Update charts/prometheus-mysql-exporter/values.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Bauer --- charts/prometheus-mysql-exporter/values.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/charts/prometheus-mysql-exporter/values.yaml b/charts/prometheus-mysql-exporter/values.yaml index b7ab57a1cce4..a9eb18074489 100644 --- a/charts/prometheus-mysql-exporter/values.yaml +++ b/charts/prometheus-mysql-exporter/values.yaml @@ -49,13 +49,13 @@ 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 - # - endpoint: mysql1.dns.local - # name: mysql1 - # port: 3307 - # - endpoint: mysql2.dns.local - # name: mysql2 + # 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 + # - endpoint: mysql1.dns.local + # name: mysql1 + # port: 3307 + # - endpoint: mysql2.dns.local + # name: mysql2 # Enable shared credentials for all targets sharedSecret: enabled: false