Skip to content

Commit

Permalink
support 0.4 metric reader config
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Dec 11, 2024
1 parent 9b0749e commit 2619859
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 366 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterConsole",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterOtlp",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricReaderPeriodic",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricReaderPull",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Logs\\LogRecordExporterConsole",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Logs\\LogRecordExporterOtlp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit
->end()
->booleanNode('record_min_max')->defaultValue(false)->end()
->end();

return $node;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class MetricReaderPeriodic implements ComponentProvider
* interval: int<0, max>,
* timeout: int<0, max>,
* exporter: ComponentPlugin<MetricExporterInterface>,
* producers: array,
* } $properties
*/
public function createPlugin(array $properties, Context $context): MetricReaderInterface
Expand All @@ -41,6 +42,8 @@ public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinit
->integerNode('interval')->min(0)->defaultValue(5000)->end()
->integerNode('timeout')->min(0)->defaultValue(30000)->end()
->append($registry->component('exporter', MetricExporterInterface::class)->isRequired())
->arrayNode('producers') //@todo
->variablePrototype()->end()
->end()
;

Expand Down
46 changes: 46 additions & 0 deletions src/Config/SDK/ComponentProvider/Metrics/MetricReaderPull.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Config\SDK\ComponentProvider\Metrics;

use OpenTelemetry\Config\SDK\Configuration\ComponentPlugin;
use OpenTelemetry\Config\SDK\Configuration\ComponentProvider;
use OpenTelemetry\Config\SDK\Configuration\ComponentProviderRegistry;
use OpenTelemetry\Config\SDK\Configuration\Context;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use OpenTelemetry\SDK\Metrics\MetricReader\NoopReader;
use OpenTelemetry\SDK\Metrics\MetricReaderInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

/**
* @implements ComponentProvider<MetricReaderInterface>
*/
final class MetricReaderPull implements ComponentProvider
{

/**
* @param array{
* exporter: ComponentPlugin<MetricExporterInterface>,
* producers: array,
* } $properties
*/
public function createPlugin(array $properties, Context $context): MetricReaderInterface
{
return new NoopReader();
}

public function getConfig(ComponentProviderRegistry $registry): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('pull');
$node
->children()
->append($registry->component('exporter', MetricExporterInterface::class)->isRequired())
->arrayNode('producers') //@todo
->variablePrototype()->end()
->end()
;

return $node;
}
}
28 changes: 9 additions & 19 deletions src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ final class OpenTelemetrySdk implements ComponentProvider
* resource: array{
* attributes: array,
* attributes_list: ?string,
<<<<<<< HEAD
* detectors: array,
=======
>>>>>>> main
* schema_url: ?string,
* },
* attribute_limits: array{
Expand Down Expand Up @@ -356,6 +353,14 @@ private function getMeterProviderConfig(ComponentProviderRegistry $registry): Ar
$node
->addDefaultsIfNotSet()
->children()
->enumNode('exemplar_filter')
->values([
'trace_based',
'always_on',
'always_off',
])
->defaultValue('trace_based')
->end()
->arrayNode('views')
->arrayPrototype()
->children()
Expand Down Expand Up @@ -401,22 +406,7 @@ private function getMeterProviderConfig(ComponentProviderRegistry $registry): Ar
->end()
->end()
->end()
->arrayNode('readers')
->arrayPrototype()
->children()
->arrayNode('pull')
->variablePrototype()->end()
->end()
->arrayNode('periodic')
->variablePrototype()->end()
->end()
->arrayNode('producers')
->variablePrototype()->end()
->end()
->end()
->end()
->end()
//->append($registry->componentArrayList('readers', MetricReaderInterface::class))
->append($registry->componentArrayList('readers', MetricReaderInterface::class))
->end()
;

Expand Down
4 changes: 4 additions & 0 deletions src/Config/SDK/Configuration/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public static function ensureString(): Closure
};
}

/**
* @psalm-suppress InvalidReturnType,InvalidReturnStatement
*/
public static function ensureNumber(): Closure
{

return static function (mixed $value): null|int|float {
if ($value === null) {
return null;
Expand Down
1 change: 1 addition & 0 deletions src/Config/SDK/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterConsole",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricExporterOtlp",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricReaderPeriodic",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Metrics\\MetricReaderPull",

"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Logs\\LogRecordExporterConsole",
"OpenTelemetry\\Config\\SDK\\ComponentProvider\\Logs\\LogRecordExporterOtlp",
Expand Down
26 changes: 26 additions & 0 deletions src/SDK/Metrics/MetricReader/NoopReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Metrics\MetricReader;

use OpenTelemetry\SDK\Metrics\MetricReaderInterface;

class NoopReader implements MetricReaderInterface
{

public function collect(): bool
{
return true;
}

public function shutdown(): bool
{
return true;
}

public function forceFlush(): bool
{
return true;
}
}
Loading

0 comments on commit 2619859

Please sign in to comment.