Skip to content

Commit

Permalink
Merge pull request #42 from magento/develop-fwd
Browse files Browse the repository at this point in the history
Forward-port develop branch
  • Loading branch information
shiftedreality authored Sep 3, 2020
2 parents e03afe2 + 46a2b55 commit 86fc24f
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 34 deletions.
22 changes: 15 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ services:
- docker

language: php
php:
- '7.1'
- '7.2'
- '7.3'

env:
- TEST_SUITE=functional

stages:
- static-unit
Expand All @@ -38,6 +31,21 @@ jobs:
php: '7.3'
env:
- TEST_SUITE=static-unit
- stage: test
php: '7.1'
env:
- TEST_SUITE=functional
- php: '7.2'
env:
- TEST_SUITE=functional
- php: '7.3'
env:
- TEST_SUITE=functional
- php: '7.4'
dist: bionic
env:
- TEST_SUITE=functional


install:
- composer config github-oauth.github.com ${GITHUB_TOKEN}
Expand Down
6 changes: 3 additions & 3 deletions Model/Cache/Evictor.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public function evict(): int
}

$dbKeys = $this->run(
$cacheConfig['backend_options']['server'],
$cacheConfig['backend_options']['port'],
$cacheConfig['backend_options']['database']
(string)$cacheConfig['backend_options']['server'],
(int)$cacheConfig['backend_options']['port'],
(int)$cacheConfig['backend_options']['database']
);
$evictedKeys += $dbKeys;

Expand Down
82 changes: 74 additions & 8 deletions Model/Cache/InvalidateLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,93 @@

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',
'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'
];

/**
* @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
*
* @param mixed $invalidateInfo
*/
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)
];
}
$needTrace = false;
if (is_array($invalidateInfo) && isset($invalidateInfo['tags'])) {
foreach ($invalidateInfo['tags'] as $tag) {
if (in_array(strtolower($tag), $this->tagsToLog)) {
$needTrace = true;
}
}

if ($needTrace) {
$invalidateInfo['trace'] = $this->debugTrace->getTrace();
}
}
parent::execute($invalidateInfo);
}
}
87 changes: 87 additions & 0 deletions Model/DebugTrace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CloudComponents\Model;

/**
* Class to get compressed debug back trace
*/
class DebugTrace
{
/**
* List of useless classes
*
* @var string[]
*/
private $notAllowedClasses = [
'Symfony\Component\Console\Application',
'Magento\Framework\Console\Cli',
'Symfony\Component\Console\Command\Command',
'Magento\Staging\Model\Event\Manager\Proxy',
'Magento\Staging\Model\Event\Manager',
'Magento\Framework\Event\Invoker\InvokerDefault',
'Magento\CloudComponents\Model\Observer\CacheFlushAll',
'Magento\CloudComponents\Model\Cache\InvalidateLogger',
'Magento\CloudComponents\Model\Cache\InvalidateLogger',
'Magento\CloudComponents\Model\Indexation\Logger',
'Magento\Framework\Cache\Frontend\Decorator\Logger',
'Magento\Framework\Cache\Frontend\Decorator\Bare',
'Magento\Framework\App\Cache\Type\AccessProxy',
'Magento\Framework\Cache\Frontend\Decorator\TagScope',
'Magento\Framework\ObjectManager\ObjectManager',
'Magento\Framework\ObjectManager\Config\Compiled',
'Magento\Framework\ObjectManager\Config\Config',
'Magento\Framework\ObjectManager\Factory\Dynamic\Developer',
'Magento\Framework\ObjectManager\Factory\Dynamic\Production'
];

/**
* List of useless functions
*
* @var string[]
*/
private $notAllowedFunctions = [
'___callPlugins',
'___callParent',
'Magento\Framework\Interception\{closure}'
];

/**
* Returns debug back trace
*
* @return array
*/
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
) {
unset($trace[$index]);
}
unset($trace[$index]['type']);
}

