]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add event logging for db and redis connection 31124/head
authorJulius Härtl <jus@bitgrid.net>
Fri, 25 Feb 2022 15:18:02 +0000 (16:18 +0100)
committerJulius Härtl <jus@bitgrid.net>
Mon, 28 Feb 2022 10:24:41 +0000 (11:24 +0100)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
lib/private/DB/Connection.php
lib/private/RedisFactory.php
lib/private/Server.php

index 2203893d4276314a04a2de4369c4f2d0c9a07024..e32c530c19ef9ca7536617f2886aef1bde7f63eb 100644 (file)
@@ -81,7 +81,17 @@ class Connection extends \Doctrine\DBAL\Connection {
         */
        public function connect() {
                try {
-                       return parent::connect();
+                       if ($this->_conn) {
+                               return parent::connect();
+                       }
+
+                       // Only trigger the event logger for the initial connect call
+                       $eventLogger = \OC::$server->getEventLogger();
+                       $eventLogger->start('connect:db', 'db connection opened');
+                       $status = parent::connect();
+                       $eventLogger->end('connect:db');
+
+                       return $status;
                } catch (Exception $e) {
                        // throw a new exception to prevent leaking info from the stacktrace
                        throw new Exception('Failed to connect to the database: ' . $e->getMessage(), $e->getCode());
index 88d22cf9d1334be87896efb407b7a8288c1cbbf0..5c38ed0807d3b9e18ef0b960c0387a172ba91f9b 100644 (file)
@@ -26,6 +26,8 @@
  */
 namespace OC;
 
+use OCP\Diagnostics\IEventLogger;
+
 class RedisFactory {
        public const REDIS_MINIMAL_VERSION = '3.1.3';
        public const REDIS_EXTRA_PARAMETERS_MINIMAL_VERSION = '5.3.0';
@@ -33,16 +35,18 @@ class RedisFactory {
        /** @var  \Redis|\RedisCluster */
        private $instance;
 
-       /** @var  SystemConfig */
-       private $config;
+       private SystemConfig $config;
+
+       private IEventLogger $eventLogger;
 
        /**
         * RedisFactory constructor.
         *
         * @param SystemConfig $config
         */
-       public function __construct(SystemConfig $config) {
+       public function __construct(SystemConfig $config, IEventLogger $eventLogger) {
                $this->config = $config;
+               $this->eventLogger = $eventLogger;
        }
 
        private function create() {
@@ -113,6 +117,7 @@ class RedisFactory {
                                $port = null;
                        }
 
+                       $this->eventLogger->start('connect:redis', 'Connect to redis and send AUTH, SELECT');
                        // Support for older phpredis versions not supporting connectionParameters
                        if ($connectionParameters !== null) {
                                // Non-clustered redis requires connection parameters to be wrapped inside `stream`
@@ -141,6 +146,7 @@ class RedisFactory {
                        if (isset($config['dbindex'])) {
                                $this->instance->select($config['dbindex']);
                        }
+                       $this->eventLogger->end('connect:redis');
                }
        }
 
index 6619302a020765451d9a6b400f1a0c8a0179169e..ec74857fd20489a607bfcd5e5ecdada5bd950ec6 100644 (file)
@@ -718,7 +718,7 @@ class Server extends ServerContainer implements IServerContainer {
 
                $this->registerService('RedisFactory', function (Server $c) {
                        $systemConfig = $c->get(SystemConfig::class);
-                       return new RedisFactory($systemConfig);
+                       return new RedisFactory($systemConfig, $c->getEventLogger());
                });
 
                $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {