Skip to content

Commit 86fc24f

Browse files
Merge pull request #42 from magento/develop-fwd
Forward-port develop branch
2 parents e03afe2 + 46a2b55 commit 86fc24f

File tree

9 files changed

+236
-34
lines changed

9 files changed

+236
-34
lines changed

.travis.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ services:
1111
- docker
1212

1313
language: php
14-
php:
15-
- '7.1'
16-
- '7.2'
17-
- '7.3'
18-
19-
env:
20-
- TEST_SUITE=functional
2114

2215
stages:
2316
- static-unit
@@ -38,6 +31,21 @@ jobs:
3831
php: '7.3'
3932
env:
4033
- TEST_SUITE=static-unit
34+
- stage: test
35+
php: '7.1'
36+
env:
37+
- TEST_SUITE=functional
38+
- php: '7.2'
39+
env:
40+
- TEST_SUITE=functional
41+
- php: '7.3'
42+
env:
43+
- TEST_SUITE=functional
44+
- php: '7.4'
45+
dist: bionic
46+
env:
47+
- TEST_SUITE=functional
48+
4149

4250
install:
4351
- composer config github-oauth.github.com ${GITHUB_TOKEN}

Model/Cache/Evictor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public function evict(): int
7474
}
7575

7676
$dbKeys = $this->run(
77-
$cacheConfig['backend_options']['server'],
78-
$cacheConfig['backend_options']['port'],
79-
$cacheConfig['backend_options']['database']
77+
(string)$cacheConfig['backend_options']['server'],
78+
(int)$cacheConfig['backend_options']['port'],
79+
(int)$cacheConfig['backend_options']['database']
8080
);
8181
$evictedKeys += $dbKeys;
8282

Model/Cache/InvalidateLogger.php

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,93 @@
88

99
namespace Magento\CloudComponents\Model\Cache;
1010

