Skip to content

Commit a768025

Browse files
sacheraPingu501
authored andcommitted
FEATURE: Add statistics event logging to ContentReleaseLogger
1 parent bc9af0c commit a768025

8 files changed

Lines changed: 98 additions & 10 deletions

File tree

Classes/BackendUi/BackendUiDataService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderingStatistics;
1515
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingErrorManager;
1616
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingStatisticsStore;
17+
use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingTimeStatisticsStore;
1718
use Flowpack\DecoupledContentStore\PrepareContentRelease\Dto\ContentReleaseMetadata;
1819
use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService;
1920
use Flowpack\DecoupledContentStore\ReleaseSwitch\Infrastructure\RedisReleaseSwitchService;
@@ -45,7 +46,7 @@ class BackendUiDataService
4546

4647
/**
4748
* @Flow\Inject
48-
* @var RedisRenderingStatisticsStore
49+
* @var RedisRenderingTimeStatisticsStore
4950
*/
5051
protected $redisRenderingStatisticsStore;
5152

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
*/
@@ -23,10 +28,11 @@ class ContentReleaseLogger
2328

2429
protected ?RendererIdentifier $rendererIdentifier;
2530

26-
protected function __construct(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, ?RendererIdentifier $rendererIdentifier)
31+
protected function __construct(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput, ?RendererIdentifier $rendererIdentifier)
2732
{
2833
$this->output = $output;
2934
$this->contentReleaseIdentifier = $contentReleaseIdentifier;
35+
$this->statisticsEventOutput = $statisticsEventOutput;
3036
$this->rendererIdentifier = $rendererIdentifier;
3137
$this->logPrefix = '';
3238

@@ -36,14 +42,14 @@ protected function __construct(OutputInterface $output, ContentReleaseIdentifier
3642
}
3743

3844

39-
public static function fromConsoleOutput(ConsoleOutput $output, ContentReleaseIdentifier $contentReleaseIdentifier): self
45+
public static function fromConsoleOutput(ConsoleOutput $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput = new RedisStatisticsEventOutput()): self
4046
{
41-
return new static($output->getOutput(), $contentReleaseIdentifier, null);
47+
return new static($output->getOutput(), $contentReleaseIdentifier, $statisticsEventOutput, null);
4248
}
4349

44-
public static function fromSymfonyOutput(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier): self
50+
public static function fromSymfonyOutput(OutputInterface $output, ContentReleaseIdentifier $contentReleaseIdentifier, StatisticsEventOutputInterface $statisticsEventOutput = new RedisStatisticsEventOutput()): self
4551
{
46-
return new static($output, $contentReleaseIdentifier, null);
52+
return new static($output, $contentReleaseIdentifier, $statisticsEventOutput, null);
4753
}
4854

4955
public function debug(string $message, array $additionalPayload = []): void
@@ -77,8 +83,13 @@ public function logException(\Exception $exception, string $message, array $addi
7783
$this->output->writeln($this->logPrefix . $message . "\n\n" . $exception->getMessage() . "\n\n" . $exception->getTraceAsString() . "\n\n" . json_encode($additionalPayload));
7884
}
7985

86+
public function logStatisticsEvent(string $event, array $additionalPayload = [])
87+
{
88+
$this->statisticsEventOutput->writeEvent($this->contentReleaseIdentifier, $this->logPrefix, $event, $additionalPayload);
89+
}
90+
8091
public function withRenderer(RendererIdentifier $rendererIdentifier): self
8192
{
82-
return new ContentReleaseLogger($this->output, $this->contentReleaseIdentifier, $rendererIdentifier);
93+
return new ContentReleaseLogger($this->output, $this->contentReleaseIdentifier, $this->statisticsEventOutput, $rendererIdentifier);
8394
}
8495
}
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
@@ -142,6 +142,11 @@ Flowpack:
142142
transfer: true
143143
transferMode: 'dump'
144144
isRequired: true
145+
statisticsEvents:
146+
redisKeyPostfix: 'statisticsEvents'
147+
transfer: false
148+
transferMode: 'dump'
149+
isRequired: false
145150

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

0 commit comments

Comments
 (0)