From 7027c3d1ff636910d7bfce23c450a18c2d510d5e Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Mon, 24 Aug 2020 11:40:47 -0500 Subject: [PATCH 1/6] Logging improvements --- Model/Cache/InvalidateLogger.php | 61 ++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/Model/Cache/InvalidateLogger.php b/Model/Cache/InvalidateLogger.php index a23c9a4..f2a0f1b 100644 --- a/Model/Cache/InvalidateLogger.php +++ b/Model/Cache/InvalidateLogger.php @@ -13,6 +13,43 @@ */ class InvalidateLogger extends \Magento\Framework\Cache\InvalidateLogger { + private $tagsToLog = [ + 'cat_p', + 'cat_c', + 'PRODUCT_PRICE', + 'cms_b', + 'cms_p', + 'config_scopes', + 'eav', + 'eav_attribute', + 'fpc', + 'review_block', + 'SEARCH_QUERY', + 'search_query', + 'store_group', + 'store', + 'store_relations', + 'website', + 'CORE_DESIGN', + 'core_design', + 'WEBSERVICE', + 'webservice', + 'banner', + 'catalog_event', + 'config', + 'block_html', + 'COLLECTION_DATA', + 'collection_data', + 'collections', + 'layout_general_cache_tag', + 'layout', + 'compiled_config', + 'acl_cache', + 'reflection', + 'db_ddl', + 'all' + ]; + /** * Log cache invalidation to a file * @@ -20,13 +57,23 @@ class InvalidateLogger extends \Magento\Framework\Cache\InvalidateLogger */ public function execute($invalidateInfo) { - if (is_array($invalidateInfo)) { - $invalidateInfo['trace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - } elseif (is_string($invalidateInfo)) { - $invalidateInfo = [ - 'main' => $invalidateInfo, - 'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) - ]; + if (is_array($invalidateInfo) && isset($invalidateInfo['tags'])) { + foreach ($invalidateInfo['tags'] as $tag) { + if (in_array(strtolower($tag), $this->tagsToLog)) { + if (function_exists('gzcompress')) { + $invalidateInfo['trace'] = bin2hex( + gzcompress( + print_r( + debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), + true + ) + ) + ); + } else { + $invalidateInfo['trace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + } + } + } } parent::execute($invalidateInfo); From d0c524793f880345e8ebec3997e13e1f7827d956 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Mon, 24 Aug 2020 15:31:48 -0500 Subject: [PATCH 2/6] Logging improvements --- Model/Cache/InvalidateLogger.php | 46 +++++++++++++----- Model/DebugTrace.php | 81 ++++++++++++++++++++++++++++++++ Model/Indexation/Logger.php | 16 +++++-- 3 files changed, 127 insertions(+), 16 deletions(-) create mode 100644 Model/DebugTrace.php diff --git a/Model/Cache/InvalidateLogger.php b/Model/Cache/InvalidateLogger.php index f2a0f1b..090683c 100644 --- a/Model/Cache/InvalidateLogger.php +++ b/Model/Cache/InvalidateLogger.php @@ -8,11 +8,18 @@ namespace Magento\CloudComponents\Model\Cache; +use Magento\Framework\App\Request\Http as HttpRequest; +use Psr\Log\LoggerInterface as Logger; +use Magento\CloudComponents\Model\DebugTrace; + /** * Log cache invalidation to a file */ class InvalidateLogger extends \Magento\Framework\Cache\InvalidateLogger { + /** + * @var string[] + */ private $tagsToLog = [ 'cat_p', 'cat_c', @@ -50,6 +57,26 @@ class InvalidateLogger extends \Magento\Framework\Cache\InvalidateLogger 'all' ]; + /** + * @var DebugTrace + */ + private $debugTrace; + + /** + * @param HttpRequest $request + * @param Logger $logger + * @param DebugTrace $debugTrace + */ + public function __construct( + HttpRequest $request, + Logger $logger, + DebugTrace $debugTrace + ) { + parent::__construct($request, $logger); + $this->debugTrace = $debugTrace; + } + + /** * Log cache invalidation to a file * @@ -57,25 +84,18 @@ class InvalidateLogger extends \Magento\Framework\Cache\InvalidateLogger */ public function execute($invalidateInfo) { + $needTrace = false; if (is_array($invalidateInfo) && isset($invalidateInfo['tags'])) { foreach ($invalidateInfo['tags'] as $tag) { if (in_array(strtolower($tag), $this->tagsToLog)) { - if (function_exists('gzcompress')) { - $invalidateInfo['trace'] = bin2hex( - gzcompress( - print_r( - debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), - true - ) - ) - ); - } else { - $invalidateInfo['trace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - } + $needTrace = true; } } - } + if ($needTrace) { + $invalidateInfo['trace'] = $this->debugTrace->getTrace(); + } + } parent::execute($invalidateInfo); } } diff --git a/Model/DebugTrace.php b/Model/DebugTrace.php new file mode 100644 index 0000000..7bee74f --- /dev/null +++ b/Model/DebugTrace.php @@ -0,0 +1,81 @@ + $line) { + if (in_array($line['function'], $this->notAllowedFunctions) + || in_array($line['class'], $this->notAllowedClasses) + || strpos($line['file'], 'Interceptor.php') !== false + ) { + unset($trace[$index]); + } + unset($trace[$index]['type']); + } + + if (function_exists('gzcompress')) { + return bin2hex( + gzcompress( + print_r( + $trace, + true + ) + ) + ); + } + return $trace; + } +} diff --git a/Model/Indexation/Logger.php b/Model/Indexation/Logger.php index e43f43a..a200c9b 100644 --- a/Model/Indexation/Logger.php +++ b/Model/Indexation/Logger.php @@ -8,6 +8,7 @@ namespace Magento\CloudComponents\Model\Indexation; +use Magento\CloudComponents\Model\DebugTrace; use Magento\Framework\Indexer\ActionInterface; use Psr\Log\LoggerInterface; @@ -21,12 +22,21 @@ class Logger */ private $logger; + /** + * @var DebugTrace + */ + private $debugTrace; + /** * @param LoggerInterface $logger + * @param DebugTrace $debugTrace */ - public function __construct(LoggerInterface $logger) - { + public function __construct( + LoggerInterface $logger, + DebugTrace $debugTrace + ) { $this->logger = $logger; + $this->debugTrace = $debugTrace; } /** @@ -39,7 +49,7 @@ public function afterExecuteFull(ActionInterface $subject) $this->logger->debug( 'full_indexation: ' . get_class($subject), [ - 'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) + 'trace' => $this->debugTrace->getTrace() ] ); } From 2b4dbcf22ddadc81c264cc109fb8588665d79ae1 Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Tue, 25 Aug 2020 11:07:52 -0500 Subject: [PATCH 3/6] test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f6d91e4..88ba1ca 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +# TEST MESSAGE # Magento Cloud Components The Magento Cloud Components module extends Magento Commerce core functionality for sites deployed on the Cloud platform. This module contains cloud-specific functionality for use with the [ece-tools](https://github.com/magento/ece-tools) package. From 66d66fc970191baa2e6d71a32c76cc1dc4ea6950 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Tue, 25 Aug 2020 11:55:17 -0500 Subject: [PATCH 4/6] Logging improvements --- Model/Cache/InvalidateLogger.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Model/Cache/InvalidateLogger.php b/Model/Cache/InvalidateLogger.php index 090683c..6b3e769 100644 --- a/Model/Cache/InvalidateLogger.php +++ b/Model/Cache/InvalidateLogger.php @@ -76,7 +76,6 @@ public function __construct( $this->debugTrace = $debugTrace; } - /** * Log cache invalidation to a file * From 9660819329e06e65eec4b884098f90a088a8d67c Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Wed, 26 Aug 2020 11:05:34 -0500 Subject: [PATCH 5/6] Logging improvements --- Model/DebugTrace.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Model/DebugTrace.php b/Model/DebugTrace.php index 7bee74f..184a254 100644 --- a/Model/DebugTrace.php +++ b/Model/DebugTrace.php @@ -3,6 +3,9 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + +declare(strict_types=1); + namespace Magento\CloudComponents\Model; /** From d1f1bb3ea37ce0edd020342371ed9191c898f275 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Fri, 28 Aug 2020 14:56:01 -0500 Subject: [PATCH 6/6] Logging improvements --- Model/DebugTrace.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Model/DebugTrace.php b/Model/DebugTrace.php index 184a254..043ae17 100644 --- a/Model/DebugTrace.php +++ b/Model/DebugTrace.php @@ -60,6 +60,9 @@ public function getTrace() { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); foreach ($trace as $index => $line) { + if (!isset($line['function'], $line['class'], $line['file'])) { + continue; + } if (in_array($line['function'], $this->notAllowedFunctions) || in_array($line['class'], $this->notAllowedClasses) || strpos($line['file'], 'Interceptor.php') !== false