summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2022-02-25 16:18:02 +0100
committerJulius Härtl <jus@bitgrid.net>2022-02-28 11:24:41 +0100
commit83717a7800e8854b3f3ba17608157598d1fe28ca (patch)
treeee7e264c35c991fe182853dbf853b95760cd4fa6 /lib
parentf13c150a560f31ed3e03833b9ed416d8c7c592f4 (diff)
downloadnextcloud-server-83717a7800e8854b3f3ba17608157598d1fe28ca.tar.gz
nextcloud-server-83717a7800e8854b3f3ba17608157598d1fe28ca.zip
Add event logging for db and redis connection
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/Connection.php12
-rw-r--r--lib/private/RedisFactory.php12
-rw-r--r--lib/private/Server.php2
3 files changed, 21 insertions, 5 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 2203893d427..e32c530c19e 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -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());
diff --git a/lib/private/RedisFactory.php b/lib/private/RedisFactory.php
index 88d22cf9d13..5c38ed0807d 100644
--- a/lib/private/RedisFactory.php
+++ b/lib/private/RedisFactory.php
@@ -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');
}
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 6619302a020..ec74857fd20 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -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) {