Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

FixedSizeReservoir.php

Namespace

OpenTelemetry\SDK\Metrics\Exemplar

File

vendor/open-telemetry/sdk/Metrics/Exemplar/FixedSizeReservoir.php

View source
<?php

declare (strict_types=1);
namespace OpenTelemetry\SDK\Metrics\Exemplar;

use OpenTelemetry\Context\ContextInterface;
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
use function random_int;
final class FixedSizeReservoir implements ExemplarReservoirInterface {
    private readonly BucketStorage $storage;
    private readonly int $size;
    private int $measurements = 0;
    public function __construct(int $size = 4) {
        $this->storage = new BucketStorage($size);
        $this->size = $size;
    }
    public function offer($index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp) : void {
        $bucket = random_int(0, $this->measurements);
        $this->measurements++;
        if ($bucket < $this->size) {
            $this->storage
                ->store($bucket, $index, $value, $attributes, $context, $timestamp);
        }
    }
    public function collect(array $dataPointAttributes) : array {
        $this->measurements = 0;
        return $this->storage
            ->collect($dataPointAttributes);
    }

}

Classes

Title Deprecated Summary
FixedSizeReservoir

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal