Skip to content

Commit fda1c11

Browse files
Merge branch 'develop' into 2002.1-fwd
2 parents 95ce8bc + 981047c commit fda1c11

File tree

92 files changed

+2621
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2621
-267
lines changed

config/schema.error.yaml

Lines changed: 575 additions & 0 deletions
Large diffs are not rendered by default.

config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<service id="Magento\MagentoCloud\Config\EnvironmentDataInterface" alias="Magento\MagentoCloud\Config\EnvironmentData" />
114114
<service id="Magento\MagentoCloud\Config\Environment\ReaderInterface" alias="Magento\MagentoCloud\Config\Environment\Reader" />
115115
<service id="Magento\MagentoCloud\Config\Magento\Env\ReaderInterface" alias="Magento\MagentoCloud\Config\Magento\Env\Reader" />
116+
<service id="Magento\MagentoCloud\App\Logger\Error\ReaderInterface" alias="Magento\MagentoCloud\App\Logger\Error\Reader" />
116117
<service id="Magento\MagentoCloud\Config\Magento\Env\WriterInterface" alias="Magento\MagentoCloud\Config\Magento\Env\Writer" />
117118
<service id="Magento\MagentoCloud\Config\Magento\Shared\ReaderInterface" alias="Magento\MagentoCloud\Config\Magento\Shared\Reader" />
118119
<service id="Magento\MagentoCloud\Config\Magento\Shared\WriterInterface" alias="Magento\MagentoCloud\Config\Magento\Shared\Writer" />

dist/error-codes.md

Lines changed: 176 additions & 0 deletions
Large diffs are not rendered by default.

src/App/Error.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Error
6868
public const DEPLOY_UNABLE_TO_READ_RESET_PASSWORD_TMPL = 129;
6969
public const DEPLOY_CACHE_ENABLE_FAILED = 130;
7070
public const DEPLOY_CRYPT_KEY_IS_ABSENT = 131;
71+
public const DEPLOY_ES_CANNOT_CONNECT = 132;
7172

7273
public const PD_DEPLOY_IS_FAILED = 201;
7374
public const PD_ENV_PHP_IS_NOT_WRITABLE = 202;
@@ -83,4 +84,56 @@ class Error
8384
public const GLOBAL_CONFIG_PARSE_FAILED = 244;
8485
public const GLOBAL_CONFIG_UNABLE_TO_READ = 245;
8586
public const GLOBAL_CONFIG_UNABLE_TO_READ_SCHEMA_YAML = 246;
87+
88+
/**
89+
* Build
90+
*/
91+
public const WARN_CONFIG_PHP_NOT_EXISTS = 1001;
92+
public const WARN_UNSUPPORTED_BUILDS_OPTION_INI = 1002;
93+
public const WARN_MISSED_MODULE_SECTION = 1003;
94+
public const WARN_CONFIGURATION_VERSION_MISMATCH = 1004;
95+
public const WARN_SCD_OPTIONS_IGNORANCE = 1005;
96+
public const WARN_CONFIGURATION_STATE_NOT_IDEAL = 1006;
97+
public const WARN_BALER_CANNOT_BE_USED = 1007;
98+
99+
/**
100+
* Deploy
101+
*/
102+
public const WARN_REDIS_SERVICE_NOT_AVAILABLE = 2001;
103+
public const WARN_WRONG_SPLIT_DB_CONFIG = 2002;
104+
public const WARN_DIR_NESTING_LEVEL_NOT_CONFIGURED = 2003;
105+
public const WARN_NOT_CORRECT_LOCAL_XML_FILE = 2004;
106+
public const WARN_ADMIN_DATA_IGNORED = 2005;
107+
public const WARN_ADMIN_EMAIL_NOT_SET = 2006;
108+
public const WARN_UPDATE_PHP_VERSION = 2007;
109+
public const WARN_SOLR_DEPRECATED = 2008;
110+
public const WARN_SOLR_NOT_SUPPORTED = 2009;
111+
public const WARN_ES_INSTALLED_BUT_NOT_USED = 2010;
112+
public const WARN_ES_VERSION_MISMATCH = 2011;
113+
public const WARN_CONFIG_NOT_COMPATIBLE = 2012;
114+
public const WARN_DEPLOY_SCD_OPTIONS_IGNORANCE = 2013;
115+
public const WARN_DEPRECATED_VARIABLES = 2014;
116+
public const WARN_ENVIRONMENT_CONFIG_NOT_VALID = 2015;
117+
public const WARN_CONFIG_WRONG_JSON_FORMAT = 2016;
118+
public const WARN_SERVICE_VERSION_NOT_COMPATIBLE = 2017;
119+
public const WARN_SERVICE_PASSED_EOL = 2018;
120+
public const WARN_DEPRECATED_MYSQL_SEARCH_ENGINE = 2019;
121+
public const WARN_ENV_PHP_MISSED = 2020;
122+
public const WARN_SPLIT_DB_CUSTOM_CONNECTION_USED = 2021;
123+
public const WARN_DB_CONFIG_NOT_COMPATIBLE_WITH_SLAVE = 2022;
124+
public const WARN_SPLIT_DB_ENABLING_SKIPPED = 2023;
125+
public const WARN_NOT_ENOUGH_DATA_SPLIT_DB_VAR = 2024;
126+
public const WARN_SLAVE_CONNECTION_NOT_SET = 2025;
127+
128+
/**
129+
* Post-deploy
130+
*/
131+
public const WARN_DEBUG_LOG_ENABLED = 3001;
132+
public const WARN_CANNOT_FETCH_STORE_URLS = 3002;
133+
public const WARN_CANNOT_FETCH_STORE_URL = 3003;
134+
135+
/**
136+
* General
137+
*/
138+
public const WARN_CANNOT_GET_PROC_COUNT = 4001;
86139
}

