Skip to content

Commit e92fb1f

Browse files
batabanaskurfuerst
authored andcommitted
FEATURE: add size information for redis keys (WIP)
1 parent b8cd72c commit e92fb1f

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

Classes/BackendUi/BackendUiDataService.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
1010
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\PrunnerJobId;
1111
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\RedisInstanceIdentifier;
12+
use Flowpack\DecoupledContentStore\Core\Infrastructure\RedisClientManager;
1213
use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Repository\RedisEnumerationRepository;
1314
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderingStatistics;
1415
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingErrorManager;
@@ -59,6 +60,12 @@ class BackendUiDataService
5960
*/
6061
protected $redisReleaseSwitchService;
6162

63+
/**
64+
* @Flow\Inject
65+
* @var RedisClientManager
66+
*/
67+
protected $redisClientManager;
68+
6269
public function loadBackendOverviewData(RedisInstanceIdentifier $redisInstanceIdentifier)
6370
{
6471
$contentReleaseIds = $this->redisContentReleaseService->fetchAllReleaseIds($redisInstanceIdentifier);
@@ -83,13 +90,30 @@ public function loadBackendOverviewData(RedisInstanceIdentifier $redisInstanceId
8390
$lastRendering->getTotalJobs() > 0 ? round($lastRendering->getRenderedJobs()
8491
/ $lastRendering->getTotalJobs() * 100) : 100,
8592
$firstRendering->getRenderedJobs(),
86-
$contentReleaseId->equals($this->redisReleaseSwitchService->getCurrentRelease($redisInstanceIdentifier))
93+
$contentReleaseId->equals($this->redisReleaseSwitchService->getCurrentRelease($redisInstanceIdentifier)),
94+
$this->calculateReleaseSize($redisInstanceIdentifier, $contentReleaseId)
8795
);
8896
}
8997

9098
return $result;
9199
}
92100

101+
private function calculateReleaseSize(RedisInstanceIdentifier $redisInstanceIdentifier, ContentReleaseIdentifier $contentReleaseIdentifier)
102+
{
103+
$redis = $this->redisClientManager->getRedis($redisInstanceIdentifier);
104+
$allKeys = $redis->keys('*');
105+
$size = 0;
106+
107+
foreach ($allKeys as $key) {
108+
if (str_contains($key, $contentReleaseIdentifier->getIdentifier())) {
109+
$size += $redis->rawCommand('memory', 'usage', $key);
110+
}
111+
}
112+
113+
// bytes are returned, convert to megabytes
114+
return round($size / 100000, 2);
115+
}
116+
93117
public function loadDetailsData(ContentReleaseIdentifier $contentReleaseIdentifier, RedisInstanceIdentifier $redisInstanceIdentifier): ContentReleaseDetails
94118
{
95119
$contentReleaseMetadata = $this->redisContentReleaseService->fetchMetadataForContentRelease($contentReleaseIdentifier, $redisInstanceIdentifier);

Classes/BackendUi/Dto/ContentReleaseOverviewRow.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ class ContentReleaseOverviewRow
2121
private float $progress;
2222
private int $renderedUrlCount;
2323
private bool $isActive;
24+
private float $releaseSize;
2425

2526
public function __construct(ContentReleaseIdentifier $contentReleaseIdentifier, ContentReleaseMetadata $metadata,
2627
int $enumeratedDocumentNodesCount, int $iterationsCount, int $errorCount,
27-
float $progress, int $renderedUrlCount, bool $isActive)
28+
float $progress, int $renderedUrlCount, bool $isActive, float $releaseSize)
2829
{
2930
$this->contentReleaseIdentifier = $contentReleaseIdentifier;
3031
$this->metadata = $metadata;
@@ -34,6 +35,7 @@ public function __construct(ContentReleaseIdentifier $contentReleaseIdentifier,
3435
$this->progress = $progress;
3536
$this->renderedUrlCount = $renderedUrlCount;
3637
$this->isActive = $isActive;
38+
$this->releaseSize = $releaseSize;
3739
}
3840

3941
/**
@@ -100,4 +102,12 @@ public function isActive(): bool
100102
return $this->isActive;
101103
}
102104

105+
/**
106+
* @return float
107+
*/
108+
public function getReleaseSize(): float
109+
{
110+
return $this->releaseSize;
111+
}
112+
103113
}

Classes/Controller/BackendController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ class BackendController extends \Neos\Flow\Mvc\Controller\ActionController
8787
public function indexAction(?string $contentStore = null)
8888
{
8989
$contentStore = $contentStore ? RedisInstanceIdentifier::fromString($contentStore) : RedisInstanceIdentifier::primary();
90+
$storeSize = $this->redisClientManager->getRedis($contentStore)->info('memory')['used_memory_human'];
9091

9192
$this->view->assign('contentStore', $contentStore->getIdentifier());
9293
$this->view->assign('overviewData', $this->backendUiDataService->loadBackendOverviewData($contentStore));
9394
$this->view->assign('redisContentStores', array_keys($this->redisContentStores));
95+
$this->view->assign('storeSize', $storeSize);
9496
}
9597

9698
public function detailsAction(string $contentReleaseIdentifier, ?string $contentStore = null, ?string $detailTaskName = '', ?string $prunnerJobId = '')

Resources/Private/BackendFusion/Integration/Backend.Index.fusion

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Flowpack.DecoupledContentStore.BackendController.index = Neos.Fusion:Component {
44
// - overviewData: list of ContentReleaseOverviewRow objects
55
// - contentStore: contains string content store identifier
66
// - redisContentStores: array of all configured content store identifiers
7+
// - storeSize: string of content store size
78

89
renderer = Neos.Fusion:Component {
910
_pruneContentStoreUri = Neos.Fusion:UriBuilder {
@@ -49,7 +50,7 @@ Flowpack.DecoupledContentStore.BackendController.index = Neos.Fusion:Component {
4950
<td>{props.start}</td>
5051
<td>{props.end}</td>
5152
<td>{props.switch}</td>
52-
<td>TODO</td>
53+
<td>{item.releaseSize} MB</td>
5354
</tr>
5455
`
5556
}
@@ -84,6 +85,9 @@ Flowpack.DecoupledContentStore.BackendController.index = Neos.Fusion:Component {
8485
</tbody>
8586
</table>
8687

88+
<span>Store size: </span>
89+
<span class="neos-badge neos-badge-info">{storeSize}</span>
90+
<br />
8791
<button form="postHelper" formaction={props._pruneContentStoreUri} type="submit" class="neos-button neos-button-danger" style="margin-top: 300px;">
8892
Prune content store
8993
</button>

0 commit comments

Comments
 (0)