Class ExponentialHistogramMerger

java.lang.Object
org.elasticsearch.exponentialhistogram.ExponentialHistogramMerger
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.lucene.util.Accountable, Releasable

public class ExponentialHistogramMerger extends Object implements org.apache.lucene.util.Accountable, Releasable
Allows accumulating multiple ExponentialHistogram into a single one while keeping the bucket count in the result below a given limit.
  • Method Details

    • create

      public static ExponentialHistogramMerger create(ExponentialHistogramCircuitBreaker circuitBreaker)
      Creates a new instance with the OpenTelemetry SDK default bucket limit of MAX_HISTOGRAM_BUCKETS
      Parameters:
      circuitBreaker - the circuit breaker to use to limit memory allocations
    • create

      public static ExponentialHistogramMerger create(int bucketLimit, ExponentialHistogramCircuitBreaker circuitBreaker)
      Creates a new instance with the specified bucket limit.
      Parameters:
      bucketLimit - the maximum number of buckets the result histogram is allowed to have, must be at least 4
      circuitBreaker - the circuit breaker to use to limit memory allocations
    • createWithMaxScale

      public static ExponentialHistogramMerger createWithMaxScale(int bucketLimit, int maxScale, ExponentialHistogramCircuitBreaker circuitBreaker)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface org.apache.lucene.util.Accountable
    • getAndClear

      public ReleasableExponentialHistogram getAndClear()
      Returns the merged histogram and clears this merger. The caller takes ownership of the returned histogram and must ensure that close() is called.
      Returns:
      the merged histogram
    • get

      public ExponentialHistogram get()
      Gets the current merged histogram without clearing this merger. Note that the ownership of the returned histogram remains with this merger, so the caller must not close it. The returned histogram is only valid until the next call to add(ExponentialHistogram), or until the merger is closed.
      Returns:
      the current merged histogram
    • addWithoutUpscaling

      public void addWithoutUpscaling(ExponentialHistogram toAdd)
      Merges the given histogram into the current result, not upscaling it. This should be used when merging intermediate results to prevent accumulating errors.
      Parameters:
      toAdd - the histogram to merge
    • add

      public void add(ExponentialHistogram toAdd)
      Merges the given histogram into the current result. The histogram might be upscaled if needed.
      Parameters:
      toAdd - the histogram to merge