With all the operations on the Aggregator, no need to define Accumulation (#2462)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
1d8c0d9229
commit
757cd79889
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.api.metrics.AsynchronousInstrument;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import java.util.List;
|
||||
|
|
@ -19,7 +18,7 @@ final class AsynchronousInstrumentAccumulator {
|
|||
private final InstrumentProcessor<?> instrumentProcessor;
|
||||
private final Runnable metricUpdater;
|
||||
|
||||
static <T extends Accumulation> AsynchronousInstrumentAccumulator doubleAsynchronousAccumulator(
|
||||
static <T> AsynchronousInstrumentAccumulator doubleAsynchronousAccumulator(
|
||||
InstrumentProcessor<T> instrumentProcessor,
|
||||
@Nullable Consumer<AsynchronousInstrument.DoubleResult> metricUpdater) {
|
||||
// TODO: Decide what to do with null updater.
|
||||
|
|
@ -35,7 +34,7 @@ final class AsynchronousInstrumentAccumulator {
|
|||
instrumentProcessor, () -> metricUpdater.accept(result));
|
||||
}
|
||||
|
||||
static <T extends Accumulation> AsynchronousInstrumentAccumulator longAsynchronousAccumulator(
|
||||
static <T> AsynchronousInstrumentAccumulator longAsynchronousAccumulator(
|
||||
InstrumentProcessor<T> instrumentProcessor,
|
||||
@Nullable Consumer<AsynchronousInstrument.LongResult> metricUpdater) {
|
||||
// TODO: Decide what to do with null updater.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.sdk.metrics;
|
|||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.Clock;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -25,10 +24,9 @@ import java.util.Objects;
|
|||
* batches together {@code Aggregator}s for the similar sets of labels.
|
||||
*
|
||||
* <p>An entire collection cycle must be protected by a lock. A collection cycle is defined by
|
||||
* multiple calls to {@link #batch(Labels, Accumulation)} followed by one {@link
|
||||
* #completeCollectionCycle()};
|
||||
* multiple calls to {@code #batch(...)} followed by one {@link #completeCollectionCycle()};
|
||||
*/
|
||||
final class InstrumentProcessor<T extends Accumulation> {
|
||||
final class InstrumentProcessor<T> {
|
||||
private final InstrumentDescriptor descriptor;
|
||||
private final Aggregator<T> aggregator;
|
||||
private final Resource resource;
|
||||
|
|
@ -43,7 +41,7 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
* aggregation. "Cumulative" means that all metrics that are generated will be considered for the
|
||||
* lifetime of the Instrument being aggregated.
|
||||
*/
|
||||
static <T extends Accumulation> InstrumentProcessor<T> getCumulativeAllLabels(
|
||||
static <T> InstrumentProcessor<T> getCumulativeAllLabels(
|
||||
InstrumentDescriptor descriptor,
|
||||
MeterProviderSharedState meterProviderSharedState,
|
||||
MeterSharedState meterSharedState,
|
||||
|
|
@ -62,7 +60,7 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
* aggregation. "Delta" means that all metrics that are generated are only for the most recent
|
||||
* collection interval.
|
||||
*/
|
||||
static <T extends Accumulation> InstrumentProcessor<T> getDeltaAllLabels(
|
||||
static <T> InstrumentProcessor<T> getDeltaAllLabels(
|
||||
InstrumentDescriptor descriptor,
|
||||
MeterProviderSharedState meterProviderSharedState,
|
||||
MeterSharedState meterSharedState,
|
||||
|
|
@ -98,7 +96,7 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
* the {@link Labels} and merge aggregations together.
|
||||
*
|
||||
* @param labelSet the {@link Labels} associated with this {@code Aggregator}.
|
||||
* @param accumulation the {@link Accumulation} produced by this instrument.
|
||||
* @param accumulation the accumulation produced by this instrument.
|
||||
*/
|
||||
void batch(Labels labelSet, T accumulation) {
|
||||
T currentAccumulation = accumulationMap.get(labelSet);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorHandle;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -16,7 +15,7 @@ import java.util.Objects;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
final class SynchronousInstrumentAccumulator<T extends Accumulation> {
|
||||
final class SynchronousInstrumentAccumulator<T> {
|
||||
private final ConcurrentHashMap<Labels, AggregatorHandle<T>> aggregatorLabels;
|
||||
private final ReentrantLock collectLock;
|
||||
private final Aggregator<T> aggregator;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -84,7 +83,7 @@ final class ViewRegistry {
|
|||
}
|
||||
|
||||
/** Create a new {@link InstrumentProcessor} for use in metric recording aggregation. */
|
||||
<T extends Accumulation> InstrumentProcessor<T> createBatcher(
|
||||
<T> InstrumentProcessor<T> createBatcher(
|
||||
MeterProviderSharedState meterProviderSharedState,
|
||||
MeterSharedState meterSharedState,
|
||||
InstrumentDescriptor descriptor) {
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.accumulation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/** An immutable representation of an accumulated value by an {@code Aggregator}. */
|
||||
@Immutable
|
||||
public interface Accumulation {
|
||||
/**
|
||||
* Returns the {@code Point} with the given properties and the value from this Accumulation.
|
||||
*
|
||||
* @param startEpochNanos the startEpochNanos for the {@code Point}.
|
||||
* @param epochNanos the epochNanos for the {@code Point}.
|
||||
* @param labels the labels for the {@code Point}.
|
||||
* @return the {@code Point} with the value from this Aggregation.
|
||||
*/
|
||||
MetricData.Point toPoint(long startEpochNanos, long epochNanos, Labels labels);
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.accumulation;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/** Accumulation that holds a {@code double} value. */
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class DoubleAccumulation implements Accumulation {
|
||||
/**
|
||||
* Creates a new {@link DoubleAccumulation} with the given {@code value}.
|
||||
*
|
||||
* @param value the value of this accumulation.
|
||||
* @return a new {@link DoubleAccumulation} with the given {@code value}.
|
||||
*/
|
||||
public static DoubleAccumulation create(double value) {
|
||||
return new AutoValue_DoubleAccumulation(value);
|
||||
}
|
||||
|
||||
DoubleAccumulation() {}
|
||||
|
||||
/**
|
||||
* Returns the {@code double} value stored by this {@link Accumulation}.
|
||||
*
|
||||
* @return the {@code double} value stored by this {@link Accumulation}.
|
||||
*/
|
||||
public abstract double getValue();
|
||||
|
||||
@Override
|
||||
public MetricData.DoublePoint toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return MetricData.DoublePoint.create(startEpochNanos, epochNanos, labels, getValue());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.accumulation;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/** Accumulation that holds a {@code long} value. */
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class LongAccumulation implements Accumulation {
|
||||
/**
|
||||
* Creates a new {@link LongAccumulation} with the given {@code value}.
|
||||
*
|
||||
* @param value the value of this accumulation.
|
||||
* @return a new {@link LongAccumulation} with the given {@code value}.
|
||||
*/
|
||||
public static LongAccumulation create(long value) {
|
||||
return new AutoValue_LongAccumulation(value);
|
||||
}
|
||||
|
||||
LongAccumulation() {}
|
||||
|
||||
/**
|
||||
* Returns the {@code long} value stored by this {@link Accumulation}.
|
||||
*
|
||||
* @return the {@code long} value stored by this {@link Accumulation}.
|
||||
*/
|
||||
public abstract long getValue();
|
||||
|
||||
@Override
|
||||
public MetricData.LongPoint toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return MetricData.LongPoint.create(startEpochNanos, epochNanos, labels, getValue());
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -24,7 +23,7 @@ import javax.annotation.concurrent.Immutable;
|
|||
* #accumulateLong(long)} will be used when reading values from the instrument callbacks.
|
||||
*/
|
||||
@Immutable
|
||||
public interface Aggregator<T extends Accumulation> {
|
||||
public interface Aggregator<T> {
|
||||
|
||||
// TODO: Move all getInstance methods here as static methods and make the implementations package
|
||||
// protected.
|
||||
|
|
@ -62,9 +61,9 @@ public interface Aggregator<T extends Accumulation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the result of the merge of the given {@link Accumulation}s.
|
||||
* Returns the result of the merge of the given accumulations.
|
||||
*
|
||||
* @return the result of the merge of the given {@link Accumulation}s.
|
||||
* @return the result of the merge of the given accumulations.
|
||||
*/
|
||||
T merge(T a1, T a2);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
|
|
@ -61,5 +60,5 @@ public interface AggregatorFactory {
|
|||
* @param instrumentValueType the type of recorded values for the {@code Instrument}.
|
||||
* @return a new {@link Aggregator}.
|
||||
*/
|
||||
<T extends Accumulation> Aggregator<T> create(InstrumentValueType instrumentValueType);
|
||||
<T> Aggregator<T> create(InstrumentValueType instrumentValueType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
|
@ -24,7 +23,7 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
* of the bits are used for reference (usage) counting.
|
||||
*/
|
||||
@ThreadSafe
|
||||
public abstract class AggregatorHandle<T extends Accumulation> {
|
||||
public abstract class AggregatorHandle<T> {
|
||||
// Atomically counts the number of references (usages) while also keeping a state of
|
||||
// mapped/unmapped into a registry map.
|
||||
private final AtomicLong refCountMapped;
|
||||
|
|
@ -72,8 +71,8 @@ public abstract class AggregatorHandle<T extends Accumulation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the current value into as {@link Accumulation} and resets the current value in this
|
||||
* {@code Aggregator}.
|
||||
* Returns the current value into as {@link T} and resets the current value in this {@code
|
||||
* Aggregator}.
|
||||
*/
|
||||
@Nullable
|
||||
public final T accumulateThenReset() {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -17,38 +16,38 @@ import java.util.concurrent.atomic.LongAdder;
|
|||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
@ThreadSafe
|
||||
public final class CountAggregator implements Aggregator<LongAccumulation> {
|
||||
private static final Aggregator<LongAccumulation> INSTANCE = new CountAggregator();
|
||||
public final class CountAggregator implements Aggregator<Long> {
|
||||
private static final Aggregator<Long> INSTANCE = new CountAggregator();
|
||||
|
||||
/**
|
||||
* Returns the instance of this {@link Aggregator}.
|
||||
*
|
||||
* @return the instance of this {@link Aggregator}.
|
||||
*/
|
||||
public static Aggregator<LongAccumulation> getInstance() {
|
||||
public static Aggregator<Long> getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private CountAggregator() {}
|
||||
|
||||
@Override
|
||||
public AggregatorHandle<LongAccumulation> createHandle() {
|
||||
public AggregatorHandle<Long> createHandle() {
|
||||
return new Handle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation accumulateDouble(double value) {
|
||||
return LongAccumulation.create(1);
|
||||
public Long accumulateDouble(double value) {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation accumulateLong(long value) {
|
||||
return LongAccumulation.create(1);
|
||||
public Long accumulateLong(long value) {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
return LongAccumulation.create(a1.getValue() + a2.getValue());
|
||||
public Long merge(Long a1, Long a2) {
|
||||
return a1 + a2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -56,7 +55,7 @@ public final class CountAggregator implements Aggregator<LongAccumulation> {
|
|||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
Map<Labels, Long> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
|
|
@ -72,7 +71,7 @@ public final class CountAggregator implements Aggregator<LongAccumulation> {
|
|||
/* isMonotonic= */ true, MetricData.AggregationTemporality.CUMULATIVE, points));
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<LongAccumulation> {
|
||||
static final class Handle extends AggregatorHandle<Long> {
|
||||
private final LongAdder current = new LongAdder();
|
||||
|
||||
private Handle() {}
|
||||
|
|
@ -88,8 +87,8 @@ public final class CountAggregator implements Aggregator<LongAccumulation> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected LongAccumulation doAccumulateThenReset() {
|
||||
return LongAccumulation.create(current.sumThenReset());
|
||||
protected Long doAccumulateThenReset() {
|
||||
return current.sumThenReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.DoubleAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -26,7 +25,7 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||
* values once.
|
||||
*/
|
||||
@ThreadSafe
|
||||
public final class DoubleLastValueAggregator implements Aggregator<DoubleAccumulation> {
|
||||
public final class DoubleLastValueAggregator implements Aggregator<Double> {
|
||||
private static final DoubleLastValueAggregator INSTANCE = new DoubleLastValueAggregator();
|
||||
|
||||
/**
|
||||
|
|
@ -41,17 +40,17 @@ public final class DoubleLastValueAggregator implements Aggregator<DoubleAccumul
|
|||
private DoubleLastValueAggregator() {}
|
||||
|
||||
@Override
|
||||
public AggregatorHandle<DoubleAccumulation> createHandle() {
|
||||
public AggregatorHandle<Double> createHandle() {
|
||||
return new Handle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleAccumulation accumulateDouble(double value) {
|
||||
return DoubleAccumulation.create(value);
|
||||
public Double accumulateDouble(double value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleAccumulation merge(DoubleAccumulation a1, DoubleAccumulation a2) {
|
||||
public Double merge(Double a1, Double a2) {
|
||||
// TODO: Define the order between accumulation.
|
||||
return a2;
|
||||
}
|
||||
|
|
@ -61,7 +60,7 @@ public final class DoubleLastValueAggregator implements Aggregator<DoubleAccumul
|
|||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, DoubleAccumulation> accumulationByLabels,
|
||||
Map<Labels, Double> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoublePoint> points =
|
||||
|
|
@ -89,15 +88,15 @@ public final class DoubleLastValueAggregator implements Aggregator<DoubleAccumul
|
|||
return null;
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<DoubleAccumulation> {
|
||||
static final class Handle extends AggregatorHandle<Double> {
|
||||
@Nullable private static final Double DEFAULT_VALUE = null;
|
||||
private final AtomicReference<Double> current = new AtomicReference<>(DEFAULT_VALUE);
|
||||
|
||||
private Handle() {}
|
||||
|
||||
@Override
|
||||
protected DoubleAccumulation doAccumulateThenReset() {
|
||||
return DoubleAccumulation.create(this.current.getAndSet(DEFAULT_VALUE));
|
||||
protected Double doAccumulateThenReset() {
|
||||
return this.current.getAndSet(DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.DoubleAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -16,7 +15,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.DoubleAdder;
|
||||
|
||||
public final class DoubleSumAggregator implements Aggregator<DoubleAccumulation> {
|
||||
public final class DoubleSumAggregator implements Aggregator<Double> {
|
||||
private static final DoubleSumAggregator INSTANCE = new DoubleSumAggregator();
|
||||
|
||||
/**
|
||||
|
|
@ -24,25 +23,25 @@ public final class DoubleSumAggregator implements Aggregator<DoubleAccumulation>
|
|||
*
|
||||
* @return the instance of this {@link Aggregator}.
|
||||
*/
|
||||
public static Aggregator<DoubleAccumulation> getInstance() {
|
||||
public static Aggregator<Double> getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private DoubleSumAggregator() {}
|
||||
|
||||
@Override
|
||||
public AggregatorHandle<DoubleAccumulation> createHandle() {
|
||||
public AggregatorHandle<Double> createHandle() {
|
||||
return new Handle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleAccumulation accumulateDouble(double value) {
|
||||
return DoubleAccumulation.create(value);
|
||||
public Double accumulateDouble(double value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DoubleAccumulation merge(DoubleAccumulation a1, DoubleAccumulation a2) {
|
||||
return DoubleAccumulation.create(a1.getValue() + a2.getValue());
|
||||
public final Double merge(Double a1, Double a2) {
|
||||
return a1 + a2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -50,7 +49,7 @@ public final class DoubleSumAggregator implements Aggregator<DoubleAccumulation>
|
|||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, DoubleAccumulation> accumulationByLabels,
|
||||
Map<Labels, Double> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoublePoint> points =
|
||||
|
|
@ -62,12 +61,12 @@ public final class DoubleSumAggregator implements Aggregator<DoubleAccumulation>
|
|||
resource, instrumentationLibraryInfo, descriptor, points, isMonotonic);
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<DoubleAccumulation> {
|
||||
static final class Handle extends AggregatorHandle<Double> {
|
||||
private final DoubleAdder current = new DoubleAdder();
|
||||
|
||||
@Override
|
||||
protected DoubleAccumulation doAccumulateThenReset() {
|
||||
return DoubleAccumulation.create(this.current.sumThenReset());
|
||||
protected Double doAccumulateThenReset() {
|
||||
return this.current.sumThenReset();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,13 +5,11 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class ImmutableAggregatorFactory<L extends Accumulation, D extends Accumulation>
|
||||
implements AggregatorFactory {
|
||||
final class ImmutableAggregatorFactory<L, D> implements AggregatorFactory {
|
||||
static final AggregatorFactory SUM =
|
||||
new ImmutableAggregatorFactory<>(
|
||||
LongSumAggregator.getInstance(), DoubleSumAggregator.getInstance());
|
||||
|
|
@ -38,7 +36,7 @@ final class ImmutableAggregatorFactory<L extends Accumulation, D extends Accumul
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Accumulation> Aggregator<T> create(InstrumentValueType instrumentValueType) {
|
||||
public <T> Aggregator<T> create(InstrumentValueType instrumentValueType) {
|
||||
switch (instrumentValueType) {
|
||||
case LONG:
|
||||
return (Aggregator<T>) longAggregator;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -24,7 +23,7 @@ import javax.annotation.Nullable;
|
|||
* problem because LastValueAggregator is currently only available for Observers which record all
|
||||
* values once.
|
||||
*/
|
||||
public final class LongLastValueAggregator implements Aggregator<LongAccumulation> {
|
||||
public final class LongLastValueAggregator implements Aggregator<Long> {
|
||||
@Nullable private static final Long DEFAULT_VALUE = null;
|
||||
private static final LongLastValueAggregator INSTANCE = new LongLastValueAggregator();
|
||||
|
||||
|
|
@ -33,24 +32,24 @@ public final class LongLastValueAggregator implements Aggregator<LongAccumulatio
|
|||
*
|
||||
* @return the instance of this {@link Aggregator}.
|
||||
*/
|
||||
public static Aggregator<LongAccumulation> getInstance() {
|
||||
public static Aggregator<Long> getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private LongLastValueAggregator() {}
|
||||
|
||||
@Override
|
||||
public AggregatorHandle<LongAccumulation> createHandle() {
|
||||
public AggregatorHandle<Long> createHandle() {
|
||||
return new Handle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation accumulateLong(long value) {
|
||||
return LongAccumulation.create(value);
|
||||
public Long accumulateLong(long value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
public Long merge(Long a1, Long a2) {
|
||||
// TODO: Define the order between accumulation.
|
||||
return a2;
|
||||
}
|
||||
|
|
@ -60,7 +59,7 @@ public final class LongLastValueAggregator implements Aggregator<LongAccumulatio
|
|||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
Map<Labels, Long> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
|
|
@ -88,12 +87,12 @@ public final class LongLastValueAggregator implements Aggregator<LongAccumulatio
|
|||
return null;
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<LongAccumulation> {
|
||||
static final class Handle extends AggregatorHandle<Long> {
|
||||
private final AtomicReference<Long> current = new AtomicReference<>(DEFAULT_VALUE);
|
||||
|
||||
@Override
|
||||
protected LongAccumulation doAccumulateThenReset() {
|
||||
return LongAccumulation.create(this.current.getAndSet(DEFAULT_VALUE));
|
||||
protected Long doAccumulateThenReset() {
|
||||
return this.current.getAndSet(DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -16,7 +15,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
|
||||
public final class LongSumAggregator implements Aggregator<LongAccumulation> {
|
||||
public final class LongSumAggregator implements Aggregator<Long> {
|
||||
private static final LongSumAggregator INSTANCE = new LongSumAggregator();
|
||||
|
||||
/**
|
||||
|
|
@ -24,25 +23,25 @@ public final class LongSumAggregator implements Aggregator<LongAccumulation> {
|
|||
*
|
||||
* @return the instance of this {@link Aggregator}.
|
||||
*/
|
||||
public static Aggregator<LongAccumulation> getInstance() {
|
||||
public static Aggregator<Long> getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private LongSumAggregator() {}
|
||||
|
||||
@Override
|
||||
public AggregatorHandle<LongAccumulation> createHandle() {
|
||||
public AggregatorHandle<Long> createHandle() {
|
||||
return new Handle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation accumulateLong(long value) {
|
||||
return LongAccumulation.create(value);
|
||||
public Long accumulateLong(long value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
return LongAccumulation.create(a1.getValue() + a2.getValue());
|
||||
public Long merge(Long a1, Long a2) {
|
||||
return a1 + a2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -50,7 +49,7 @@ public final class LongSumAggregator implements Aggregator<LongAccumulation> {
|
|||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
Map<Labels, Long> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
|
|
@ -62,12 +61,12 @@ public final class LongSumAggregator implements Aggregator<LongAccumulation> {
|
|||
resource, instrumentationLibraryInfo, descriptor, points, isMonotonic);
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<LongAccumulation> {
|
||||
static final class Handle extends AggregatorHandle<Long> {
|
||||
private final LongAdder current = new LongAdder();
|
||||
|
||||
@Override
|
||||
protected LongAccumulation doAccumulateThenReset() {
|
||||
return LongAccumulation.create(this.current.sumThenReset());
|
||||
protected Long doAccumulateThenReset() {
|
||||
return this.current.sumThenReset();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -7,9 +7,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.DoubleAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -53,30 +50,22 @@ final class MetricDataUtils {
|
|||
}
|
||||
|
||||
static List<MetricData.LongPoint> toLongPointList(
|
||||
Map<Labels, LongAccumulation> accumulationMap, long startEpochNanos, long epochNanos) {
|
||||
Map<Labels, Long> accumulationMap, long startEpochNanos, long epochNanos) {
|
||||
List<MetricData.LongPoint> points = new ArrayList<>(accumulationMap.size());
|
||||
accumulationMap.forEach(
|
||||
(labels, accumulation) -> {
|
||||
MetricData.LongPoint point = accumulation.toPoint(startEpochNanos, epochNanos, labels);
|
||||
if (point == null) {
|
||||
return;
|
||||
}
|
||||
points.add(point);
|
||||
});
|
||||
(labels, accumulation) ->
|
||||
points.add(
|
||||
MetricData.LongPoint.create(startEpochNanos, epochNanos, labels, accumulation)));
|
||||
return points;
|
||||
}
|
||||
|
||||
static List<MetricData.DoublePoint> toDoublePointList(
|
||||
Map<Labels, DoubleAccumulation> accumulationMap, long startEpochNanos, long epochNanos) {
|
||||
Map<Labels, Double> accumulationMap, long startEpochNanos, long epochNanos) {
|
||||
List<MetricData.DoublePoint> points = new ArrayList<>(accumulationMap.size());
|
||||
accumulationMap.forEach(
|
||||
(labels, accumulation) -> {
|
||||
MetricData.DoublePoint point = accumulation.toPoint(startEpochNanos, epochNanos, labels);
|
||||
if (point == null) {
|
||||
return;
|
||||
}
|
||||
points.add(point);
|
||||
});
|
||||
(labels, accumulation) ->
|
||||
points.add(
|
||||
MetricData.DoublePoint.create(startEpochNanos, epochNanos, labels, accumulation)));
|
||||
return points;
|
||||
}
|
||||
|
||||
|
|
@ -86,14 +75,8 @@ final class MetricDataUtils {
|
|||
long epochNanos) {
|
||||
List<MetricData.DoubleSummaryPoint> points = new ArrayList<>(accumulationMap.size());
|
||||
accumulationMap.forEach(
|
||||
(labels, aggregator) -> {
|
||||
MetricData.DoubleSummaryPoint point =
|
||||
aggregator.toPoint(startEpochNanos, epochNanos, labels);
|
||||
if (point == null) {
|
||||
return;
|
||||
}
|
||||
points.add(point);
|
||||
});
|
||||
(labels, aggregator) ->
|
||||
points.add(aggregator.toPoint(startEpochNanos, epochNanos, labels)));
|
||||
return points;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.accumulation;
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
|
|
@ -13,7 +13,7 @@ import javax.annotation.concurrent.Immutable;
|
|||
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class MinMaxSumCountAccumulation implements Accumulation {
|
||||
abstract class MinMaxSumCountAccumulation {
|
||||
/**
|
||||
* Creates a new {@link MinMaxSumCountAccumulation} with the given values.
|
||||
*
|
||||
|
|
@ -23,42 +23,41 @@ public abstract class MinMaxSumCountAccumulation implements Accumulation {
|
|||
* @param max the max value out of all measurements.
|
||||
* @return a new {@link MinMaxSumCountAccumulation} with the given values.
|
||||
*/
|
||||
public static MinMaxSumCountAccumulation create(long count, double sum, double min, double max) {
|
||||
static MinMaxSumCountAccumulation create(long count, double sum, double min, double max) {
|
||||
return new AutoValue_MinMaxSumCountAccumulation(count, sum, min, max);
|
||||
}
|
||||
|
||||
MinMaxSumCountAccumulation() {}
|
||||
|
||||
/**
|
||||
* Returns the count (number of measurements) stored by this {@link Accumulation}.
|
||||
* Returns the count (number of measurements) stored by this accumulation.
|
||||
*
|
||||
* @return the count stored by this {@link Accumulation}.
|
||||
* @return the count stored by this accumulation.
|
||||
*/
|
||||
public abstract long getCount();
|
||||
abstract long getCount();
|
||||
|
||||
/**
|
||||
* Returns the sum (sum of measurements) stored by this {@link Accumulation}.
|
||||
* Returns the sum (sum of measurements) stored by this accumulation.
|
||||
*
|
||||
* @return the sum stored by this {@link Accumulation}.
|
||||
* @return the sum stored by this accumulation.
|
||||
*/
|
||||
public abstract double getSum();
|
||||
abstract double getSum();
|
||||
|
||||
/**
|
||||
* Returns the min (minimum of all measurements) stored by this {@link Accumulation}.
|
||||
* Returns the min (minimum of all measurements) stored by this accumulation.
|
||||
*
|
||||
* @return the min stored by this {@link Accumulation}.
|
||||
* @return the min stored by this accumulation.
|
||||
*/
|
||||
public abstract double getMin();
|
||||
abstract double getMin();
|
||||
|
||||
/**
|
||||
* Returns the max (maximum of all measurements) stored by this {@link Accumulation}.
|
||||
* Returns the max (maximum of all measurements) stored by this accumulation.
|
||||
*
|
||||
* @return the max stored by this {@link Accumulation}.
|
||||
* @return the max stored by this accumulation.
|
||||
*/
|
||||
public abstract double getMax();
|
||||
abstract double getMax();
|
||||
|
||||
@Override
|
||||
public MetricData.DoubleSummaryPoint toPoint(
|
||||
final MetricData.DoubleSummaryPoint toPoint(
|
||||
long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return MetricData.DoubleSummaryPoint.create(
|
||||
startEpochNanos,
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.accumulation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.offset;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class DoubleAccumulationTest {
|
||||
@Test
|
||||
void toPoint() {
|
||||
Accumulation accumulation = DoubleAccumulation.create(12.1);
|
||||
assertThat(getPoint(accumulation).getValue()).isCloseTo(12.1, offset(1e-6));
|
||||
}
|
||||
|
||||
private static MetricData.DoublePoint getPoint(Accumulation aggregator) {
|
||||
MetricData.Point point = aggregator.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNotNull();
|
||||
assertThat(point.getStartEpochNanos()).isEqualTo(12345);
|
||||
assertThat(point.getEpochNanos()).isEqualTo(12358);
|
||||
assertThat(point.getLabels().size()).isEqualTo(1);
|
||||
assertThat(point.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(point).isInstanceOf(MetricData.DoublePoint.class);
|
||||
return (MetricData.DoublePoint) point;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.accumulation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class LongAccumulationTest {
|
||||
@Test
|
||||
void toPoint() {
|
||||
Accumulation accumulation = LongAccumulation.create(12);
|
||||
assertThat(getPoint(accumulation).getValue()).isEqualTo(12);
|
||||
}
|
||||
|
||||
private static MetricData.LongPoint getPoint(Accumulation accumulation) {
|
||||
MetricData.Point point = accumulation.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNotNull();
|
||||
assertThat(point.getStartEpochNanos()).isEqualTo(12345);
|
||||
assertThat(point.getEpochNanos()).isEqualTo(12358);
|
||||
assertThat(point.getLabels().size()).isEqualTo(1);
|
||||
assertThat(point.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(point).isInstanceOf(MetricData.LongPoint.class);
|
||||
return (MetricData.LongPoint) point;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -91,13 +90,13 @@ public class AggregatorHandleTest {
|
|||
assertThat(testAggregator.recordedDouble.get()).isEqualTo(0);
|
||||
}
|
||||
|
||||
private static class TestAggregatorHandle extends AggregatorHandle<Accumulation> {
|
||||
private static class TestAggregatorHandle extends AggregatorHandle<Void> {
|
||||
final AtomicLong recordedLong = new AtomicLong();
|
||||
final AtomicDouble recordedDouble = new AtomicDouble();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Accumulation doAccumulateThenReset() {
|
||||
protected Void doAccumulateThenReset() {
|
||||
recordedLong.set(0);
|
||||
recordedDouble.set(0);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -28,33 +27,30 @@ class CountAggregatorTest {
|
|||
|
||||
@Test
|
||||
void toPoint() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
CountAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = CountAggregator.getInstance().createHandle();
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordLongOperations() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
CountAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = CountAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(12);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(2));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordDoubleOperations() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
CountAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = CountAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordDouble(12.3);
|
||||
aggregatorHandle.recordDouble(12.3);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(2));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<LongAccumulation> count = CountAggregator.getInstance();
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = count.createHandle();
|
||||
Aggregator<Long> count = CountAggregator.getInstance();
|
||||
AggregatorHandle<Long> aggregatorHandle = count.createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.DoubleAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -28,34 +27,34 @@ class DoubleLastValueAggregatorTest {
|
|||
|
||||
@Test
|
||||
void multipleRecords() {
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle =
|
||||
AggregatorHandle<Double> aggregatorHandle =
|
||||
DoubleLastValueAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordDouble(12.1);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(12.1));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(12.1);
|
||||
aggregatorHandle.recordDouble(13.1);
|
||||
aggregatorHandle.recordDouble(14.1);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(14.1));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(14.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toAccumulationAndReset() {
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle =
|
||||
AggregatorHandle<Double> aggregatorHandle =
|
||||
DoubleLastValueAggregator.getInstance().createHandle();
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordDouble(13.1);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(13.1));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(13.1);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordDouble(12.1);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(12.1));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(12.1);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<DoubleAccumulation> lastValue = DoubleLastValueAggregator.getInstance();
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle = lastValue.createHandle();
|
||||
Aggregator<Double> lastValue = DoubleLastValueAggregator.getInstance();
|
||||
AggregatorHandle<Double> aggregatorHandle = lastValue.createHandle();
|
||||
aggregatorHandle.recordDouble(10);
|
||||
|
||||
MetricData metricData =
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -143,9 +141,9 @@ class DoubleMinMaxSumCountAggregatorTest {
|
|||
|
||||
@GuardedBy("lock")
|
||||
@Nullable
|
||||
private Accumulation accumulation;
|
||||
private MinMaxSumCountAccumulation accumulation;
|
||||
|
||||
void process(@Nullable Accumulation other) {
|
||||
void process(@Nullable MinMaxSumCountAccumulation other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -155,10 +153,7 @@ class DoubleMinMaxSumCountAggregatorTest {
|
|||
accumulation = other;
|
||||
return;
|
||||
}
|
||||
accumulation =
|
||||
AggregatorFactory.minMaxSumCount()
|
||||
.create(InstrumentValueType.DOUBLE)
|
||||
.merge(accumulation, other);
|
||||
accumulation = DoubleMinMaxSumCountAggregator.getInstance().merge(accumulation, other);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.DoubleAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -28,51 +27,47 @@ class DoubleSumAggregatorTest {
|
|||
|
||||
@Test
|
||||
void multipleRecords() {
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle =
|
||||
DoubleSumAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Double> aggregatorHandle = DoubleSumAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordDouble(12.1);
|
||||
aggregatorHandle.recordDouble(12.1);
|
||||
aggregatorHandle.recordDouble(12.1);
|
||||
aggregatorHandle.recordDouble(12.1);
|
||||
aggregatorHandle.recordDouble(12.1);
|
||||
assertThat(aggregatorHandle.accumulateThenReset())
|
||||
.isEqualTo(DoubleAccumulation.create(12.1 * 5));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(12.1 * 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleRecords_WithNegatives() {
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle =
|
||||
DoubleSumAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Double> aggregatorHandle = DoubleSumAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordDouble(12);
|
||||
aggregatorHandle.recordDouble(12);
|
||||
aggregatorHandle.recordDouble(-23);
|
||||
aggregatorHandle.recordDouble(12);
|
||||
aggregatorHandle.recordDouble(12);
|
||||
aggregatorHandle.recordDouble(-11);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(14));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(14);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toAccumulationAndReset() {
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle =
|
||||
DoubleSumAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Double> aggregatorHandle = DoubleSumAggregator.getInstance().createHandle();
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordDouble(13);
|
||||
aggregatorHandle.recordDouble(12);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(25));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(25);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordDouble(12);
|
||||
aggregatorHandle.recordDouble(-25);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(-13));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(-13);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<DoubleAccumulation> sum = DoubleSumAggregator.getInstance();
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle = sum.createHandle();
|
||||
Aggregator<Double> sum = DoubleSumAggregator.getInstance();
|
||||
AggregatorHandle<Double> aggregatorHandle = sum.createHandle();
|
||||
aggregatorHandle.recordDouble(10);
|
||||
|
||||
MetricData metricData =
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -28,34 +27,32 @@ class LongLastValueAggregatorTest {
|
|||
|
||||
@Test
|
||||
void multipleRecords() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
LongLastValueAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = LongLastValueAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordLong(12);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(12));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(12L);
|
||||
aggregatorHandle.recordLong(13);
|
||||
aggregatorHandle.recordLong(14);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(14));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(14L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toAccumulationAndReset() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
LongLastValueAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = LongLastValueAggregator.getInstance().createHandle();
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordLong(13);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(13));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(13L);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordLong(12);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(12));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(12L);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<LongAccumulation> lastValue = LongLastValueAggregator.getInstance();
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = lastValue.createHandle();
|
||||
Aggregator<Long> lastValue = LongLastValueAggregator.getInstance();
|
||||
AggregatorHandle<Long> aggregatorHandle = lastValue.createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -140,7 +138,7 @@ class LongMinMaxSumCountAggregatorTest {
|
|||
|
||||
@GuardedBy("lock")
|
||||
@Nullable
|
||||
private Accumulation accumulation;
|
||||
private MinMaxSumCountAccumulation accumulation;
|
||||
|
||||
void process(@Nullable MinMaxSumCountAccumulation other) {
|
||||
if (other == null) {
|
||||
|
|
@ -152,10 +150,7 @@ class LongMinMaxSumCountAggregatorTest {
|
|||
accumulation = other;
|
||||
return;
|
||||
}
|
||||
accumulation =
|
||||
AggregatorFactory.minMaxSumCount()
|
||||
.create(InstrumentValueType.LONG)
|
||||
.merge(accumulation, other);
|
||||
accumulation = LongMinMaxSumCountAggregator.getInstance().merge(accumulation, other);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -28,52 +27,49 @@ class LongSumAggregatorTest {
|
|||
|
||||
@Test
|
||||
void multipleRecords() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
LongSumAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = LongSumAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(12);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(12 * 5));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(12 * 5);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleRecords_WithNegatives() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
LongSumAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = LongSumAggregator.getInstance().createHandle();
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(-23);
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(-11);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(14));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(14);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toAccumulationAndReset() {
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle =
|
||||
LongSumAggregator.getInstance().createHandle();
|
||||
AggregatorHandle<Long> aggregatorHandle = LongSumAggregator.getInstance().createHandle();
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordLong(13);
|
||||
aggregatorHandle.recordLong(12);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(25));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(25);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
|
||||
aggregatorHandle.recordLong(12);
|
||||
aggregatorHandle.recordLong(-25);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(-13));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(-13);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<LongAccumulation> sum = LongSumAggregator.getInstance();
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = sum.createHandle();
|
||||
Aggregator<Long> sum = LongSumAggregator.getInstance();
|
||||
AggregatorHandle<Long> aggregatorHandle = sum.createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.accumulation;
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ import org.junit.jupiter.api.Test;
|
|||
class MinMaxSumCountAccumulationTest {
|
||||
@Test
|
||||
void toPoint() {
|
||||
Accumulation accumulation = MinMaxSumCountAccumulation.create(12, 25, 1, 3);
|
||||
MinMaxSumCountAccumulation accumulation = MinMaxSumCountAccumulation.create(12, 25, 1, 3);
|
||||
MetricData.DoubleSummaryPoint point = getPoint(accumulation);
|
||||
assertThat(point.getCount()).isEqualTo(12);
|
||||
assertThat(point.getSum()).isEqualTo(25);
|
||||
|
|
@ -25,14 +25,15 @@ class MinMaxSumCountAccumulationTest {
|
|||
.isEqualTo(MetricData.ValueAtPercentile.create(100.0, 3));
|
||||
}
|
||||
|
||||
private static MetricData.DoubleSummaryPoint getPoint(Accumulation accumulation) {
|
||||
MetricData.Point point = accumulation.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
private static MetricData.DoubleSummaryPoint getPoint(MinMaxSumCountAccumulation accumulation) {
|
||||
MetricData.DoubleSummaryPoint point =
|
||||
accumulation.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNotNull();
|
||||
assertThat(point.getStartEpochNanos()).isEqualTo(12345);
|
||||
assertThat(point.getEpochNanos()).isEqualTo(12358);
|
||||
assertThat(point.getLabels().size()).isEqualTo(1);
|
||||
assertThat(point.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(point).isInstanceOf(MetricData.DoubleSummaryPoint.class);
|
||||
return (MetricData.DoubleSummaryPoint) point;
|
||||
return point;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue