From ba1eaa2b7926236b23f202f3decc4dc04e65be0a Mon Sep 17 00:00:00 2001 From: diosmosis Date: Tue, 26 Nov 2019 17:01:17 -0800 Subject: [PATCH 1/4] Add a couple more debug statments to Lock class. --- core/Concurrency/Lock.php | 40 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/core/Concurrency/Lock.php b/core/Concurrency/Lock.php index 38818fd1563..7a7de32a371 100644 --- a/core/Concurrency/Lock.php +++ b/core/Concurrency/Lock.php @@ -72,26 +72,32 @@ public function unlock() public function expireLock($ttlInSeconds) { - if ($ttlInSeconds > 0 && $this->lockValue) { - $success = $this->backend->expireIfKeyHasValue($this->lockKey, $this->lockValue, $ttlInSeconds); - if (!$success) { - $value = $this->backend->get($this->lockKey); - $message = sprintf('Failed to expire key %s (%s / %s).', $this->lockKey, $this->lockValue, (string) $value); - - if ($value === false) { - Common::printDebug($message . ' It seems like the key already expired as it no longer exists.'); - } elseif (!empty($value) && $value == $this->lockValue) { - Common::printDebug($message . ' We still have the lock but for some reason it did not expire.'); - } elseif (!empty($value)) { - Common::printDebug($message . ' This lock has been acquired by another process/server.'); - } else { - Common::printDebug($message . ' Failed to expire key.'); + if ($ttlInSeconds > 0) { + if ($this->lockValue) { + $success = $this->backend->expireIfKeyHasValue($this->lockKey, $this->lockValue, $ttlInSeconds); + if (!$success) { + $value = $this->backend->get($this->lockKey); + $message = sprintf('Failed to expire key %s (%s / %s).', $this->lockKey, $this->lockValue, (string)$value); + + if ($value === false) { + Common::printDebug($message . ' It seems like the key already expired as it no longer exists.'); + } elseif (!empty($value) && $value == $this->lockValue) { + Common::printDebug($message . ' We still have the lock but for some reason it did not expire.'); + } elseif (!empty($value)) { + Common::printDebug($message . ' This lock has been acquired by another process/server.'); + } else { + Common::printDebug($message . ' Failed to expire key.'); + } + + return false; } - return false; + return true; + } else { + Common::printDebug('Lock is not acquired, cannot update expiration.'); } - - return true; + } else { + Common::printDebug('Provided TTL ' . $ttlInSeconds . ' is in valid in Lock::expireLock().'); } return false; From 19692b0d4a99c5dc953e2102681685980cb0bd92 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Tue, 26 Nov 2019 17:23:31 -0800 Subject: [PATCH 2/4] Make sure tracker debug works when tracker environment is used in CLI command. --- core/Tracker.php | 4 +++- plugins/Monolog/config/config.php | 3 ++- plugins/Monolog/config/tracker.php | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/Tracker.php b/core/Tracker.php index 3e0cefc4c28..6c95a9ddbe8 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -74,7 +74,9 @@ public function shouldRecordStatistics() public static function loadTrackerEnvironment() { SettingsServer::setIsTrackerApiRequest(); - $GLOBALS['PIWIK_TRACKER_DEBUG'] = self::isDebugEnabled(); + if (empty($GLOBALS['PIWIK_TRACKER_DEBUG'])) { + $GLOBALS['PIWIK_TRACKER_DEBUG'] = self::isDebugEnabled(); + } PluginManager::getInstance()->loadTrackerPlugins(); } diff --git a/plugins/Monolog/config/config.php b/plugins/Monolog/config/config.php index b81fb089c1f..7bb9ec6f0f3 100644 --- a/plugins/Monolog/config/config.php +++ b/plugins/Monolog/config/config.php @@ -43,8 +43,9 @@ if ($writerName === 'screen' && \Piwik\Common::isPhpCliMode() && !defined('PIWIK_TEST_MODE') + && !\Piwik\SettingsServer::isTrackerApiRequest() ) { - continue; // screen writer is only valid for web requests + continue; // screen writer is only valid for web requests (except for tracker CLI requests) } if (isset($classes[$writerName])) { diff --git a/plugins/Monolog/config/tracker.php b/plugins/Monolog/config/tracker.php index bb7820f9f1b..2ba99662a44 100644 --- a/plugins/Monolog/config/tracker.php +++ b/plugins/Monolog/config/tracker.php @@ -10,6 +10,14 @@ function isTrackerDebugEnabled(ContainerInterface $c) return array( + 'ini.log.log_writers' => DI\decorate(function ($previous, ContainerInterface $c) { + if (isTrackerDebugEnabled($c)) { + $previous[] = 'screen'; + $previous = array_unique($previous); + } + return $previous; + }), + 'log.handler.classes' => DI\decorate(function ($previous, ContainerInterface $c) { if (isset($previous['screen']) && isTrackerDebugEnabled($c) From 6ff52ca4044ed8d02252d94e2c56cf66289167e3 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Tue, 26 Nov 2019 17:26:33 -0800 Subject: [PATCH 3/4] Update submodule. --- plugins/QueuedTracking | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/QueuedTracking b/plugins/QueuedTracking index 6c0e28bbd99..1e65dcaaf50 160000 --- a/plugins/QueuedTracking +++ b/plugins/QueuedTracking @@ -1 +1 @@ -Subproject commit 6c0e28bbd99f5d1f6013bccc1c91fe5f0ca66cda +Subproject commit 1e65dcaaf5092afb01903019932bd42439bb7fe2 From e17beabc80ef60c0286345dcd6afd5d69fd92188 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 9 Dec 2019 14:42:41 -0800 Subject: [PATCH 4/4] Only force screen logger in tracker environment when also in CLI mode. --- plugins/Monolog/config/tracker.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/Monolog/config/tracker.php b/plugins/Monolog/config/tracker.php index 2ba99662a44..6b5301441ea 100644 --- a/plugins/Monolog/config/tracker.php +++ b/plugins/Monolog/config/tracker.php @@ -11,7 +11,9 @@ function isTrackerDebugEnabled(ContainerInterface $c) return array( 'ini.log.log_writers' => DI\decorate(function ($previous, ContainerInterface $c) { - if (isTrackerDebugEnabled($c)) { + if (isTrackerDebugEnabled($c) + && \Piwik\Common::isPhpCliMode() + ) { $previous[] = 'screen'; $previous = array_unique($previous); }