Bug #113196 MySQL Operator - Metrics provider doesn't take command line arguments
Submitted: 23 Nov 2023 11:49 Modified: 23 Nov 2023 14:16
Reporter: Prasad Kris Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Operator Severity:S3 (Non-critical)
Version:8.2.0-2.1.1 OS:Any
Assigned to: CPU Architecture:Any
Tags: innodb, mysql-operator

[23 Nov 2023 11:49] Prasad Kris
Description:
Greetings,

It looks like there is an issue or bug with the metrics provider. According to the documentation (https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-properties.html#mysql-operator-...), we should be able to pass the exporter command-line arguments as options (InnoDBCluster.spec.metrics.options). I attempted this with the prom/mysqld_exporter image, including the required command-line arguments as options, the metrics: section form the manifest is furnished below.

metrics:
enable: true
image: prom/mysqld-exporter
monitor: true
monitorSpec:
  labels:
    release: prometheus-operator
options:
- --mysqld.address=localhost:3306
- --mysqld.username=metrics

However, it just ignores the operations, resulting in the metrics sidecar crash-looping with the below messages.

ts=2023-11-23T10:07:05.058Z caller=config.go:150 level=error msg="failed to validate config" section=client err="no user specified in section or parent"
ts=2023-11-23T10:07:05.058Z caller=mysqld_exporter.go:225 level=info msg="Error parsing host config" file=.my.cnf err="no configuration found" 

It is because the command line arguments specified in the options: are not being recognized by the sidecar pod, resulting in the sidecar just running the mysql-process as shown below.

k run test --image prom/mysqld-exporter --command sleep infinity        
pod/test created
k exec  test -- mysqld_exporter                              
ts=2023-11-23T11:34:22.610Z caller=config.go:150 level=error msg="failed to validate config" section=client err="no user specified in section or parent"
ts=2023-11-23T11:34:22.610Z caller=mysqld_exporter.go:225 level=info msg="Error parsing host config" file=.my.cnf err="no configuration found"

The labels specified in the monitorSpec are also being ignored, resulting in the creation of a ServiceMonitor object without the mentioned labels.

monitorSpec:
  labels:
    release: prometheus-operator

How to repeat:
Enable metrics with the following parameters on an InnoDB cluster resource.

metrics:
enable: true
image: prom/mysqld-exporter
monitor: true
monitorSpec:
  labels:
    release: prometheus-operator
options:
- --mysqld.address=localhost:3306
- --mysqld.username=metrics

Once applied, the InnoDB pods will enter a crash loop due to issues with the metrics sidecar container. The metrics sidecar will display the following logs:

ts=2023-11-23T10:07:05.058Z caller=config.go:150 level=error msg="failed to validate config" section=client err="no user specified in section or parent"
ts=2023-11-23T10:07:05.058Z caller=mysqld_exporter.go:225 level=info msg="Error parsing host config" file=.my.cnf err="no configuration found" 

Suggested fix:
[23 Nov 2023 14:16] MySQL Verification Team
Thanks for the report