if (function_exists('gzcompress')) {
return bin2hex(
gzcompress(
print_r(
$trace,
true
)
)
);
}
return $trace;
}
}
16 changes: 13 additions & 3 deletions Model/Indexation/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magento\CloudComponents\Model\Indexation;

use Magento\CloudComponents\Model\DebugTrace;
use Magento\Framework\Indexer\ActionInterface;
use Psr\Log\LoggerInterface;

Expand All @@ -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;
}

/**
Expand All @@ -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()
]
);
}
Expand Down
25 changes: 25 additions & 0 deletions Test/Functional/Acceptance/Acceptance73Cest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CloudComponents\Test\Functional\Acceptance;

/**
* @group php73
*/
class Acceptance73Cest extends AcceptanceCest
{
/**
* @return array
*/
protected function patchesDataProvider(): array
{
return [
['magentoVersion' => '2.3.3'],
['magentoVersion' => '2.3.5'],
];
}
}
25 changes: 14 additions & 11 deletions Test/Functional/Acceptance/AcceptanceCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Magento\CloudComponents\Test\Functional\Acceptance;

/**
* @group php73
* @group php74
*/
class AcceptanceCest
{
Expand Down Expand Up @@ -49,7 +49,7 @@ protected function prepareTemplate(\CliTester $I, string $magentoVersion): void
public function testPatches(\CliTester $I, \Codeception\Example $data): void
{
$this->prepareTemplate($I, $data['magentoVersion']);
$this->removeESIfExists($I);
$this->removeESIfExists($I, $data['magentoVersion']);
$I->runEceDockerCommand('build:compose --mode=production');
$I->runDockerComposeCommand('run build cloud-build');
$I->startEnvironment();
Expand All @@ -62,18 +62,21 @@ public function testPatches(\CliTester $I, \Codeception\Example $data): void

/**
* @param \CliTester $I
* @param string $magentoVersion
*/
protected function removeESIfExists(\CliTester $I): void
protected function removeESIfExists(\CliTester $I, string $magentoVersion): void
{
$services = $I->readServicesYaml();
if ($magentoVersion !== 'master' && version_compare($magentoVersion, '2.4.0', '<')) {
$services = $I->readServicesYaml();

if (isset($services['elasticsearch'])) {
unset($services['elasticsearch']);
$I->writeServicesYaml($services);
if (isset($services['elasticsearch'])) {
unset($services['elasticsearch']);
$I->writeServicesYaml($services);

$app = $I->readAppMagentoYaml();
unset($app['relationships']['elasticsearch']);
$I->writeAppMagentoYaml($app);
$app = $I->readAppMagentoYaml();
unset($app['relationships']['elasticsearch']);
$I->writeAppMagentoYaml($app);
}
}
}

Expand All @@ -83,7 +86,7 @@ protected function removeESIfExists(\CliTester $I): void
protected function patchesDataProvider(): array
{
return [
['magentoVersion' => '2.3.3'],
['magentoVersion' => '2.4.0'],
['magentoVersion' => 'master'],
];
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magento/magento-cloud-components",
"description": "Cloud Components Module for Magento 2.x",
"type": "magento2-module",
"version": "1.0.6",
"version": "1.0.7",
"require": {
"php": "^7.0",
"ext-json": "*",
Expand All @@ -19,7 +19,7 @@
"consolidation/robo": "^1.2",
"phpmd/phpmd": "@stable",
"phpstan/phpstan": "^0.11",
"phpunit/phpunit": "^6.2",
"phpunit/phpunit": "^7.2",
"squizlabs/php_codesniffer": "^3.0"
},
"config": {
Expand Down
3 changes: 3 additions & 0 deletions tests/travis/functional.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ case $TRAVIS_PHP_VERSION in
7.3)
./vendor/bin/codecept run -g php73 --steps
;;
7.4)
./vendor/bin/codecept run -g php74 --steps
;;
esac

0 comments on commit 86fc24f

Please sign in to comment.