Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add event logging for db and redis connection
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and backportbot[bot] committed Mar 2, 2022
commit fc8b80a44f35dec465f52e000b1258aa4cce8835
12 changes: 11 additions & 1 deletion lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
12 changes: 9 additions & 3 deletions lib/private/RedisFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@
*/
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';

/** @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() {
Expand Down Expand Up @@ -113,6 +117,7 @@ private function create() {
$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`
Expand All @@ -133,6 +138,7 @@ private function create() {
if (isset($config['dbindex'])) {
$this->instance->select($config['dbindex']);
}
$this->eventLogger->end('connect:redis');
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ public function __construct($webRoot, \OC\Config $config) {

$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) {
Expand Down