Skip to content

Commit ef8706e

Browse files
committed
FEATURE: Add statistics event logging to ContentReleaseLogger
1 parent e525968 commit ef8706e

8 files changed

Lines changed: 98 additions & 11 deletions

File tree

Classes/BackendUi/BackendUiDataService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Repository\RedisEnumerationRepository;
1414
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderingStatistics;
1515
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingErrorManager;
16-
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingStatisticsStore;
16+
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingTimeStatisticsStore;
1717
use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService;
1818
use Flowpack\DecoupledContentStore\ReleaseSwitch\Infrastructure\RedisReleaseSwitchService;
1919
use Neos\Flow\Annotations as Flow;
@@ -44,7 +44,7 @@ class BackendUiDataService
4444

4545
/**
4646
* @Flow\Inject
47-
* @var RedisRenderingStatisticsStore
47+
* @var RedisRenderingTimeStatisticsStore
4848
*/
4949
protected $redisRenderingStatisticsStore;
5050

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\DecoupledContentStore\Core\Infrastructure;
5+
6+
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
7+
use Neos\Flow\Cli\ConsoleOutput;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class ConsoleStatisticsEventOutput implements StatisticsEventOutputInterface
11+
{
12+
protected OutputInterface $output;
13+
14+
function __construct(OutputInterface $output)
15+
{
16+
$this->output = $output;
17+
}
18+
19+
public static function fromConsoleOutput(ConsoleOutput $output): self
20+
{
21+
return static::fromSymfonyOutput($output->getOutput());
22+
}
23+
24+
public static function fromSymfonyOutput(OutputInterface $output): self
25+
{
26+
return new static($output);
27+
}
28+
29+
public function writeEvent(ContentReleaseIdentifier $contentReleaseIdentifier, string $prefix, string $event, array $additionalPayload): void
30+
{
31+
$this->output->writeln($prefix . 'STATISTICS EVENT ' . $event . ($additionalPayload ? ' ' . json_encode($additionalPayload) : ''));
32+
}
33+
}

Classes/Core/Infrastructure/ContentReleaseLogger.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class ContentReleaseLogger
1414
*/
1515
protected $output;
1616

17+
/**
18+
* @var StatisticsEventOutputInterface
19+
*/
20+
protected $statisticsEventOutput;
21+
1722
/**
1823
* @var ContentReleaseIdentifier
1924
*/
@@ -24,10 +29,11 @@ class ContentReleaseLogger
2429
*/
2530
protected $logPrefix = '';
2631

