Skip to content

Add command line option to explicitly disable lock_wait_timeout (adds possibility to opt out of breaking changes with older versions) #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions collector/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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 not disabled
if !*disableExporterLockTimeout {
dsnParams = append(dsnParams, fmt.Sprintf(timeoutParam, *exporterLockTimeout))
}

if *slowLogFilter {
dsnParams = append(dsnParams, sessionSettingsParam)
Expand Down