From c41224a3205018b11f9088d86f6c9ff229ac60a7 Mon Sep 17 00:00:00 2001 From: Francisco Esteveira Date: Thu, 21 Nov 2024 19:07:48 +0000 Subject: [PATCH 1/5] Set lock_wait_timeout option only if positive Signed-off-by: Francisco Esteveira --- collector/exporter.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/collector/exporter.go b/collector/exporter.go index 4e98ea25..7a4c173c 100644 --- a/collector/exporter.go +++ b/collector/exporter.go @@ -87,9 +87,14 @@ 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 positive + if (*exporterLockTimeout >= 0) { + dsnParams = append(dsnParams, fmt.Sprintf(timeoutParam, *exporterLockTimeout)) + } + if *slowLogFilter { dsnParams = append(dsnParams, sessionSettingsParam) } From 141cba1b5a655370dfbd13e5fd55df5e20fee17b Mon Sep 17 00:00:00 2001 From: Francisco Esteveira Date: Thu, 21 Nov 2024 19:13:09 +0000 Subject: [PATCH 2/5] Fix CI test failures Signed-off-by: Francisco Esteveira --- collector/exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/exporter.go b/collector/exporter.go index 7a4c173c..597983ce 100644 --- a/collector/exporter.go +++ b/collector/exporter.go @@ -91,7 +91,7 @@ func New(ctx context.Context, dsn string, scrapers []Scraper, logger *slog.Logge dsnParams := []string{} // Only set lock_wait_timeout if it is positive - if (*exporterLockTimeout >= 0) { + if *exporterLockTimeout >= 0 { dsnParams = append(dsnParams, fmt.Sprintf(timeoutParam, *exporterLockTimeout)) } From 3ced62e1da0f644eb160dbca2bba5d4eebcc7c98 Mon Sep 17 00:00:00 2001 From: Francisco Esteveira Date: Thu, 21 Nov 2024 19:14:08 +0000 Subject: [PATCH 3/5] Fix CI test failures Signed-off-by: Francisco Esteveira --- collector/exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/exporter.go b/collector/exporter.go index 597983ce..94b2e50d 100644 --- a/collector/exporter.go +++ b/collector/exporter.go @@ -94,7 +94,7 @@ func New(ctx context.Context, dsn string, scrapers []Scraper, logger *slog.Logge if *exporterLockTimeout >= 0 { dsnParams = append(dsnParams, fmt.Sprintf(timeoutParam, *exporterLockTimeout)) } - + if *slowLogFilter { dsnParams = append(dsnParams, sessionSettingsParam) } From f547a131f64c5f35976e39f61e4e2c4f4cfc4f48 Mon Sep 17 00:00:00 2001 From: Francisco Esteveira Date: Thu, 20 Feb 2025 14:28:35 +0000 Subject: [PATCH 4/5] Add command line option to explicitly disable lock_wait_timeout Signed-off-by: Francisco Esteveira --- README.md | 1 + collector/exporter.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 159724fe..1c3da4b5 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.disable_lock_wait_timeout | Disable the lock_wait_timeout connection parameter. Makes the exporter compatible with older versions of MySQL. (default: false) 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 94b2e50d..6f1fd505 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() + disableExporterLockTimeout = kingpin.Flag( + "exporter.disable_lock_wait_timeout", + "Disable the lock_wait_timeout MySQL connection parameter.", + ).Default("false").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.", @@ -90,8 +94,8 @@ func New(ctx context.Context, dsn string, scrapers []Scraper, logger *slog.Logge // Setup extra params for the DSN dsnParams := []string{} - // Only set lock_wait_timeout if it is positive - if *exporterLockTimeout >= 0 { + // Only set lock_wait_timeout if it is not disabled + if !*disableExporterLockTimeout { dsnParams = append(dsnParams, fmt.Sprintf(timeoutParam, *exporterLockTimeout)) } From 8d4b01c7c18d13483482df8eac1141cf29d55ffc Mon Sep 17 00:00:00 2001 From: Francisco Esteveira Date: Fri, 21 Feb 2025 15:44:45 +0000 Subject: [PATCH 5/5] Change from flag from disable to enable defaulting to true Signed-off-by: Francisco Esteveira --- README.md | 2 +- collector/exporter.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1c3da4b5..603a17b3 100644 --- a/README.md +++ b/README.md @@ -145,7 +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.disable_lock_wait_timeout | Disable the lock_wait_timeout connection parameter. Makes the exporter compatible with older versions of MySQL. (default: false) +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 6f1fd505..c49b990d 100644 --- a/collector/exporter.go +++ b/collector/exporter.go @@ -46,10 +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() - disableExporterLockTimeout = kingpin.Flag( - "exporter.disable_lock_wait_timeout", - "Disable the lock_wait_timeout MySQL connection parameter.", - ).Default("false").Bool() + 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.", @@ -94,8 +94,8 @@ func New(ctx context.Context, dsn string, scrapers []Scraper, logger *slog.Logge // Setup extra params for the DSN dsnParams := []string{} - // Only set lock_wait_timeout if it is not disabled - if !*disableExporterLockTimeout { + // Only set lock_wait_timeout if it is enabled + if *enableExporterLockTimeout { dsnParams = append(dsnParams, fmt.Sprintf(timeoutParam, *exporterLockTimeout)) }