Bug #112185 DATA_SOURCE_NAME is not compatible with myqsld-exporter
Submitted: 25 Aug 2023 17:24 Modified: 7 Sep 2023 14:32
Reporter: Brock Alberry Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Operator Severity:S3 (Non-critical)
Version:8.1.0-2.1.0 OS:Any
Assigned to: CPU Architecture:Any

[25 Aug 2023 17:24] Brock Alberry
Description:
Starting with this commit: https://github.com/mysql/mysql-operator/commit/b4ddf425653c9e87678c10fd24ac62c63d17d7a1#di...

DATA_SOURCE_NAME is the only way the operator configs/allows for connectivity to the db for metrics, but this was removed a few months ago in v0.15.0 of the mysqld-exporter: https://github.com/prometheus/mysqld_exporter/releases/tag/v0.15.0

That means only v0.14.0 (and lower) can be used, which is over a year old :(

How to repeat:
this yaml does not work:
  ...
  metrics:
    enable: true
    image: prom/mysqld-exporter # or anything > v0.15.0
    monitor: true

the only way to get it to work is:
  ...
  metrics:
    enable: true
    image: prom/mysqld-exporter:v0.14.0
    monitor: true

Suggested fix:
change the operator so that it mounts the generated /etc/my.cnf in the metrics sidecar, and append the --config.my-cnf="/etc/my.cnf" flag.

bonus points if you allow full metrics sidecar config (ie. allow the user to specify volume mounts, env vars, etc.)
[7 Sep 2023 14:32] MySQL Verification Team
Thanks for the report. I'm not sure if this is a bug or just configuration change but I'll be verifying this and will wait for operator team to decide how to proceed.

thanks
[9 Jan 12:32] Martin Fleurke
The operator already creates a my.cfg file. The only problem is that in that file, it has
socket=unix:///var/run/mysqld/mysql.sock

And this results in log output like:
time=2025-01-09T12:23:14.089Z level=ERROR source=exporter.go:131 msg="Error opening connection to database" err="dial unix unix:///var/run/mysqld/mysql.sock: connect: no such file or directory"

If it is changed to 
socket=/var/run/mysqld/mysql.sock

then it works fine on the 0.15+ versions of the exporter.
[9 Jan 12:39] Martin Fleurke
https://github.com/mysql/mysql-operator/pull/39 fixes this problem.
[10 Jan 19:42] OCA Admin
Contribution submitted via Github - Fix for bug #112185 - metrics collector v0.15.0+ cannot connect to unix socket 
(*) Contribution by Martin Fleurke (Github amfleurke, mysql-operator/pull/39#issuecomment-2582118705): I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: git_patch_2268300270.txt (text/plain), 910 bytes.