Class ExponentialHistogramMerger
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.lucene.util.Accountable,Releasable
ExponentialHistogram into a single one
while keeping the bucket count in the result below a given limit.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ExponentialHistogram toAdd) Merges the given histogram into the current result.voidclose()static ExponentialHistogramMergercreate(int bucketLimit, ExponentialHistogramCircuitBreaker circuitBreaker) Creates a new instance with the specified bucket limit.static ExponentialHistogramMergercreate(ExponentialHistogramCircuitBreaker circuitBreaker) Creates a new instance with the OpenTelemetry SDK default bucket limit ofDEFAULT_MAX_HISTOGRAM_BUCKETS.createFactory(int bucketLimit, ExponentialHistogramCircuitBreaker circuitBreaker) Creates a new factory with the specified bucket limit.createFactory(ExponentialHistogramCircuitBreaker circuitBreaker) Creates a new factory with the OpenTelemetry SDK default bucket limit ofDEFAULT_MAX_HISTOGRAM_BUCKETS.static ExponentialHistogramMergercreateWithMaxScale(int bucketLimit, int maxScale, ExponentialHistogramCircuitBreaker circuitBreaker) get()Gets the current merged histogram without clearing this merger.Returns the merged histogram and clears this merger.longbooleanClears this merger and sets it to the histogramaminus the histogramb.voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Field Details
-
DEFAULT_MAX_HISTOGRAM_BUCKETS
public static final int DEFAULT_MAX_HISTOGRAM_BUCKETS- See Also:
-
-
Method Details
-
createFactory
public static ExponentialHistogramMerger.Factory createFactory(ExponentialHistogramCircuitBreaker circuitBreaker) Creates a new factory with the OpenTelemetry SDK default bucket limit ofDEFAULT_MAX_HISTOGRAM_BUCKETS.- Parameters:
circuitBreaker- the circuit breaker to use to limit memory allocations
-
createFactory
public static ExponentialHistogramMerger.Factory createFactory(int bucketLimit, ExponentialHistogramCircuitBreaker circuitBreaker) Creates a new factory with the specified bucket limit.- Parameters:
bucketLimit- the maximum number of buckets the result histogram is allowed to have, must be at least 4circuitBreaker- the circuit breaker to use to limit memory allocations
-
create
Creates a new instance with the OpenTelemetry SDK default bucket limit ofDEFAULT_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 4circuitBreaker- 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReleasable
-
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceorg.apache.lucene.util.Accountable
-
getAndClear
Returns the merged histogram and clears this merger. The caller takes ownership of the returned histogram and must ensure thatclose()is called.- Returns:
- the merged histogram
-
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 toadd(ExponentialHistogram), or until the merger is closed.- Returns:
- the current merged histogram
-
add
Merges the given histogram into the current result.- Parameters:
toAdd- the histogram to merge
-
setToMerged
-
setToDifference
Clears this merger and sets it to the histogramaminus the histogramb.This method is intended to compute the delta between two cumulative histograms from the same time series, where
ais a later snapshot andbis an earlier snapshot. In cumulative histograms, bucket counts only increase over time, which means that subtractingbfromashould never result in negative bucket counts. Note that this algorithm still is capable of dealing with cases where the histograms seem to be cumulative (a.count() >= b.count()), but actually are not. In this case the negative buckets will be clamped to a count of0and the remaining populate buckets will have their count scaled down to compensate for this.The algorithm provides the following guarantees if the histograms are actually cumulative: Given two exponential histograms
bandc. The histogramais the result of merging the histogramsbandc. Thena - bwill yield the histogramc, with the limitation thata - bmight have a smaller scale (=less precision) thanc(but no lower than the scale ofa)a - bmight have a greater zero threshold thanc(but not greater than the zero threshold ofa)a - bmight not preserve the exact minimum / maximum ofc, but will provide an estimate in that case
If the histograms are not cumulative, the following guarantees are provided instead:
result.valueCount()will be exactlya.valueCount() - b.valueCount()result.sum()will be exactlya.sum() - b.count()result.min()andresult.max()will be sane values (e.g. not outside the min/max values of the inputs)- Each bucket in the result will correspond to input buckets where the
count for
awas greater than the count ofb
- Parameters:
a- the base histogram to subtract fromb- the histogram to be subtracted- Returns:
- true if the histograms were actually cumulative and the result is the exact difference, false if the histograms were not cumulative and the result only provides the weaker guarantees explained above
-