src/App/ErrorInfo.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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\MagentoCloud\App;
9+
10+
use Magento\MagentoCloud\Filesystem\Driver\File;
11+
use Magento\MagentoCloud\Filesystem\FileList;
12+
use Symfony\Component\Yaml\Yaml;
13+
14+
/**
15+
* Returns info about errors from ./config/schema.error.yaml file
16+
*/
17+
class ErrorInfo
18+
{
19+
/**
20+
* @var array
21+
*/
22+
private $errors = [];
23+
24+
/**
25+
* @var File
26+
*/
27+
private $file;
28+
29+
/**
30+
* @var FileList
31+
*/
32+
private $fileList;
33+
34+
/**
35+
* @param File $file
36+
* @param FileList $fileList
37+
*/
38+
public function __construct(File $file, FileList $fileList)
39+
{
40+
$this->file = $file;
41+
$this->fileList = $fileList;
42+
}
43+
44+
/**
45+
* Returns info about error based on passed error code
46+
*
47+
* @param int $errorCode
48+
* @return array
49+
* @throws \Magento\MagentoCloud\Filesystem\FileSystemException
50+
*/
51+
public function get(int $errorCode): array
52+
{
53+
$this->loadErrors();
54+
55+
return $this->errors[$errorCode] ?? [];
56+
}
57+
58+
/**
59+
* Fetches all errors from schema.error.yaml file and caches them
60+
*
61+
* @throws \Magento\MagentoCloud\Filesystem\FileSystemException
62+
*/
63+
private function loadErrors(): void
64+
{
65+
if (empty($this->errors)) {
66+
$this->errors = Yaml::parse(
67+
$this->file->fileGetContents($this->fileList->getErrorSchema()),
68+
Yaml::PARSE_CONSTANT
69+
);
70+
}
71+
}
72+
}