11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Psr\Log\LoggerInterface as Logger;
13+
use Magento\CloudComponents\Model\DebugTrace;
14+
1115
/**
1216
* Log cache invalidation to a file
1317
*/
1418
class InvalidateLogger extends \Magento\Framework\Cache\InvalidateLogger
1519
{
20+
/**
21+
* @var string[]
22+
*/
23+
private $tagsToLog = [
24+
'cat_p',
25+
'cat_c',
26+
'PRODUCT_PRICE',
27+
'cms_b',
28+
'cms_p',
29+
'config_scopes',
30+
'eav',
31+
'eav_attribute',
32+
'fpc',
33+
'review_block',
34+
'SEARCH_QUERY',
35+
'search_query',
36+
'store_group',
37+
'store',
38+
'store_relations',
39+
'website',
40+
'CORE_DESIGN',
41+
'core_design',
42+
'WEBSERVICE',
43+
'webservice',
44+
'banner',
45+
'catalog_event',
46+
'config',
47+
'block_html',
48+
'COLLECTION_DATA',
49+
'collection_data',
50+
'collections',
51+
'layout_general_cache_tag',
52+
'layout',
53+
'compiled_config',
54+
'acl_cache',
55+
'reflection',
56+
'db_ddl',
57+
'all'
58+
];
59+
60+
/**
61+
* @var DebugTrace
62+
*/
63+
private $debugTrace;
64+
65+
/**
66+
* @param HttpRequest $request
67+
* @param Logger $logger
68+
* @param DebugTrace $debugTrace
69+
*/
70+
public function __construct(
71+
HttpRequest $request,
72+
Logger $logger,
73+
DebugTrace $debugTrace
74+
) {
75+
parent::__construct($request, $logger);
76+
$this->debugTrace = $debugTrace;
77+
}
78+
1679
/**
1780
* Log cache invalidation to a file
1881
*
1982
* @param mixed $invalidateInfo
2083
*/
2184
public function execute($invalidateInfo)
2285
{
23-
if (is_array($invalidateInfo)) {
24-
$invalidateInfo['trace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
25-
} elseif (is_string($invalidateInfo)) {
26-
$invalidateInfo = [
27-
'main' => $invalidateInfo,
28-
'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)
29-
];
30-
}
86+
$needTrace = false;
87+
if (is_array($invalidateInfo) && isset($invalidateInfo['tags'])) {
88+
foreach ($invalidateInfo['tags'] as $tag) {
89+
if (in_array(strtolower($tag), $this->tagsToLog)) {
90+
$needTrace = true;
91+
}
92+
}
3193

94+
if ($needTrace) {
95+
$invalidateInfo['trace'] = $this->debugTrace->getTrace();
96+
}
97+
}
3298
parent::execute($invalidateInfo);
3399
}
34100
}

Model/DebugTrace.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\CloudComponents\Model;
10+
11+
/**
12+
* Class to get compressed debug back trace
13+
*/
14+
class DebugTrace
15+
{
16+
/**
17+
* List of useless classes
18+
*
19+
* @var string[]
20+
*/
21+
private $notAllowedClasses = [
22+
'Symfony\Component\Console\Application',
23+
'Magento\Framework\Console\Cli',
24+
'Symfony\Component\Console\Command\Command',
25+
'Magento\Staging\Model\Event\Manager\Proxy',
26+
'Magento\Staging\Model\Event\Manager',
27+
'Magento\Framework\Event\Invoker\InvokerDefault',
28+
'Magento\CloudComponents\Model\Observer\CacheFlushAll',
29+
'Magento\CloudComponents\Model\Cache\InvalidateLogger',
30+
'Magento\CloudComponents\Model\Cache\InvalidateLogger',
31+
'Magento\CloudComponents\Model\Indexation\Logger',
32+
'Magento\Framework\Cache\Frontend\Decorator\Logger',
33+
'Magento\Framework\Cache\Frontend\Decorator\Bare',
34+
'Magento\Framework\App\Cache\Type\AccessProxy',
35+
'Magento\Framework\Cache\Frontend\Decorator\TagScope',
36+
'Magento\Framework\ObjectManager\ObjectManager',
37+
'Magento\Framework\ObjectManager\Config\Compiled',
38+
'Magento\Framework\ObjectManager\Config\Config',
39+
'Magento\Framework\ObjectManager\Factory\Dynamic\Developer',
40+
'Magento\Framework\ObjectManager\Factory\Dynamic\Production'
41+
];
42+
43+
/**
44+
* List of useless functions
45+
*
46+
* @var string[]
47+
*/
48+
private $notAllowedFunctions = [
49+
'___callPlugins',
50+
'___callParent',
51+
'Magento\Framework\Interception\{closure}'
52+
];
53+
54+
/**
55+
* Returns debug back trace
56+
*
57+
* @return array
58+
*/
59+
public function getTrace()
60+
{
61+
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
62+
foreach ($trace as $index => $line) {
63+
if (!isset($line['function'], $line['class'], $line['file'])) {
64+
continue;
65+
}
66+
if (in_array($line['function'], $this->notAllowedFunctions)
67+
|| in_array($line['class'], $this->notAllowedClasses)
68+
|| strpos($line['file'], 'Interceptor.php') !== false
69+
) {
70+
unset($trace[$index]);
71+
}
72+
unset($trace[$index]['type']);
73+
}
74+
75+
if (function_exists('gzcompress')) {
76+
return bin2hex(
77+
gzcompress(
78+
print_r(
79+
$trace,
80+
true
81+
)
82+
)
83+
);
84+
}
85+
return $trace;
86+
}
87+
}

Model/Indexation/Logger.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\CloudComponents\Model\Indexation;
1010

11+
use Magento\CloudComponents\Model\DebugTrace;
1112
use Magento\Framework\Indexer\ActionInterface;
1213
use Psr\Log\LoggerInterface;
1314

@@ -21,12 +22,21 @@ class Logger
2122
*/
2223
private $logger;
2324

25+
/**
26+
* @var DebugTrace
27+
*/
28+
private $debugTrace;
29+
2430
/**
2531
* @param LoggerInterface $logger
32+
* @param DebugTrace $debugTrace
2633
*/
27-
public function __construct(LoggerInterface $logger)
28-
{
34+
public function __construct(
35+
LoggerInterface $logger,
36+
DebugTrace $debugTrace
37+
) {
2938
$this->logger = $logger;
39+
$this->debugTrace = $debugTrace;
3040
}
3141

3242
/**
@@ -39,7 +49,7 @@ public function afterExecuteFull(ActionInterface $subject)
3949
$this->logger->debug(
4050
'full_indexation: ' . get_class($subject),
4151
[
42-
'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)
52+
'trace' => $this->debugTrace->getTrace()
4353
]
4454
);
4555
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CloudComponents\Test\Functional\Acceptance;
9+
10+
/**
11+
* @group php73
12+
*/
13+
class Acceptance73Cest extends AcceptanceCest
14+
{
15+
/**
16+
* @return array
17+
*/
18+
protected function patchesDataProvider(): array
19+
{
20+
return [
21+
['magentoVersion' => '2.3.3'],
22+
['magentoVersion' => '2.3.5'],
23+
];
24+
}
25+
}

Test/Functional/Acceptance/AcceptanceCest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Magento\CloudComponents\Test\Functional\Acceptance;
99

1010
/**
11-
* @group php73
11+
* @group php74
1212
*/
1313
class AcceptanceCest
1414
{
@@ -49,7 +49,7 @@ protected function prepareTemplate(\CliTester $I, string $magentoVersion): void
4949
public function testPatches(\CliTester $I, \Codeception\Example $data): void
5050
{
5151
$this->prepareTemplate($I, $data['magentoVersion']);
52-
$this->removeESIfExists($I);
52+
$this->removeESIfExists($I, $data['magentoVersion']);
5353
$I->runEceDockerCommand('build:compose --mode=production');
5454
$I->runDockerComposeCommand('run build cloud-build');
5555
$I->startEnvironment();
@@ -62,18 +62,21 @@ public function testPatches(\CliTester $I, \Codeception\Example $data): void
6262

6363
/**
6464
* @param \CliTester $I
65+
* @param string $magentoVersion
6566
*/
66-
protected function removeESIfExists(\CliTester $I): void
67+
protected function removeESIfExists(\CliTester $I, string $magentoVersion): void
6768
{
68-
$services = $I->readServicesYaml();
69+
if ($magentoVersion !== 'master' && version_compare($magentoVersion, '2.4.0', '<')) {
70+
$services = $I->readServicesYaml();
6971

70-
if (isset($services['elasticsearch'])) {
71-
unset($services['elasticsearch']);
72-
$I->writeServicesYaml($services);
72+
if (isset($services['elasticsearch'])) {
73+
unset($services['elasticsearch']);
74+
$I->writeServicesYaml($services);
7375

74-
$app = $I->readAppMagentoYaml();
75-
unset($app['relationships']['elasticsearch']);
76-
$I->writeAppMagentoYaml($app);
76+
$app = $I->readAppMagentoYaml();
77+
unset($app['relationships']['elasticsearch']);
78+
$I->writeAppMagentoYaml($app);
79+
}
7780
}
7881
}
7982

@@ -83,7 +86,7 @@ protected function removeESIfExists(\CliTester $I): void
8386
protected function patchesDataProvider(): array
8487
{
8588
return [
86-
['magentoVersion' => '2.3.3'],
89+
['magentoVersion' => '2.4.0'],
8790
['magentoVersion' => 'master'],
8891
];
8992
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/magento-cloud-components",
33
"description": "Cloud Components Module for Magento 2.x",
44
"type": "magento2-module",
5-
"version": "1.0.6",
5+
"version": "1.0.7",
66
"require": {
77
"php": "^7.0",
88
"ext-json": "*",
@@ -19,7 +19,7 @@
1919
"consolidation/robo": "^1.2",
2020
"phpmd/phpmd": "@stable",
2121
"phpstan/phpstan": "^0.11",
22-
"phpunit/phpunit": "^6.2",
22+
"phpunit/phpunit": "^7.2",
2323
"squizlabs/php_codesniffer": "^3.0"
2424
},
2525
"config": {

tests/travis/functional.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ case $TRAVIS_PHP_VERSION in
1616
7.3)
1717
./vendor/bin/codecept run -g php73 --steps
1818
;;
19+
7.4)
20+
./vendor/bin/codecept run -g php74 --steps
21+
;;
1922
esac

0 commit comments

Comments
 (0)