From cdd7ad020e165fe680703b6d3319b908b682fb7a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 20 Oct 2023 17:12:29 +0300 Subject: jaeger-client -> opentelemetry --- .../sdk/Metrics/View/CriteriaViewRegistry.php | 40 +++++++++++ .../Metrics/View/SelectionCriteria/AllCriteria.php | 33 ++++++++++ .../SelectionCriteria/InstrumentNameCriteria.php | 28 ++++++++ .../SelectionCriteria/InstrumentTypeCriteria.php | 29 ++++++++ .../InstrumentationScopeNameCriteria.php | 24 +++++++ .../InstrumentationScopeSchemaUrlCriteria.php | 24 +++++++ .../InstrumentationScopeVersionCriteria.php | 24 +++++++ .../Metrics/View/SelectionCriteriaInterface.php | 13 ++++ .../sdk/Metrics/View/ViewTemplate.php | 77 ++++++++++++++++++++++ 9 files changed, 292 insertions(+) create mode 100644 vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/ViewTemplate.php (limited to 'vendor/open-telemetry/sdk/Metrics/View') diff --git a/vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php b/vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php new file mode 100644 index 000000000..f387abf9c --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php @@ -0,0 +1,40 @@ + */ + private array $criteria = []; + /** @var list */ + private array $views = []; + + public function register(SelectionCriteriaInterface $criteria, ViewTemplate $view): void + { + $this->criteria[] = $criteria; + $this->views[] = $view; + } + + public function find(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): ?iterable + { + $views = $this->generateViews($instrument, $instrumentationScope); + + return $views->valid() ? $views : null; + } + + private function generateViews(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): Generator + { + foreach ($this->criteria as $i => $criteria) { + if ($criteria->accepts($instrument, $instrumentationScope)) { + yield $this->views[$i]->project($instrument); + } + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php new file mode 100644 index 000000000..438297324 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php @@ -0,0 +1,33 @@ + $criteria + */ + public function __construct(iterable $criteria) + { + $this->criteria = $criteria; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + foreach ($this->criteria as $criterion) { + if (!$criterion->accepts($instrument, $instrumentationScope)) { + return false; + } + } + + return true; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php new file mode 100644 index 000000000..ed6034755 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php @@ -0,0 +1,28 @@ +pattern = sprintf('/^%s$/', strtr(preg_quote($name, '/'), ['\\?' => '.', '\\*' => '.*'])); + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return (bool) preg_match($this->pattern, $instrument->name); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php new file mode 100644 index 000000000..46a88def0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php @@ -0,0 +1,29 @@ +instrumentTypes = (array) $instrumentType; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return in_array($instrument->type, $this->instrumentTypes, true); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php new file mode 100644 index 000000000..201d1a7b2 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php @@ -0,0 +1,24 @@ +name = $name; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return $this->name === $instrumentationScope->getName(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php new file mode 100644 index 000000000..a11a1d589 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php @@ -0,0 +1,24 @@ +schemaUrl = $schemaUrl; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return $this->schemaUrl === $instrumentationScope->getSchemaUrl(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php new file mode 100644 index 000000000..37d180f99 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php @@ -0,0 +1,24 @@ +version = $version; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return $this->version === $instrumentationScope->getVersion(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php new file mode 100644 index 000000000..8abd6fa69 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php @@ -0,0 +1,13 @@ + + */ + private ?array $attributeKeys = null; + private ?AggregationInterface $aggregation = null; + + private function __construct() + { + } + + public static function create(): self + { + static $instance; + + return $instance ??= new self(); + } + + public function withName(string $name): self + { + $self = clone $this; + $self->name = $name; + + return $self; + } + + public function withDescription(string $description): self + { + $self = clone $this; + $self->description = $description; + + return $self; + } + + /** + * @param list $attributeKeys + */ + public function withAttributeKeys(array $attributeKeys): self + { + $self = clone $this; + $self->attributeKeys = $attributeKeys; + + return $self; + } + + public function withAggregation(?AggregationInterface $aggregation): self + { + $self = clone $this; + $self->aggregation = $aggregation; + + return $self; + } + + public function project(Instrument $instrument): ViewProjection + { + return new ViewProjection( + $this->name ?? $instrument->name, + $instrument->unit, + $this->description ?? $instrument->description, + $this->attributeKeys, + $this->aggregation, + ); + } +} -- cgit v1.2.3