]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(db): Increase log level for very slow transactions 47528/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Tue, 27 Aug 2024 08:03:35 +0000 (10:03 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 27 Aug 2024 13:24:08 +0000 (13:24 +0000)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
lib/private/DB/Connection.php

index 3cdd5fd06c01b99cb158769d9d498422fd7f9035..ef12171e0a52879533b6723a56861a3b0fbd4cdd 100644 (file)
@@ -28,6 +28,7 @@ use OC\SystemConfig;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\Diagnostics\IEventLogger;
 use OCP\IDBConnection;
+use OCP\ILogger;
 use OCP\IRequestId;
 use OCP\PreConditionNotMetException;
 use OCP\Profiler\IProfiler;
@@ -719,7 +720,20 @@ class Connection extends PrimaryReadReplicaConnection {
                        $this->transactionBacktrace = null;
                        $this->transactionActiveSince = null;
                        if ($timeTook > 1) {
-                               $this->logger->debug('Transaction took ' . $timeTook . 's', ['exception' => new \Exception('Transaction took ' . $timeTook . 's')]);
+                               $logLevel = match (true) {
+                                       $timeTook > 20 * 60 => ILogger::ERROR,
+                                       $timeTook > 5 * 60 => ILogger::WARN,
+                                       $timeTook > 10 => ILogger::INFO,
+                                       default => ILogger::DEBUG,
+                               };
+                               $this->logger->log(
+                                       $logLevel,
+                                       'Transaction took ' . $timeTook . 's',
+                                       [
+                                               'exception' => new \Exception('Transaction took ' . $timeTook . 's'),
+                                               'timeSpent' => $timeTook,
+                                       ]
+                               );
                        }
                }
                return $result;
@@ -732,7 +746,20 @@ class Connection extends PrimaryReadReplicaConnection {
                        $this->transactionBacktrace = null;
                        $this->transactionActiveSince = null;
                        if ($timeTook > 1) {
-                               $this->logger->debug('Transaction rollback took longer than 1s: ' . $timeTook, ['exception' => new \Exception('Long running transaction rollback')]);
+                               $logLevel = match (true) {
+                                       $timeTook > 20 * 60 => ILogger::ERROR,
+                                       $timeTook > 5 * 60 => ILogger::WARN,
+                                       $timeTook > 10 => ILogger::INFO,
+                                       default => ILogger::DEBUG,
+                               };
+                               $this->logger->log(
+                                       $logLevel,
+                                       'Transaction rollback took longer than 1s: ' . $timeTook,
+                                       [
+                                               'exception' => new \Exception('Long running transaction rollback'),
+                                               'timeSpent' => $timeTook,
+                                       ]
+                               );
                        }
                }
                return $result;