src/App/Logger/Error/Reader.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\MagentoCloud\App\Logger\Error;
9+
10+
use Magento\MagentoCloud\Filesystem\FileList;
11+
use Magento\MagentoCloud\Package\UndefinedPackageException;
12+
13+
/**
14+
* @inheritDoc
15+
*/
16+
class Reader implements ReaderInterface
17+
{
18+
/**
19+
* @var FileList
20+
*/
21+
private $fileList;
22+
23+
/**
24+
* @param FileList $fileList
25+
*/
26+
public function __construct(FileList $fileList)
27+
{
28+
$this->fileList = $fileList;
29+
}
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function read(): array
35+
{
36+
try {
37+
$handle = @fopen($this->fileList->getCloudErrorLog(), 'r');
38+
if (!$handle) {
39+
return [];
40+
}
41+
$logs = [];
42+
while (($line = fgets($handle)) !== false) {
43+
$error = json_decode($line, true);
44+
$logs[$error['errorCode']] = $error;
45+
}
46+
fclose($handle);
47+
48+
return $logs;
49+
} catch (UndefinedPackageException $e) {
50+
return [];
51+
}
52+
}
53+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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\MagentoCloud\App\Logger\Error;
9+
10+
/**
11+
* Reads configuration from error log file.
12+
*/
13+
interface ReaderInterface extends \Magento\MagentoCloud\Filesystem\Reader\ReaderInterface
14+
{
15+
16+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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\MagentoCloud\App\Logger\Formatter;
9+
10+
use Magento\MagentoCloud\App\ContainerInterface;
11+
use Magento\MagentoCloud\App\ErrorInfo;
12+
use Magento\MagentoCloud\App\Logger\Error\ReaderInterface;
13+
use Monolog\Formatter\JsonFormatter;
14+
15+
/**
16+
* The factory for JsonErrorFormatter.
17+
*/
18+
class ErrorFormatterFactory
19+
{
20+
/**
21+
* @var ContainerInterface
22+
*/
23+
private $container;
24+
25+
/**
26+
* @param ContainerInterface $container
27+
*/
28+
public function __construct(ContainerInterface $container)
29+
{
30+
$this->container = $container;
31+
}
32+
33+
/**
34+
* @return JsonErrorFormatter
35+
*/
36+
public function create(): JsonErrorFormatter
37+
{
38+
return new JsonErrorFormatter(
39+
$this->container->get(ErrorInfo::class),
40+
$this->container->get(ReaderInterface::class),
41+
JsonFormatter::BATCH_MODE_JSON,
42+
true
43+
);
44+
}
45+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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\MagentoCloud\App\Logger\Formatter;
9+
10+
use Magento\MagentoCloud\App\ErrorInfo;
11+
use Magento\MagentoCloud\App\Logger\Error\ReaderInterface;
12+
use Magento\MagentoCloud\Filesystem\FileSystemException;
13+
use Monolog\Formatter\JsonFormatter;
14+
15+
/**
16+
* Formatter for log messages for cloud.error.log
17+
*/
18+
class JsonErrorFormatter extends JsonFormatter
19+
{
20+
/**
21+
* @var ErrorInfo
22+
*/
23+
private $errorInfo;
24+
25+
/**
26+
* @var ReaderInterface
27+
*/
28+
private $reader;
29+
30+
/**
31+
* @param ErrorInfo $errorInfo
32+
* @param ReaderInterface $reader
33+
* @param int $batchMode
34+
* @param bool $appendNewline
35+
*/
36+
public function __construct(
37+
ErrorInfo $errorInfo,
38+
ReaderInterface $reader,
39+
$batchMode = self::BATCH_MODE_JSON,
40+
$appendNewline = true
41+
) {
42+
parent::__construct($batchMode, $appendNewline);
43+
44+
$this->errorInfo = $errorInfo;
45+
$this->reader = $reader;
46+
}
47+
48+
/**
49+
* Format record, skip logging if ErrorCode isn't passed.
50+
*
51+
* {@inheritDoc}
52+
*/
53+
public function format(array $record)
54+
{
55+
try {
56+
if (!isset($record['context']['errorCode'])) {
57+
return false;
58+
}
59+
60+
$loggedErrors = $this->reader->read();
61+
62+
if (isset($loggedErrors[$record['context']['errorCode']])) {
63+
return false;
64+
}
65+
66+
return parent::format($this->formatLog($record));
67+
} catch (\Exception $e) {
68+
return false;
69+
}
70+
}
71+
72+
/**
73+
* Returns error info data based on errorCode.
74+
*
75+
* @param array $record
76+
* @return array
77+
* @throws FileSystemException
78+
*/
79+
private function formatLog(array $record): array
80+
{
81+
$errorCode = $record['context']['errorCode'];
82+
$errorInfo = $this->errorInfo->get($errorCode);
83+
84+
if (empty($errorInfo)) {
85+
$errorInfo = [
86+
'errorCode' => $errorCode,
87+
'title' => $record['message'] ?? ''
88+
];
89+
} else {
90+
$errorInfo['errorCode'] = $errorCode;
91+
if (!empty($record['message'])) {
92+
$errorInfo['title'] = $record['message'];
93+
}
94+
}
95+
96+
if (!empty($record['context']['suggestion'])) {
97+
$errorInfo['suggestion'] = $record['context']['suggestion'];
98+
}
99+
100+
ksort($errorInfo);
101+
return $errorInfo;
102+
}
103+
}

0 commit comments

Comments
 (0)