Skip to content

Commit ecbfd3f

Browse files
authored
feat: remove ok messages from PerformanceChecker, refactor table to be meant as info, add installation path and database information, (#206)
1 parent be7d367 commit ecbfd3f

19 files changed

+155
-229
lines changed

src/Components/Health/Checker/HealthChecker/MysqlChecker.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function collect(HealthCollection $collection): void
1717
{
1818
$version = $this->connection->fetchOne('SELECT VERSION()');
1919
if (!\is_string($version)) {
20-
$collection->add(SettingsResult::error('mysql', 'MySQL Version cannot be checked'));
20+
$collection->add(SettingsResult::error('mysql', 'MySQL Version', 'unknown'));
2121

2222
return;
2323
}
@@ -60,13 +60,14 @@ private function checkMysqlVersion(HealthCollection $collection, string $version
6060
'8.0.20',
6161
'8.0.21',
6262
];
63+
$snippet = 'MySQL Version';
6364

6465
$recommended = 'min ' . $minVersion . ', but not ' . \implode(' or ', $brokenVersions);
6566

6667
if (\in_array($version, $brokenVersions, true)) {
6768
$collection->add(SettingsResult::error(
6869
'mysql',
69-
'MySQL Version has technical problems',
70+
$snippet,
7071
$version,
7172
$recommended
7273
));
@@ -77,7 +78,7 @@ private function checkMysqlVersion(HealthCollection $collection, string $version
7778
if (version_compare($version, $minVersion, '>=')) {
7879
$collection->add(SettingsResult::ok(
7980
'mysql',
80-
'MySQL version',
81+
$snippet,
8182
$version,
8283
$recommended
8384
));
@@ -87,7 +88,7 @@ private function checkMysqlVersion(HealthCollection $collection, string $version
8788

8889
$collection->add(SettingsResult::error(
8990
'mysql',
90-
'MySQL Version is outdated',
91+
$snippet,
9192
$version,
9293
'min ' . $minVersion
9394
));

src/Components/Health/Checker/HealthChecker/PhpChecker.php

+24-27
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,29 @@ private function formatSize(float $size): string
2727

2828
private function checkPhp(HealthCollection $collection): void
2929
{
30-
$minPhpVersion = '8.1.0';
30+
$minPhpVersion = '8.2.0';
3131
$currentPhpVersion = \PHP_VERSION;
32-
if (version_compare('8.0.0', $currentPhpVersion, '>')) {
33-
$collection->add(
34-
SettingsResult::error(
35-
'php-version',
36-
'PHP Version is outdated',
37-
$currentPhpVersion,
38-
'min ' . $minPhpVersion
39-
)
40-
);
41-
} elseif (version_compare('8.1.0', $currentPhpVersion, '>')) {
32+
if (version_compare($minPhpVersion, $currentPhpVersion, '>')) {
4233
$collection->add(
4334
SettingsResult::warning(
44-
'php-version',
45-
'PHP Version is outdated',
46-
$currentPhpVersion,
47-
'min ' . $minPhpVersion
48-
)
49-
);
50-
} else {
51-
$collection->add(
52-
SettingsResult::ok(
5335
'php-version',
5436
'PHP Version',
5537
$currentPhpVersion,
5638
'min ' . $minPhpVersion
5739
)
5840
);
41+
42+
return;
5943
}
44+
45+
$collection->add(
46+
SettingsResult::ok(
47+
'php-version',
48+
'PHP Version',
49+
$currentPhpVersion,
50+
'min ' . $minPhpVersion
51+
)
52+
);
6053
}
6154

6255
private function checkMaxExecutionTime(HealthCollection $collection): void
@@ -67,7 +60,7 @@ private function checkMaxExecutionTime(HealthCollection $collection): void
6760
$collection->add(
6861
SettingsResult::error(
6962
'php-max-execution',
70-
'Max-Execution-Time is too low',
63+
'Max-Execution-Time',
7164
(string) $currentMaxExecutionTime,
7265
'min ' . $minMaxExecutionTime
7366
)
@@ -92,7 +85,7 @@ private function checkMemoryLimit(HealthCollection $collection): void
9285
$collection->add(
9386
SettingsResult::error(
9487
'php-memory-limit',
95-
'Can not read Memory-Limit',
88+
'Memory-Limit',
9689
'unknown',
9790
'min ' . $this->formatSize($minMemoryLimit)
9891
)
@@ -106,7 +99,7 @@ private function checkMemoryLimit(HealthCollection $collection): void
10699
$collection->add(
107100
SettingsResult::error(
108101
'php-memory-limit',
109-
'Memory-Limit is too low',
102+
'Memory-Limit',
110103
$this->formatSize($currentMemoryLimit),
111104
'min ' . $this->formatSize($minMemoryLimit)
112105
)
@@ -125,24 +118,28 @@ private function checkMemoryLimit(HealthCollection $collection): void
125118

126119
private function checkOpCacheActive(HealthCollection $collection): void
127120
{
121+
$snippet = 'Zend Opcache';
122+
128123
if (\extension_loaded('Zend OPcache') && \ini_get('opcache.enable')) {
129-
$collection->add(SettingsResult::ok('zend-opcache', 'Zend Opcache is active', 'active', 'active'));
124+
$collection->add(SettingsResult::ok('zend-opcache', $snippet, 'active', 'active'));
130125

131126
return;
132127
}
133128

134-
$collection->add(SettingsResult::warning('zend-opcache', 'Zend Opcache is not active', 'not active', 'active'));
129+
$collection->add(SettingsResult::warning('zend-opcache', $snippet, 'not active', 'active'));
135130
}
136131

137132
private function checkPcreJitActive(HealthCollection $collection): void
138133
{
134+
$snippet = 'PCRE-Jit';
135+
139136
if (\ini_get('pcre.jit')) {
140-
$collection->add(SettingsResult::ok('pcre-jit', 'PCRE-Jit is active', 'active', 'active'));
137+
$collection->add(SettingsResult::ok('pcre-jit', $snippet, 'active', 'active'));
141138

142139
return;
143140
}
144141

145-
$collection->add(SettingsResult::warning('pcre-jit', 'PCRE-Jit is not active', 'not active', 'active'));
142+
$collection->add(SettingsResult::warning('pcre-jit', $snippet, 'not active', 'active'));
146143
}
147144

148145
private function decodePhpSize(string $val): float

src/Components/Health/Checker/HealthChecker/ProductionChecker.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public function __construct(private readonly string $environment)
1515
public function collect(HealthCollection $collection): void
1616
{
1717
if ($this->environment !== 'prod') {
18-
$collection->add(SettingsResult::error('app.env', 'Shop is not in production mode', $this->environment, 'prod'));
18+
$collection->add(SettingsResult::error('app.env', 'Shop mode', $this->environment, 'prod'));
1919

2020
return;
2121
}
2222

23-
$collection->add(SettingsResult::ok('app.env', 'Shop is in production mode', $this->environment, 'prod'));
23+
$collection->add(SettingsResult::ok('app.env', 'Shop mode', $this->environment, 'prod'));
2424
}
2525
}

src/Components/Health/Checker/HealthChecker/QueueChecker.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,27 @@ public function __construct(private readonly Connection $connection)
1515

1616
public function collect(HealthCollection $collection): void
1717
{
18-
$oldMessageLimit = (new \DateTimeImmutable())->modify('-15 minutes');
18+
$maxDiff = 15;
19+
$oldMessageLimit = (new \DateTimeImmutable())->modify(\sprintf('-%d minutes', $maxDiff));
20+
21+
$snippet = 'Open Queues';
22+
$recommended = \sprintf('max %d mins', $maxDiff);
1923

2024
/** @var string|false $oldestMessageAt */
2125
$oldestMessageAt = $this->connection->fetchOne('SELECT available_at FROM messenger_messages ORDER BY available_at ASC LIMIT 1');
2226

23-
if (is_string($oldestMessageAt) && new \DateTimeImmutable($oldestMessageAt . ' UTC') < $oldMessageLimit) {
24-
$result = SettingsResult::warning('queue', 'Open Queues older than 15 minutes found');
27+
if (is_string($oldestMessageAt)) {
28+
$diff = round(abs(
29+
((new \DateTime($oldestMessageAt . ' UTC'))->getTimestamp() - $oldMessageLimit->getTimestamp()) / 60
30+
));
31+
32+
if ($diff > $maxDiff) {
33+
$result = SettingsResult::warning('queue', $snippet, $diff . ' mins', $recommended);
34+
} else {
35+
$result = SettingsResult::ok('queue', $snippet, $diff . ' mins', $recommended);
36+
}
2537
} else {
26-
$result = SettingsResult::ok('queue', 'Queues working good');
38+
$result = SettingsResult::info('queue', $snippet, 'unknown', $recommended);
2739
}
2840

2941
$result->url = 'https://developer.shopware.com/docs/guides/hosting/infrastructure/message-queue';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Frosh\Tools\Components\Health\Checker\HealthChecker;
4+
5+
use Frosh\Tools\Components\Health\Checker\CheckerInterface;
6+
use Frosh\Tools\Components\Health\HealthCollection;
7+
use Frosh\Tools\Components\Health\SettingsResult;
8+
use Shopware\Core\Maintenance\System\Struct\DatabaseConnectionInformation;
9+
10+
class SystemInfoChecker implements CheckerInterface
11+
{
12+
public function __construct(private readonly string $kernelProjectDir)
13+
{
14+
}
15+
16+
public function collect(HealthCollection $collection): void
17+
{
18+
$this->checkPath($collection);
19+
$this->getDatabaseInfo($collection);
20+
}
21+
22+
private function checkPath(HealthCollection $collection): void
23+
{
24+
$collection->add(
25+
SettingsResult::ok(
26+
'installation-path',
27+
'Installation Path',
28+
$this->kernelProjectDir
29+
)
30+
);
31+
}
32+
33+
private function getDatabaseInfo(HealthCollection $collection)
34+
{
35+
$databaseConnectionInfo = (new DatabaseConnectionInformation())->fromEnv();
36+
37+
$collection->add(
38+
SettingsResult::ok(
39+
'database-info',
40+
'Database',
41+
\sprintf('%s@%s:%s',
42+
$databaseConnectionInfo->getDatabaseName(),
43+
$databaseConnectionInfo->getHostname(),
44+
$databaseConnectionInfo->getPort()
45+
)
46+
)
47+
);
48+
}
49+
}

src/Components/Health/Checker/HealthChecker/TaskChecker.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,30 @@ public function collect(HealthCollection $collection): void
3434
return $taskClass::shouldRun($this->parameterBag);
3535
});
3636

37-
$taskDateLimit = (new \DateTimeImmutable())->modify('-10 minutes');
37+
$maxDiff = 10;
38+
$taskDateLimit = (new \DateTimeImmutable())->modify(\sprintf('-%d minutes', $maxDiff));
39+
$recommended = \sprintf('max %d mins', $maxDiff);
3840

3941
$tasks = array_filter($tasks, function (array $task) use ($taskDateLimit) {
4042
return new \DateTimeImmutable($task['next_execution_time']) < $taskDateLimit;
4143
});
4244

4345
if ($tasks === []) {
44-
$collection->add(SettingsResult::ok('scheduled_task', 'Scheduled tasks working scheduled'));
46+
$collection->add(SettingsResult::ok('scheduled_task', 'Scheduled tasks', '0 mins', $recommended));
4547

4648
return;
4749
}
4850

49-
$collection->add(SettingsResult::warning('scheduled_task', 'The scheduled tasks are waiting for executing for more than 10 minutes'));
51+
$maxTaskNextExecTime = 0;
52+
53+
foreach ($tasks as $task) {
54+
$maxTaskNextExecTime = max((new \DateTimeImmutable($task['next_execution_time']))->getTimestamp(), $maxTaskNextExecTime);
55+
}
56+
57+
$diff = round(abs(
58+
($maxTaskNextExecTime - $taskDateLimit->getTimestamp()) / 60
59+
));
60+
61+
$collection->add(SettingsResult::warning('scheduled_task', 'Scheduled tasks', \sprintf('%d mins',$diff), $recommended));
5062
}
5163
}

src/Components/Health/Checker/PerformanceChecker/AdminWorkerChecker.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,12 @@ public function collect(HealthCollection $collection): void
1818
$collection->add(
1919
SettingsResult::warning(
2020
'admin-watcher',
21-
'Admin-Worker should be disabled',
21+
'Admin-Worker',
2222
'enabled',
2323
'disabled',
2424
'https://developer.shopware.com/docs/guides/plugins/plugins/framework/message-queue/add-message-handler#the-admin-worker'
2525
)
2626
);
27-
28-
return;
2927
}
30-
31-
$collection->add(
32-
SettingsResult::ok(
33-
'admin-watcher',
34-
'Admin-Worker is disabled',
35-
'disabled',
36-
'disabled'
37-
)
38-
);
3928
}
4029
}

src/Components/Health/Checker/PerformanceChecker/DisabledMailUpdatesChecker.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ public function collect(HealthCollection $collection): void
2020
return;
2121
}
2222

23-
$result = SettingsResult::ok('mail_variables', 'MailVariables are not updated frequently', 'disabled');
2423
$setting = $this->params->get('shopware.mail.update_mail_variables_on_send');
2524

26-
if ($setting) {
27-
$result = SettingsResult::warning('mail_variables', 'MailVariables should not be updated frequently');
28-
$result->current = 'enabled';
25+
if (!$setting) {
26+
return;
2927
}
3028

31-
$result->recommended = 'disabled';
29+
$result = SettingsResult::warning('mail_variables', 'MailVariables updates', 'enabled', 'disabled');
30+
3231
$result->url = 'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks#prevent-mail-data-updates';
3332
$collection->add($result);
3433
}

src/Components/Health/Checker/PerformanceChecker/EsChecker.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,12 @@ public function collect(HealthCollection $collection): void
2222
$collection->add(
2323
SettingsResult::info(
2424
'elasticsearch',
25-
'Elasticsearch is disabled',
25+
'Elasticsearch',
2626
'disabled',
2727
'enabled',
2828
'https://developer.shopware.com/docs/guides/hosting/infrastructure/elasticsearch/elasticsearch-setup'
2929
)
3030
);
31-
32-
return;
3331
}
34-
35-
$collection->add(
36-
SettingsResult::ok(
37-
'elasticsearch',
38-
'Elasticsearch is enabled',
39-
'enabled',
40-
'enabled'
41-
)
42-
);
4332
}
4433
}

src/Components/Health/Checker/PerformanceChecker/FixCacheIdSetChecker.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,12 @@ public function collect(HealthCollection $collection): void
2525
$collection->add(
2626
SettingsResult::warning(
2727
'cache-id',
28-
'A fixed cache id should be set',
28+
'Fixed cache id',
2929
'not set',
3030
'set',
3131
'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks#cache-id'
3232
)
3333
);
34-
35-
return;
3634
}
37-
38-
$collection->add(
39-
SettingsResult::ok(
40-
'cache-id',
41-
'A fixed cache id is set',
42-
\sprintf('set (%s)', $cacheId),
43-
'set',
44-
)
45-
);
4635
}
4736
}

0 commit comments

Comments
 (0)