diff --git a/README.md b/README.md index 159724fe..603a17b3 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ mysqld.username | Username to be used for connecting config.my-cnf | Path to .my.cnf file to read MySQL credentials from. (default: `~/.my.cnf`) log.level | Logging verbosity (default: info) exporter.lock_wait_timeout | Set a lock_wait_timeout (in seconds) on the connection to avoid long metadata locking. (default: 2) +exporter.enable_lock_wait_timeout | Enable the lock_wait_timeout connection parameter. Makes the exporter compatible with older versions of MySQL. (default: true) exporter.log_slow_filter | Add a log_slow_filter to avoid slow query logging of scrapes. NOTE: Not supported by Oracle MySQL. tls.insecure-skip-verify | Ignore tls verification errors. web.config.file | Path to a [web configuration file](#tls-and-basic-authentication) diff --git a/collector/exporter.go b/collector/exporter.go index 4e98ea25..c49b990d 100644 --- a/collector/exporter.go +++ b/collector/exporter.go @@ -46,6 +46,10 @@ var ( "exporter.lock_wait_timeout", "Set a lock_wait_timeout (in seconds) on the connection to avoid long metadata locking.", ).Default("2").Int() + enableExporterLockTimeout = kingpin.Flag( + "exporter.enable_lock_wait_timeout", + "Enable the lock_wait_timeout MySQL connection parameter.", + ).Default("true").Bool() slowLogFilter = kingpin.Flag( "exporter.log_slow_filter", "Add a log_slow_filter to avoid slow query logging of scrapes. NOTE: Not supported by Oracle MySQL.", @@ -87,8 +91,13 @@ type Exporter struct { // New returns a new MySQL exporter for the provided DSN. func New(ctx context.Context, dsn string, scrapers []Scraper, logger *slog.Logger) *Exporter { - // Setup extra params for the DSN, default to having a lock timeout. - dsnParams := []string{fmt.Sprintf(timeoutParam, *exporterLockTimeout)} + // Setup extra params for the DSN + dsnParams := []string{} + + // Only set lock_wait_timeout if it is enabled + if *enableExporterLockTimeout { + dsnParams = append(dsnParams, fmt.Sprintf(timeoutParam, *exporterLockTimeout)) + } if *slowLogFilter { dsnParams = append(dsnParams, sessionSettingsParam)