Skip to content
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

feat(db): Make dirty query logging available in production #43185

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,15 @@
*/
'loglevel_frontend' => 2,

/**
* Loglevel used by the dirty database query detection. Useful to identify
* potential database bugs in production. Set this to loglevel or higher to
* see dirty queries in the logs.
*
* Defaults to ``0`` (debug)
*/
'loglevel_dirty_database_queries' => 0,

/**
* If you maintain different instances and aggregate the logs, you may want
* to distinguish between them. ``syslog_tag`` can be set per instance
Expand Down
10 changes: 9 additions & 1 deletion lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,15 @@ public function executeQuery(string $sql, array $params = [], $types = [], Query
} else {
// Read to a table that has been written to previously
// While this might not necessarily mean that we did a read after write it is an indication for a code path to check
$this->logger->debug('dirty table reads: ' . $sql, ['tables' => $this->tableDirtyWrites, 'reads' => $tables, 'exception' => new \Exception()]);
$this->logger->log(
(int) ($this->systemConfig->getValue('loglevel_dirty_database_queries', null) ?? 0),
'dirty table reads: ' . $sql,
[
'tables' => $this->tableDirtyWrites,
'reads' => $tables,
'exception' => new \Exception(),
],
);
}

$sql = $this->replaceTablePrefix($sql);
Expand Down
Loading