27-
protected function __construct(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, ?RendererIdentifier $rendererIdentifier)
32+
protected function __construct(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput, ?RendererIdentifier $rendererIdentifier)
2833
{
2934
$this->output = $output;
3035
$this->contentReleaseIdentifier = $contentReleaseIdentifier;
36+
$this->statisticsEventOutput = $statisticsEventOutput;
3137
$this->rendererIdentifier = $rendererIdentifier;
3238
$this->logPrefix = '';
3339

@@ -37,14 +43,14 @@ protected function __construct(OutputInterface $output, ContentReleaseIdentifier
3743
}
3844

3945

40-
public static function fromConsoleOutput(ConsoleOutput $output, ContentReleaseIdentifier $contentReleaseIdentifier): self
46+
public static function fromConsoleOutput(ConsoleOutput $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput = new RedisStatisticsEventOutput()): self
4147
{
42-
return new static($output->getOutput(), $contentReleaseIdentifier, null);
48+
return new static($output->getOutput(), $contentReleaseIdentifier, $statisticsEventOutput, null);
4349
}
4450

45-
public static function fromSymfonyOutput(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier): self
51+
public static function fromSymfonyOutput(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput = new RedisStatisticsEventOutput()): self
4652
{
47-
return new static($output, $contentReleaseIdentifier, null);
53+
return new static($output, $contentReleaseIdentifier, $statisticsEventOutput, null);
4854
}
4955

5056
public function debug($message, array $additionalPayload = [])
@@ -72,8 +78,13 @@ public function logException(\Exception $exception, string $message, array $addi
7278
$this->output->writeln($this->logPrefix . $message . "\n\n" . $exception->getMessage() . "\n\n" . $exception->getTraceAsString() . "\n\n" . json_encode($additionalPayload));
7379
}
7480

81+
public function logStatisticsEvent(string $event, array $additionalPayload = [])
82+
{
83+
$this->statisticsEventOutput->writeEvent($this->contentReleaseIdentifier, $this->logPrefix, $event, $additionalPayload);
84+
}
85+
7586
public function withRenderer(RendererIdentifier $rendererIdentifier): self
7687
{
77-
return new ContentReleaseLogger($this->output, $this->contentReleaseIdentifier, $rendererIdentifier);
88+
return new ContentReleaseLogger($this->output, $this->contentReleaseIdentifier, $this->statisticsEventOutput, $rendererIdentifier);
7889
}
7990
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\DecoupledContentStore\Core\Infrastructure;
5+
6+
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
7+
use Flowpack\DecoupledContentStore\Core\RedisKeyService;
8+
use Neos\Flow\Annotations as Flow;
9+
10+
class RedisStatisticsEventOutput implements StatisticsEventOutputInterface
11+
{
12+
13+
#[Flow\Inject]
14+
protected RedisClientManager $redisClientManager;
15+
16+
#[Flow\Inject]
17+
protected RedisKeyService $redisKeyService;
18+
19+
public function writeEvent(ContentReleaseIdentifier $contentReleaseIdentifier, string $prefix, string $event, array $additionalPayload): void
20+
{
21+
$this->redisClientManager->getPrimaryRedis()->rPush($this->redisKeyService->getRedisKeyForPostfix($contentReleaseIdentifier, 'statisticsEvents'), json_encode([
22+
'event' => $event,
23+
'prefix' => $prefix,
24+
'additionalPayload' => $additionalPayload,
25+
]));
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\DecoupledContentStore\Core\Infrastructure;
5+
6+
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
7+
8+
interface StatisticsEventOutputInterface
9+
{
10+
public function writeEvent(ContentReleaseIdentifier $contentReleaseIdentifier, string $prefix, string $event, array $additionalPayload): void;
11+
}

Classes/NodeRendering/Infrastructure/RedisRenderingStatisticsStore.php renamed to Classes/NodeRendering/Infrastructure/RedisRenderingTimeStatisticsStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @Flow\Scope("singleton")
1616
*/
17-
class RedisRenderingStatisticsStore
17+
class RedisRenderingTimeStatisticsStore
1818
{
1919

2020
/**

Classes/NodeRendering/NodeRenderOrchestrator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderingStatistics;
1010
use Flowpack\DecoupledContentStore\NodeRendering\Extensibility\NodeRenderingExtensionManager;
1111
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingErrorManager;
12-
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingStatisticsStore;
12+
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingTimeStatisticsStore;
1313
use Flowpack\DecoupledContentStore\NodeRendering\ProcessEvents\ExitEvent;
1414
use Flowpack\DecoupledContentStore\NodeRendering\ProcessEvents\RenderingIterationCompletedEvent;
1515
use Flowpack\DecoupledContentStore\NodeRendering\ProcessEvents\RenderingQueueFilledEvent;
@@ -70,7 +70,7 @@ class NodeRenderOrchestrator
7070

7171
/**
7272
* @Flow\Inject
73-
* @var RedisRenderingStatisticsStore
73+
* @var RedisRenderingTimeStatisticsStore
7474
*/
7575
protected $redisRenderingStatisticsStore;
7676

Configuration/Settings.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ Flowpack:
136136
transfer: true
137137
transferMode: 'dump'
138138
isRequired: true
139+
statisticsEvents:
140+
redisKeyPostfix: 'statisticsEvents'
141+
transfer: false
142+
transferMode: 'dump'
143+
isRequired: false
139144

140145
# can be used on the consuming site to ensure non-breaking deployments for changes in the config
141146
configEpoch:

0 commit comments

Comments
 (0)