summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php')
-rw-r--r--vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php b/vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php
new file mode 100644
index 000000000..b56a1b2be
--- /dev/null
+++ b/vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php
@@ -0,0 +1,40 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\SDK\Metrics\Exemplar;
+
+use function count;
+use OpenTelemetry\Context\ContextInterface;
+use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
+
+final class HistogramBucketReservoir implements ExemplarReservoirInterface
+{
+ private BucketStorage $storage;
+ /**
+ * @var list<float|int>
+ */
+ private array $boundaries;
+
+ /**
+ * @param list<float|int> $boundaries
+ */
+ public function __construct(array $boundaries)
+ {
+ $this->storage = new BucketStorage(count($boundaries) + 1);
+ $this->boundaries = $boundaries;
+ }
+
+ public function offer($index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void
+ {
+ $boundariesCount = count($this->boundaries);
+ for ($i = 0; $i < $boundariesCount && $this->boundaries[$i] < $value; $i++) {
+ }
+ $this->storage->store($i, $index, $value, $attributes, $context, $timestamp);
+ }
+
+ public function collect(array $dataPointAttributes): array
+ {
+ return $this->storage->collect($dataPointAttributes);
+ }
+}