Skip to content

Commit

Permalink
feat: check for RedisTagAwareAdapter in performance info
Browse files Browse the repository at this point in the history
  • Loading branch information
tinect committed Jan 8, 2024
1 parent 96a05ce commit a411844
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Command/MonitorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function queueFailed(): bool
{
/** @var string $createdAt */
$createdAt = $this->connection->fetchOne('SELECT IFNULL(MIN(created_at), 0) FROM messenger_messages');
$oldestMessage = (int)$createdAt;
$oldestMessage = (int) $createdAt;
$oldestMessage /= 10000;
$minutes = $this->configService->getInt(
'FroshTools.config.monitorQueueGraceTime'
Expand Down
18 changes: 13 additions & 5 deletions src/Components/CacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

class CacheAdapter
{
public const TYPE_REDIS = 'Redis';
public const TYPE_REDIS_TAG_AWARE = 'Redis (TagAware)';
public const TYPE_FILESYSTEM = 'Filesystem';
public const TYPE_ARRAY = 'Array';
public const TYPE_PHP_FILES = 'PHP files';
public const TYPE_APCU = 'APCu';

private readonly AdapterInterface $adapter;

public function __construct(AdapterInterface $adapter)
Expand Down Expand Up @@ -93,11 +100,12 @@ public function clear(): void
public function getType(): string
{
return match (true) {
$this->adapter instanceof RedisAdapter, $this->adapter instanceof RedisTagAwareAdapter => 'Redis ' . $this->getRedis($this->adapter)->info()['redis_version'],
$this->adapter instanceof FilesystemAdapter => 'Filesystem',
$this->adapter instanceof ArrayAdapter => 'Array',
$this->adapter instanceof PhpFilesAdapter => 'PHP files',
$this->adapter instanceof ApcuAdapter => 'APCu',
$this->adapter instanceof RedisAdapter, => self::TYPE_REDIS . ' ' . $this->getRedis($this->adapter)->info()['redis_version'],
$this->adapter instanceof RedisTagAwareAdapter => self::TYPE_REDIS_TAG_AWARE . ' ' . $this->getRedis($this->adapter)->info()['redis_version'],
$this->adapter instanceof FilesystemAdapter => self::TYPE_FILESYSTEM,
$this->adapter instanceof ArrayAdapter => self::TYPE_ARRAY,
$this->adapter instanceof PhpFilesAdapter => self::TYPE_PHP_FILES,
$this->adapter instanceof ApcuAdapter => self::TYPE_APCU,
default => '',
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker;

use Frosh\Tools\Components\CacheAdapter;
use Frosh\Tools\Components\CacheRegistry;
use Frosh\Tools\Components\Health\Checker\CheckerInterface;
use Frosh\Tools\Components\Health\HealthCollection;
use Frosh\Tools\Components\Health\SettingsResult;

class RedisTagAwareChecker implements PerformanceCheckerInterface, CheckerInterface
{
public function __construct(
private readonly CacheRegistry $cacheRegistry
) {}

public function collect(HealthCollection $collection): void
{
$httpCacheType = $this->cacheRegistry->get('cache.http')->getType();

if (!\str_starts_with($httpCacheType, CacheAdapter::TYPE_REDIS)
|| \str_starts_with($httpCacheType, CacheAdapter::TYPE_REDIS_TAG_AWARE)) {
return;
}

$collection->add(
SettingsResult::warning(
'redis-tag-aware',
'Redis should be TagAware',
CacheAdapter::TYPE_REDIS,
CacheAdapter::TYPE_REDIS_TAG_AWARE,
'https://developer.shopware.com/docs/guides/hosting/performance/caches.html#example-replace-some-cache-with-redis'
)
);


}

private function checkAssertActive(HealthCollection $collection, string $url): void

Check failure on line 41 in src/Components/Health/Checker/PerformanceChecker/RedisTagAwareChecker.php

View workflow job for this annotation

GitHub Actions / phpstan / check

Method Frosh\Tools\Components\Health\Checker\PerformanceChecker\RedisTagAwareChecker::checkAssertActive() is unused.
{
$currentValue = $this->iniGetFailover('zend.assertions');
if ($currentValue !== '-1') {
$collection->add(
SettingsResult::warning(
'zend.assertions',
'PHP value zend.assertions',
$currentValue,
'-1',
$url
)
);
}
}

private function checkEnableFileOverride(HealthCollection $collection, string $url): void

Check failure on line 57 in src/Components/Health/Checker/PerformanceChecker/RedisTagAwareChecker.php

View workflow job for this annotation

GitHub Actions / phpstan / check

Method Frosh\Tools\Components\Health\Checker\PerformanceChecker\RedisTagAwareChecker::checkEnableFileOverride() is unused.
{
$currentValue = $this->iniGetFailover('opcache.enable_file_override');
if ($currentValue !== '1') {
$collection->add(
SettingsResult::warning(
'php.opcache.enable_file_override',
'PHP value opcache.enable_file_override',
$currentValue,
'1',
$url
)
);
}
}

private function checkInternedStringsBuffer(HealthCollection $collection, string $url): void

Check failure on line 73 in src/Components/Health/Checker/PerformanceChecker/RedisTagAwareChecker.php

View workflow job for this annotation

GitHub Actions / phpstan / check

Method Frosh\Tools\Components\Health\Checker\PerformanceChecker\RedisTagAwareChecker::checkInternedStringsBuffer() is unused.
{
$currentValue = $this->iniGetFailover('opcache.interned_strings_buffer');
if ((int) $currentValue < 20) {
$collection->add(
SettingsResult::warning(
'php.opcache.interned_strings_buffer',
'PHP value opcache.interned_strings_buffer',
$currentValue,
'min 20',
$url
)
);
}
}

private function checkZendDetectUnicode(HealthCollection $collection, string $url): void

Check failure on line 89 in src/Components/Health/Checker/PerformanceChecker/RedisTagAwareChecker.php

View workflow job for this annotation

GitHub Actions / phpstan / check

Method Frosh\Tools\Components\Health\Checker\PerformanceChecker\RedisTagAwareChecker::checkZendDetectUnicode() is unused.
{
$currentValue = $this->iniGetFailover('zend.detect_unicode');
if ($currentValue !== '0') {
$collection->add(
SettingsResult::warning(
'php.zend.detect_unicode',
'PHP value zend.detect_unicode',
$currentValue,
'0',
$url
)
);
}
}

private function checkRealpathCacheTtl(HealthCollection $collection, string $url): void

Check failure on line 105 in src/Components/Health/Checker/PerformanceChecker/RedisTagAwareChecker.php

View workflow job for this annotation

GitHub Actions / phpstan / check

Method Frosh\Tools\Components\Health\Checker\PerformanceChecker\RedisTagAwareChecker::checkRealpathCacheTtl() is unused.
{
$currentValue = $this->iniGetFailover('realpath_cache_ttl');
if ((int) $currentValue < 3600) {
$collection->add(
SettingsResult::warning(
'php.zend.realpath_cache_ttl',
'PHP value realpath_cache_ttl',
$currentValue,
'min 3600',
$url
)
);
}
}

private function iniGetFailover(string $option): string
{
$currentValue = \ini_get($option);
if (\is_string($currentValue)) {
return $currentValue;
}

return 'not set';
}
}
2 changes: 1 addition & 1 deletion src/Components/SystemConfig/ConfigSystemConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function load(?string $salesChannelId): array
);

foreach ($specific as $key => $value) {
$keys = \explode('.', (string)$key);
$keys = \explode('.', (string) $key);

$specific = $this->getSubArray($specific, $keys, $value);

Expand Down

0 comments on commit a411844

Please sign in to comment.