Remove aggregation and merge functionality into aggregator (#2460)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
711efc3ed4
commit
1c40444da3
|
|
@ -27,7 +27,7 @@ final class AsynchronousInstrumentAccumulator {
|
|||
return new AsynchronousInstrumentAccumulator(instrumentProcessor, () -> {});
|
||||
}
|
||||
|
||||
Aggregator<T> aggregator = instrumentProcessor.getAggregation().getAggregator();
|
||||
Aggregator<T> aggregator = instrumentProcessor.getAggregator();
|
||||
AsynchronousInstrument.DoubleResult result =
|
||||
(value, labels) -> instrumentProcessor.batch(labels, aggregator.accumulateDouble(value));
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ final class AsynchronousInstrumentAccumulator {
|
|||
return new AsynchronousInstrumentAccumulator(instrumentProcessor, () -> {});
|
||||
}
|
||||
|
||||
Aggregator<T> aggregator = instrumentProcessor.getAggregation().getAggregator();
|
||||
Aggregator<T> aggregator = instrumentProcessor.getAggregator();
|
||||
AsynchronousInstrument.LongResult result =
|
||||
(value, labels) -> instrumentProcessor.batch(labels, aggregator.accumulateLong(value));
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ 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.aggregation.Aggregation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -30,7 +30,7 @@ import java.util.Objects;
|
|||
*/
|
||||
final class InstrumentProcessor<T extends Accumulation> {
|
||||
private final InstrumentDescriptor descriptor;
|
||||
private final Aggregation<T> aggregation;
|
||||
private final Aggregator<T> aggregator;
|
||||
private final Resource resource;
|
||||
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
||||
private final Clock clock;
|
||||
|
|
@ -47,10 +47,10 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
InstrumentDescriptor descriptor,
|
||||
MeterProviderSharedState meterProviderSharedState,
|
||||
MeterSharedState meterSharedState,
|
||||
Aggregation<T> aggregation) {
|
||||
Aggregator<T> aggregator) {
|
||||
return new InstrumentProcessor<>(
|
||||
descriptor,
|
||||
aggregation,
|
||||
aggregator,
|
||||
meterProviderSharedState.getResource(),
|
||||
meterSharedState.getInstrumentationLibraryInfo(),
|
||||
meterProviderSharedState.getClock(),
|
||||
|
|
@ -66,10 +66,10 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
InstrumentDescriptor descriptor,
|
||||
MeterProviderSharedState meterProviderSharedState,
|
||||
MeterSharedState meterSharedState,
|
||||
Aggregation<T> aggregation) {
|
||||
Aggregator<T> aggregator) {
|
||||
return new InstrumentProcessor<>(
|
||||
descriptor,
|
||||
aggregation,
|
||||
aggregator,
|
||||
meterProviderSharedState.getResource(),
|
||||
meterSharedState.getInstrumentationLibraryInfo(),
|
||||
meterProviderSharedState.getClock(),
|
||||
|
|
@ -78,13 +78,13 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
|
||||
private InstrumentProcessor(
|
||||
InstrumentDescriptor descriptor,
|
||||
Aggregation<T> aggregation,
|
||||
Aggregator<T> aggregator,
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
Clock clock,
|
||||
boolean delta) {
|
||||
this.descriptor = descriptor;
|
||||
this.aggregation = aggregation;
|
||||
this.aggregator = aggregator;
|
||||
this.resource = resource;
|
||||
this.instrumentationLibraryInfo = instrumentationLibraryInfo;
|
||||
this.clock = clock;
|
||||
|
|
@ -106,7 +106,7 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
accumulationMap.put(labelSet, accumulation);
|
||||
return;
|
||||
}
|
||||
accumulationMap.put(labelSet, aggregation.merge(currentAccumulation, accumulation));
|
||||
accumulationMap.put(labelSet, aggregator.merge(currentAccumulation, accumulation));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,7 +126,7 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
}
|
||||
|
||||
MetricData metricData =
|
||||
aggregation.toMetricData(
|
||||
aggregator.toMetricData(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor,
|
||||
|
|
@ -142,8 +142,8 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
return metricData == null ? Collections.emptyList() : Collections.singletonList(metricData);
|
||||
}
|
||||
|
||||
Aggregation<T> getAggregation() {
|
||||
return this.aggregation;
|
||||
Aggregator<T> getAggregator() {
|
||||
return this.aggregator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -174,7 +174,7 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
if (!Objects.equals(descriptor, allLabels.descriptor)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(aggregation, allLabels.aggregation)) {
|
||||
if (!Objects.equals(aggregator, allLabels.aggregator)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(resource, allLabels.resource)) {
|
||||
|
|
@ -192,7 +192,7 @@ final class InstrumentProcessor<T extends Accumulation> {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
int result = descriptor != null ? descriptor.hashCode() : 0;
|
||||
result = 31 * result + (aggregation != null ? aggregation.hashCode() : 0);
|
||||
result = 31 * result + (aggregator != null ? aggregator.hashCode() : 0);
|
||||
result = 31 * result + (resource != null ? resource.hashCode() : 0);
|
||||
result =
|
||||
31 * result
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ final class SynchronousInstrumentAccumulator<T extends Accumulation> {
|
|||
aggregatorLabels = new ConcurrentHashMap<>();
|
||||
collectLock = new ReentrantLock();
|
||||
this.instrumentProcessor = instrumentProcessor;
|
||||
this.aggregator = instrumentProcessor.getAggregation().getAggregator();
|
||||
this.aggregator = instrumentProcessor.getAggregator();
|
||||
}
|
||||
|
||||
AggregatorHandle<?> bind(Labels labels) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregation.AggregationFactory;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -40,16 +40,16 @@ final class ViewRegistry {
|
|||
new LinkedHashMap<>();
|
||||
private static final AggregationConfiguration CUMULATIVE_SUM =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE);
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE);
|
||||
private static final AggregationConfiguration DELTA_SUMMARY =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.minMaxSumCount(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.minMaxSumCount(), MetricData.AggregationTemporality.DELTA);
|
||||
private static final AggregationConfiguration CUMULATIVE_LAST_VALUE =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.lastValue(), MetricData.AggregationTemporality.CUMULATIVE);
|
||||
AggregatorFactory.lastValue(), MetricData.AggregationTemporality.CUMULATIVE);
|
||||
private static final AggregationConfiguration DELTA_LAST_VALUE =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.lastValue(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.lastValue(), MetricData.AggregationTemporality.DELTA);
|
||||
|
||||
private final ReentrantLock collectLock = new ReentrantLock();
|
||||
private volatile EnumMap<InstrumentType, LinkedHashMap<Pattern, AggregationConfiguration>>
|
||||
|
|
@ -96,13 +96,13 @@ final class ViewRegistry {
|
|||
descriptor,
|
||||
meterProviderSharedState,
|
||||
meterSharedState,
|
||||
specification.getAggregationFactory().create(descriptor.getValueType()));
|
||||
specification.getAggregatorFactory().create(descriptor.getValueType()));
|
||||
case DELTA:
|
||||
return InstrumentProcessor.getDeltaAllLabels(
|
||||
descriptor,
|
||||
meterProviderSharedState,
|
||||
meterSharedState,
|
||||
specification.getAggregationFactory().create(descriptor.getValueType()));
|
||||
specification.getAggregatorFactory().create(descriptor.getValueType()));
|
||||
}
|
||||
throw new IllegalStateException("unsupported Temporality: " + specification.getTemporality());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
|
||||
abstract class AbstractAggregation<T extends Accumulation> implements Aggregation<T> {
|
||||
private final Aggregator<T> aggregator;
|
||||
|
||||
AbstractAggregation(Aggregator<T> aggregator) {
|
||||
this.aggregator = aggregator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Aggregator<T> getAggregator() {
|
||||
return aggregator;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
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;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* {@link Aggregation} is the process of combining a certain set of recorded measurements for a
|
||||
* given {@code Instrument} into the equivalent {@code MetricData}.
|
||||
*/
|
||||
@Immutable
|
||||
public interface Aggregation<T extends Accumulation> {
|
||||
|
||||
/**
|
||||
* Returns an {@link Aggregator} that can be used to aggregate measurements and produce {@link
|
||||
* Accumulation}.
|
||||
*
|
||||
* @return the {@link Aggregator} for this {@link Aggregation}.
|
||||
*/
|
||||
Aggregator<T> getAggregator();
|
||||
|
||||
/**
|
||||
* Returns the result of the merge of the given {@link Accumulation}s.
|
||||
*
|
||||
* @return the result of the merge of the given {@link Accumulation}s.
|
||||
*/
|
||||
T merge(T a1, T a2);
|
||||
|
||||
/**
|
||||
* Returns the {@link MetricData} that this {@code Aggregation} will produce.
|
||||
*
|
||||
* @param resource the Resource associated with the {@code Instrument}.
|
||||
* @param instrumentationLibraryInfo the InstrumentationLibraryInfo associated with the {@code
|
||||
* Instrument}.
|
||||
* @param descriptor the InstrumentDescriptor of the {@code Instrument}.
|
||||
* @param accumulationByLabels the map of Labels to Accumulation.
|
||||
* @param startEpochNanos the startEpochNanos for the {@code Point}.
|
||||
* @param epochNanos the epochNanos for the {@code Point}.
|
||||
* @return the {@link MetricData.Type} that this {@code Aggregation} will produce.
|
||||
*/
|
||||
@Nullable
|
||||
MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, T> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos);
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.CountAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class CountAggregation implements Aggregation<LongAccumulation> {
|
||||
static final CountAggregation INSTANCE = new CountAggregation();
|
||||
|
||||
private CountAggregation() {}
|
||||
|
||||
@Override
|
||||
public Aggregator<LongAccumulation> getAggregator() {
|
||||
return CountAggregator.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
return LongAccumulation.create(a1.getValue() + a2.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
MetricDataUtils.toLongPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
|
||||
return MetricData.createLongSum(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
"1",
|
||||
MetricData.LongSumData.create(
|
||||
/* isMonotonic= */ true, MetricData.AggregationTemporality.CUMULATIVE, points));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.DoubleAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.DoubleLastValueAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class DoubleLastValueAggregation extends AbstractAggregation<DoubleAccumulation> {
|
||||
static final DoubleLastValueAggregation INSTANCE =
|
||||
new DoubleLastValueAggregation(DoubleLastValueAggregator.getInstance());
|
||||
|
||||
private DoubleLastValueAggregation(Aggregator<DoubleAccumulation> aggregator) {
|
||||
super(aggregator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleAccumulation merge(DoubleAccumulation a1, DoubleAccumulation a2) {
|
||||
// TODO: Define the order between accumulation.
|
||||
return a2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, DoubleAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoublePoint> points =
|
||||
MetricDataUtils.toDoublePointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
|
||||
switch (descriptor.getType()) {
|
||||
case SUM_OBSERVER:
|
||||
return MetricDataUtils.toDoubleSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ true);
|
||||
case UP_DOWN_SUM_OBSERVER:
|
||||
return MetricDataUtils.toDoubleSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ false);
|
||||
case VALUE_OBSERVER:
|
||||
return MetricData.createDoubleGauge(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
descriptor.getUnit(),
|
||||
MetricData.DoubleGaugeData.create(points));
|
||||
case COUNTER:
|
||||
case UP_DOWN_COUNTER:
|
||||
case VALUE_RECORDER:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.DoubleAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.DoubleSumAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class DoubleSumAggregation extends AbstractAggregation<DoubleAccumulation> {
|
||||
static final DoubleSumAggregation INSTANCE =
|
||||
new DoubleSumAggregation(DoubleSumAggregator.getInstance());
|
||||
|
||||
private DoubleSumAggregation(Aggregator<DoubleAccumulation> aggregator) {
|
||||
super(aggregator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DoubleAccumulation merge(DoubleAccumulation a1, DoubleAccumulation a2) {
|
||||
return DoubleAccumulation.create(a1.getValue() + a2.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, DoubleAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoublePoint> points =
|
||||
MetricDataUtils.toDoublePointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
boolean isMonotonic =
|
||||
descriptor.getType() == InstrumentType.COUNTER
|
||||
|| descriptor.getType() == InstrumentType.SUM_OBSERVER;
|
||||
return MetricDataUtils.toDoubleSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, isMonotonic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class ImmutableAggregationFactory<L extends Accumulation, D extends Accumulation>
|
||||
implements AggregationFactory {
|
||||
static final AggregationFactory SUM =
|
||||
new ImmutableAggregationFactory<>(LongSumAggregation.INSTANCE, DoubleSumAggregation.INSTANCE);
|
||||
|
||||
static final AggregationFactory COUNT =
|
||||
new ImmutableAggregationFactory<>(CountAggregation.INSTANCE, CountAggregation.INSTANCE);
|
||||
|
||||
static final AggregationFactory LAST_VALUE =
|
||||
new ImmutableAggregationFactory<>(
|
||||
LongLastValueAggregation.INSTANCE, DoubleLastValueAggregation.INSTANCE);
|
||||
|
||||
static final AggregationFactory MIN_MAX_SUM_COUNT =
|
||||
new ImmutableAggregationFactory<>(
|
||||
MinMaxSumCountAggregation.LONG_INSTANCE, MinMaxSumCountAggregation.DOUBLE_INSTANCE);
|
||||
|
||||
private final Aggregation<L> longAggregation;
|
||||
private final Aggregation<D> doubleAggregation;
|
||||
|
||||
private ImmutableAggregationFactory(
|
||||
Aggregation<L> longAggregation, Aggregation<D> doubleAggregation) {
|
||||
this.longAggregation = longAggregation;
|
||||
this.doubleAggregation = doubleAggregation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Accumulation> Aggregation<T> create(InstrumentValueType instrumentValueType) {
|
||||
switch (instrumentValueType) {
|
||||
case LONG:
|
||||
return (Aggregation<T>) longAggregation;
|
||||
case DOUBLE:
|
||||
return (Aggregation<T>) doubleAggregation;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid instrument value type");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.LongLastValueAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class LongLastValueAggregation extends AbstractAggregation<LongAccumulation> {
|
||||
static final LongLastValueAggregation INSTANCE =
|
||||
new LongLastValueAggregation(LongLastValueAggregator.getInstance());
|
||||
|
||||
private LongLastValueAggregation(Aggregator<LongAccumulation> aggregator) {
|
||||
super(aggregator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
// TODO: Define the order between accumulation.
|
||||
return a2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
MetricDataUtils.toLongPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
|
||||
switch (descriptor.getType()) {
|
||||
case SUM_OBSERVER:
|
||||
return MetricDataUtils.toLongSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ true);
|
||||
case UP_DOWN_SUM_OBSERVER:
|
||||
return MetricDataUtils.toLongSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ false);
|
||||
case VALUE_OBSERVER:
|
||||
return MetricData.createLongGauge(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
descriptor.getUnit(),
|
||||
MetricData.LongGaugeData.create(points));
|
||||
case COUNTER:
|
||||
case UP_DOWN_COUNTER:
|
||||
case VALUE_RECORDER:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.LongSumAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class LongSumAggregation extends AbstractAggregation<LongAccumulation> {
|
||||
static final LongSumAggregation INSTANCE =
|
||||
new LongSumAggregation(LongSumAggregator.getInstance());
|
||||
|
||||
private LongSumAggregation(Aggregator<LongAccumulation> aggregator) {
|
||||
super(aggregator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
return LongAccumulation.create(a1.getValue() + a2.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
MetricDataUtils.toLongPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
boolean isMonotonic =
|
||||
descriptor.getType() == InstrumentType.COUNTER
|
||||
|| descriptor.getType() == InstrumentType.SUM_OBSERVER;
|
||||
return MetricDataUtils.toLongSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, isMonotonic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.accumulation.MinMaxSumCountAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.DoubleMinMaxSumCountAggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.LongMinMaxSumCountAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
final class MinMaxSumCountAggregation extends AbstractAggregation<MinMaxSumCountAccumulation> {
|
||||
static final MinMaxSumCountAggregation LONG_INSTANCE =
|
||||
new MinMaxSumCountAggregation(LongMinMaxSumCountAggregator.getInstance());
|
||||
static final MinMaxSumCountAggregation DOUBLE_INSTANCE =
|
||||
new MinMaxSumCountAggregation(DoubleMinMaxSumCountAggregator.getInstance());
|
||||
|
||||
private MinMaxSumCountAggregation(Aggregator<MinMaxSumCountAccumulation> aggregator) {
|
||||
super(aggregator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinMaxSumCountAccumulation merge(
|
||||
MinMaxSumCountAccumulation a1, MinMaxSumCountAccumulation a2) {
|
||||
return MinMaxSumCountAccumulation.create(
|
||||
a1.getCount() + a2.getCount(),
|
||||
a1.getSum() + a2.getSum(),
|
||||
Math.min(a1.getMin(), a2.getMin()),
|
||||
Math.max(a1.getMax(), a2.getMax()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, MinMaxSumCountAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoubleSummaryPoint> points =
|
||||
MetricDataUtils.toDoubleSummaryPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
return MetricData.createDoubleSummary(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
descriptor.getUnit(),
|
||||
MetricData.DoubleSummaryData.create(points));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,14 @@
|
|||
|
||||
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;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
|
|
@ -53,4 +60,32 @@ public interface Aggregator<T extends Accumulation> {
|
|||
throw new UnsupportedOperationException(
|
||||
"This aggregator does not support recording double values.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of the merge of the given {@link Accumulation}s.
|
||||
*
|
||||
* @return the result of the merge of the given {@link Accumulation}s.
|
||||
*/
|
||||
T merge(T a1, T a2);
|
||||
|
||||
/**
|
||||
* Returns the {@link MetricData} that this {@code Aggregation} will produce.
|
||||
*
|
||||
* @param resource the Resource associated with the {@code Instrument}.
|
||||
* @param instrumentationLibraryInfo the InstrumentationLibraryInfo associated with the {@code
|
||||
* Instrument}.
|
||||
* @param descriptor the InstrumentDescriptor of the {@code Instrument}.
|
||||
* @param accumulationByLabels the map of Labels to Accumulation.
|
||||
* @param startEpochNanos the startEpochNanos for the {@code Point}.
|
||||
* @param epochNanos the epochNanos for the {@code Point}.
|
||||
* @return the {@link MetricData.Type} that this {@code Aggregation} will produce.
|
||||
*/
|
||||
@Nullable
|
||||
MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, T> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,23 +3,22 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.accumulation.Accumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorHandle;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/** Factory class for {@link AggregatorHandle}. */
|
||||
/** Factory class for {@link Aggregator}. */
|
||||
@Immutable
|
||||
public interface AggregationFactory {
|
||||
public interface AggregatorFactory {
|
||||
/**
|
||||
* Returns an {@code AggregationFactory} that calculates sum of recorded measurements.
|
||||
*
|
||||
* @return an {@code AggregationFactory} that calculates sum of recorded measurements.
|
||||
*/
|
||||
static AggregationFactory sum() {
|
||||
return ImmutableAggregationFactory.SUM;
|
||||
static AggregatorFactory sum() {
|
||||
return ImmutableAggregatorFactory.SUM;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -29,8 +28,8 @@ public interface AggregationFactory {
|
|||
* @return an {@code AggregationFactory} that calculates count of recorded measurements (the
|
||||
* number of recorded * measurements).
|
||||
*/
|
||||
static AggregationFactory count() {
|
||||
return ImmutableAggregationFactory.COUNT;
|
||||
static AggregatorFactory count() {
|
||||
return ImmutableAggregatorFactory.COUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -40,8 +39,8 @@ public interface AggregationFactory {
|
|||
* @return an {@code AggregationFactory} that calculates the last value of all recorded
|
||||
* measurements.
|
||||
*/
|
||||
static AggregationFactory lastValue() {
|
||||
return ImmutableAggregationFactory.LAST_VALUE;
|
||||
static AggregatorFactory lastValue() {
|
||||
return ImmutableAggregatorFactory.LAST_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,15 +51,15 @@ public interface AggregationFactory {
|
|||
* @return an {@code AggregationFactory} that calculates a simple summary of all recorded
|
||||
* measurements.
|
||||
*/
|
||||
static AggregationFactory minMaxSumCount() {
|
||||
return ImmutableAggregationFactory.MIN_MAX_SUM_COUNT;
|
||||
static AggregatorFactory minMaxSumCount() {
|
||||
return ImmutableAggregatorFactory.MIN_MAX_SUM_COUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link Aggregation}.
|
||||
* Returns a new {@link Aggregator}.
|
||||
*
|
||||
* @param instrumentValueType the type of recorded values for the {@code Instrument}.
|
||||
* @return a new {@link Aggregation}.
|
||||
* @return a new {@link Aggregator}.
|
||||
*/
|
||||
<T extends Accumulation> Aggregation<T> create(InstrumentValueType instrumentValueType);
|
||||
<T extends Accumulation> Aggregator<T> create(InstrumentValueType instrumentValueType);
|
||||
}
|
||||
|
|
@ -5,7 +5,14 @@
|
|||
|
||||
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;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
|
|
@ -39,6 +46,32 @@ public final class CountAggregator implements Aggregator<LongAccumulation> {
|
|||
return LongAccumulation.create(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
return LongAccumulation.create(a1.getValue() + a2.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
MetricDataUtils.toLongPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
|
||||
return MetricData.createLongSum(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
"1",
|
||||
MetricData.LongSumData.create(
|
||||
/* isMonotonic= */ true, MetricData.AggregationTemporality.CUMULATIVE, points));
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<LongAccumulation> {
|
||||
private final LongAdder current = new LongAdder();
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,14 @@
|
|||
|
||||
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;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
|
@ -43,6 +50,45 @@ public final class DoubleLastValueAggregator implements Aggregator<DoubleAccumul
|
|||
return DoubleAccumulation.create(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleAccumulation merge(DoubleAccumulation a1, DoubleAccumulation a2) {
|
||||
// TODO: Define the order between accumulation.
|
||||
return a2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, DoubleAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoublePoint> points =
|
||||
MetricDataUtils.toDoublePointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
|
||||
switch (descriptor.getType()) {
|
||||
case SUM_OBSERVER:
|
||||
return MetricDataUtils.toDoubleSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ true);
|
||||
case UP_DOWN_SUM_OBSERVER:
|
||||
return MetricDataUtils.toDoubleSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ false);
|
||||
case VALUE_OBSERVER:
|
||||
return MetricData.createDoubleGauge(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
descriptor.getUnit(),
|
||||
MetricData.DoubleGaugeData.create(points));
|
||||
case COUNTER:
|
||||
case UP_DOWN_COUNTER:
|
||||
case VALUE_RECORDER:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<DoubleAccumulation> {
|
||||
@Nullable private static final Double DEFAULT_VALUE = null;
|
||||
private final AtomicReference<Double> current = new AtomicReference<>(DEFAULT_VALUE);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,14 @@
|
|||
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;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
|
|
@ -37,6 +44,35 @@ public final class DoubleMinMaxSumCountAggregator
|
|||
return MinMaxSumCountAccumulation.create(1, value, value, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinMaxSumCountAccumulation merge(
|
||||
MinMaxSumCountAccumulation a1, MinMaxSumCountAccumulation a2) {
|
||||
return MinMaxSumCountAccumulation.create(
|
||||
a1.getCount() + a2.getCount(),
|
||||
a1.getSum() + a2.getSum(),
|
||||
Math.min(a1.getMin(), a2.getMin()),
|
||||
Math.max(a1.getMax(), a2.getMax()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, MinMaxSumCountAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoubleSummaryPoint> points =
|
||||
MetricDataUtils.toDoubleSummaryPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
return MetricData.createDoubleSummary(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
descriptor.getUnit(),
|
||||
MetricData.DoubleSummaryData.create(points));
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<MinMaxSumCountAccumulation> {
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
// The current value. This controls its own internal thread-safety via method access. Don't
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@
|
|||
|
||||
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;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.DoubleAdder;
|
||||
|
||||
public final class DoubleSumAggregator implements Aggregator<DoubleAccumulation> {
|
||||
|
|
@ -32,6 +40,28 @@ public final class DoubleSumAggregator implements Aggregator<DoubleAccumulation>
|
|||
return DoubleAccumulation.create(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DoubleAccumulation merge(DoubleAccumulation a1, DoubleAccumulation a2) {
|
||||
return DoubleAccumulation.create(a1.getValue() + a2.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, DoubleAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoublePoint> points =
|
||||
MetricDataUtils.toDoublePointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
boolean isMonotonic =
|
||||
descriptor.getType() == InstrumentType.COUNTER
|
||||
|| descriptor.getType() == InstrumentType.SUM_OBSERVER;
|
||||
return MetricDataUtils.toDoubleSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, isMonotonic);
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<DoubleAccumulation> {
|
||||
private final DoubleAdder current = new DoubleAdder();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
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 {
|
||||
static final AggregatorFactory SUM =
|
||||
new ImmutableAggregatorFactory<>(
|
||||
LongSumAggregator.getInstance(), DoubleSumAggregator.getInstance());
|
||||
|
||||
static final AggregatorFactory COUNT =
|
||||
new ImmutableAggregatorFactory<>(
|
||||
CountAggregator.getInstance(), CountAggregator.getInstance());
|
||||
|
||||
static final AggregatorFactory LAST_VALUE =
|
||||
new ImmutableAggregatorFactory<>(
|
||||
LongLastValueAggregator.getInstance(), DoubleLastValueAggregator.getInstance());
|
||||
|
||||
static final AggregatorFactory MIN_MAX_SUM_COUNT =
|
||||
new ImmutableAggregatorFactory<>(
|
||||
LongMinMaxSumCountAggregator.getInstance(), DoubleMinMaxSumCountAggregator.getInstance());
|
||||
|
||||
private final Aggregator<L> longAggregator;
|
||||
private final Aggregator<D> doubleAggregator;
|
||||
|
||||
private ImmutableAggregatorFactory(Aggregator<L> longAggregator, Aggregator<D> doubleAggregator) {
|
||||
this.longAggregator = longAggregator;
|
||||
this.doubleAggregator = doubleAggregator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Accumulation> Aggregator<T> create(InstrumentValueType instrumentValueType) {
|
||||
switch (instrumentValueType) {
|
||||
case LONG:
|
||||
return (Aggregator<T>) longAggregator;
|
||||
case DOUBLE:
|
||||
return (Aggregator<T>) doubleAggregator;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid instrument value type");
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,14 @@
|
|||
|
||||
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;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
|
@ -42,6 +49,45 @@ public final class LongLastValueAggregator implements Aggregator<LongAccumulatio
|
|||
return LongAccumulation.create(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
// TODO: Define the order between accumulation.
|
||||
return a2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
MetricDataUtils.toLongPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
|
||||
switch (descriptor.getType()) {
|
||||
case SUM_OBSERVER:
|
||||
return MetricDataUtils.toLongSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ true);
|
||||
case UP_DOWN_SUM_OBSERVER:
|
||||
return MetricDataUtils.toLongSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, /* isMonotonic= */ false);
|
||||
case VALUE_OBSERVER:
|
||||
return MetricData.createLongGauge(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
descriptor.getUnit(),
|
||||
MetricData.LongGaugeData.create(points));
|
||||
case COUNTER:
|
||||
case UP_DOWN_COUNTER:
|
||||
case VALUE_RECORDER:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<LongAccumulation> {
|
||||
private final AtomicReference<Long> current = new AtomicReference<>(DEFAULT_VALUE);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,14 @@
|
|||
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;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
|
|
@ -35,6 +42,35 @@ public final class LongMinMaxSumCountAggregator implements Aggregator<MinMaxSumC
|
|||
return MinMaxSumCountAccumulation.create(1, value, value, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinMaxSumCountAccumulation merge(
|
||||
MinMaxSumCountAccumulation a1, MinMaxSumCountAccumulation a2) {
|
||||
return MinMaxSumCountAccumulation.create(
|
||||
a1.getCount() + a2.getCount(),
|
||||
a1.getSum() + a2.getSum(),
|
||||
Math.min(a1.getMin(), a2.getMin()),
|
||||
Math.max(a1.getMax(), a2.getMax()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, MinMaxSumCountAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.DoubleSummaryPoint> points =
|
||||
MetricDataUtils.toDoubleSummaryPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
return MetricData.createDoubleSummary(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
descriptor.getName(),
|
||||
descriptor.getDescription(),
|
||||
descriptor.getUnit(),
|
||||
MetricData.DoubleSummaryData.create(points));
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<MinMaxSumCountAccumulation> {
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
// The current value. This controls its own internal thread-safety via method access. Don't
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@
|
|||
|
||||
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;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
|
||||
public final class LongSumAggregator implements Aggregator<LongAccumulation> {
|
||||
|
|
@ -32,6 +40,28 @@ public final class LongSumAggregator implements Aggregator<LongAccumulation> {
|
|||
return LongAccumulation.create(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongAccumulation merge(LongAccumulation a1, LongAccumulation a2) {
|
||||
return LongAccumulation.create(a1.getValue() + a2.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricData toMetricData(
|
||||
Resource resource,
|
||||
InstrumentationLibraryInfo instrumentationLibraryInfo,
|
||||
InstrumentDescriptor descriptor,
|
||||
Map<Labels, LongAccumulation> accumulationByLabels,
|
||||
long startEpochNanos,
|
||||
long epochNanos) {
|
||||
List<MetricData.LongPoint> points =
|
||||
MetricDataUtils.toLongPointList(accumulationByLabels, startEpochNanos, epochNanos);
|
||||
boolean isMonotonic =
|
||||
descriptor.getType() == InstrumentType.COUNTER
|
||||
|| descriptor.getType() == InstrumentType.SUM_OBSERVER;
|
||||
return MetricDataUtils.toLongSumMetricData(
|
||||
resource, instrumentationLibraryInfo, descriptor, points, isMonotonic);
|
||||
}
|
||||
|
||||
static final class Handle extends AggregatorHandle<LongAccumulation> {
|
||||
private final LongAdder current = new LongAdder();
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -6,14 +6,13 @@
|
|||
package io.opentelemetry.sdk.metrics.view;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.sdk.metrics.aggregation.Aggregation;
|
||||
import io.opentelemetry.sdk.metrics.aggregation.AggregationFactory;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An AggregationConfiguration describes how an aggregation should be performed. It includes both an
|
||||
* {@link Aggregation} which implements what shape of aggregation is created (i.e. histogram, sum,
|
||||
* {@code Aggregator} which implements what shape of aggregation is created (i.e. histogram, sum,
|
||||
* minMaxSumCount, etc), and a {@link MetricData.AggregationTemporality} which describes whether
|
||||
* aggregations should be reset with every collection interval, or continue to accumulate across
|
||||
* collection intervals.
|
||||
|
|
@ -24,13 +23,13 @@ public abstract class AggregationConfiguration {
|
|||
|
||||
/** Returns a new configuration with the provided options. */
|
||||
public static AggregationConfiguration create(
|
||||
AggregationFactory aggregationFactory,
|
||||
AggregatorFactory aggregatorFactory,
|
||||
MetricData.AggregationTemporality aggregationTemporality) {
|
||||
return new AutoValue_AggregationConfiguration(aggregationFactory, aggregationTemporality);
|
||||
return new AutoValue_AggregationConfiguration(aggregatorFactory, aggregationTemporality);
|
||||
}
|
||||
|
||||
/** Returns the {@link Aggregation} that should be used for this View. */
|
||||
public abstract AggregationFactory getAggregationFactory();
|
||||
/** Returns the {@link AggregatorFactory} that should be used for this View. */
|
||||
public abstract AggregatorFactory getAggregatorFactory();
|
||||
|
||||
/**
|
||||
* Returns the {@link MetricData.AggregationTemporality} that should be used for this View (delta
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import io.opentelemetry.api.metrics.LongUpDownCounter;
|
|||
import io.opentelemetry.api.metrics.LongValueRecorder;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.aggregation.AggregationFactory;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.view.AggregationConfiguration;
|
||||
|
|
@ -148,7 +148,7 @@ public class SdkMeterProviderTest {
|
|||
registerViewForAllTypes(
|
||||
testMeterProvider,
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.count(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.count(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
LongCounter longCounter = testSdk.longCounterBuilder("testLongCounter").build();
|
||||
longCounter.add(10, Labels.empty());
|
||||
LongUpDownCounter longUpDownCounter =
|
||||
|
|
@ -347,7 +347,7 @@ public class SdkMeterProviderTest {
|
|||
registerViewForAllTypes(
|
||||
testMeterProvider,
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.count(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.count(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
testSdk
|
||||
.longSumObserverBuilder("testLongSumObserver")
|
||||
.setUpdater(longResult -> longResult.observe(10, Labels.empty()))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import io.opentelemetry.api.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.aggregation.AggregationFactory;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorHandle;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -35,7 +35,7 @@ public class SynchronousInstrumentAccumulatorTest {
|
|||
DESCRIPTOR,
|
||||
providerSharedState,
|
||||
meterSharedState,
|
||||
AggregationFactory.count().create(DESCRIPTOR.getValueType())));
|
||||
AggregatorFactory.count().create(DESCRIPTOR.getValueType())));
|
||||
AggregatorHandle<?> aggregatorHandle = accumulator.bind(Labels.of("K", "V"));
|
||||
AggregatorHandle<?> duplicateAggregatorHandle = accumulator.bind(Labels.of("K", "V"));
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.aggregation.AggregationFactory;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
|
|
@ -34,7 +34,7 @@ class ViewRegistryTest {
|
|||
|
||||
AggregationConfiguration specification =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.count(), MetricData.AggregationTemporality.CUMULATIVE);
|
||||
AggregatorFactory.count(), MetricData.AggregationTemporality.CUMULATIVE);
|
||||
viewRegistry.registerView(
|
||||
InstrumentSelector.builder()
|
||||
.setInstrumentType(InstrumentType.COUNTER)
|
||||
|
|
@ -47,7 +47,7 @@ class ViewRegistryTest {
|
|||
descriptor,
|
||||
providerSharedState,
|
||||
meterSharedState,
|
||||
AggregationFactory.count().create(descriptor.getValueType()));
|
||||
AggregatorFactory.count().create(descriptor.getValueType()));
|
||||
|
||||
InstrumentProcessor<?> result =
|
||||
viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor);
|
||||
|
|
@ -72,7 +72,7 @@ class ViewRegistryTest {
|
|||
|
||||
AggregationConfiguration specification =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.count(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.count(), MetricData.AggregationTemporality.DELTA);
|
||||
viewRegistry.registerView(
|
||||
InstrumentSelector.builder()
|
||||
.setInstrumentType(InstrumentType.COUNTER)
|
||||
|
|
@ -85,7 +85,7 @@ class ViewRegistryTest {
|
|||
descriptor,
|
||||
providerSharedState,
|
||||
meterSharedState,
|
||||
AggregationFactory.count().create(descriptor.getValueType()));
|
||||
AggregatorFactory.count().create(descriptor.getValueType()));
|
||||
|
||||
InstrumentProcessor<?> result =
|
||||
viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor);
|
||||
|
|
@ -100,7 +100,7 @@ class ViewRegistryTest {
|
|||
void selection_onType() {
|
||||
AggregationConfiguration configuration =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
|
||||
ViewRegistry viewRegistry = new ViewRegistry();
|
||||
viewRegistry.registerView(
|
||||
|
|
@ -121,14 +121,14 @@ class ViewRegistryTest {
|
|||
"", "", "", InstrumentType.UP_DOWN_COUNTER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void selection_onName() {
|
||||
AggregationConfiguration configuration =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
|
||||
ViewRegistry viewRegistry = new ViewRegistry();
|
||||
viewRegistry.registerView(
|
||||
|
|
@ -149,17 +149,17 @@ class ViewRegistryTest {
|
|||
"default", "", "", InstrumentType.COUNTER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void selection_LastAddedViewWins() {
|
||||
AggregationConfiguration configuration1 =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregationConfiguration configuration2 =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.count(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.count(), MetricData.AggregationTemporality.DELTA);
|
||||
|
||||
ViewRegistry viewRegistry = new ViewRegistry();
|
||||
viewRegistry.registerView(
|
||||
|
|
@ -191,7 +191,7 @@ class ViewRegistryTest {
|
|||
void selection_regex() {
|
||||
AggregationConfiguration configuration1 =
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.DELTA);
|
||||
|
||||
ViewRegistry viewRegistry = new ViewRegistry();
|
||||
viewRegistry.registerView(
|
||||
|
|
@ -218,7 +218,7 @@ class ViewRegistryTest {
|
|||
"default", "", "", InstrumentType.UP_DOWN_COUNTER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -230,41 +230,41 @@ class ViewRegistryTest {
|
|||
"", "", "", InstrumentType.COUNTER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
assertThat(
|
||||
viewRegistry.chooseAggregation(
|
||||
InstrumentDescriptor.create(
|
||||
"", "", "", InstrumentType.UP_DOWN_COUNTER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.sum(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
assertThat(
|
||||
viewRegistry.chooseAggregation(
|
||||
InstrumentDescriptor.create(
|
||||
"", "", "", InstrumentType.VALUE_RECORDER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.minMaxSumCount(), MetricData.AggregationTemporality.DELTA));
|
||||
AggregatorFactory.minMaxSumCount(), MetricData.AggregationTemporality.DELTA));
|
||||
assertThat(
|
||||
viewRegistry.chooseAggregation(
|
||||
InstrumentDescriptor.create(
|
||||
"", "", "", InstrumentType.SUM_OBSERVER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.lastValue(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.lastValue(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
assertThat(
|
||||
viewRegistry.chooseAggregation(
|
||||
InstrumentDescriptor.create(
|
||||
"", "", "", InstrumentType.VALUE_OBSERVER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.lastValue(), MetricData.AggregationTemporality.DELTA));
|
||||
AggregatorFactory.lastValue(), MetricData.AggregationTemporality.DELTA));
|
||||
assertThat(
|
||||
viewRegistry.chooseAggregation(
|
||||
InstrumentDescriptor.create(
|
||||
"", "", "", InstrumentType.UP_DOWN_SUM_OBSERVER, InstrumentValueType.LONG)))
|
||||
.isEqualTo(
|
||||
AggregationConfiguration.create(
|
||||
AggregationFactory.lastValue(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
AggregatorFactory.lastValue(), MetricData.AggregationTemporality.CUMULATIVE));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
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.aggregator.AggregatorHandle;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.CountAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class CountAggregationTest {
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregation<LongAccumulation> count =
|
||||
AggregationFactory.count().create(InstrumentValueType.LONG);
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = count.getAggregator().createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
count.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_RECORDER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getUnit()).isEqualTo("1");
|
||||
assertThat(metricData.getType()).isEqualTo(MetricData.Type.LONG_SUM);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAggregatorFactory() {
|
||||
AggregationFactory count = AggregationFactory.count();
|
||||
assertThat(count.create(InstrumentValueType.LONG).getAggregator())
|
||||
.isInstanceOf(CountAggregator.getInstance().getClass());
|
||||
assertThat(count.create(InstrumentValueType.DOUBLE).getAggregator())
|
||||
.isInstanceOf(CountAggregator.getInstance().getClass());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
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.aggregator.AggregatorHandle;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.DoubleLastValueAggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.LongLastValueAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class LastValueAggregationTest {
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregation<LongAccumulation> lastValue =
|
||||
AggregationFactory.lastValue().create(InstrumentValueType.LONG);
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = lastValue.getAggregator().createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
lastValue.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_OBSERVER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getType()).isEqualTo(MetricData.Type.LONG_GAUGE);
|
||||
assertThat(metricData.getLongGaugeData().getPoints())
|
||||
.containsExactly(MetricData.LongPoint.create(0, 100, Labels.empty(), 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAggregatorFactory() {
|
||||
AggregationFactory lastValue = AggregationFactory.lastValue();
|
||||
assertThat(lastValue.create(InstrumentValueType.LONG).getAggregator())
|
||||
.isInstanceOf(LongLastValueAggregator.getInstance().getClass());
|
||||
assertThat(lastValue.create(InstrumentValueType.DOUBLE).getAggregator())
|
||||
.isInstanceOf(DoubleLastValueAggregator.getInstance().getClass());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
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.MinMaxSumCountAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorHandle;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.DoubleMinMaxSumCountAggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.LongMinMaxSumCountAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MinMaxSumCountAggregationTest {
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregation<MinMaxSumCountAccumulation> minMaxSumCount =
|
||||
AggregationFactory.minMaxSumCount().create(InstrumentValueType.LONG);
|
||||
AggregatorHandle<MinMaxSumCountAccumulation> aggregatorHandle =
|
||||
minMaxSumCount.getAggregator().createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
minMaxSumCount.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_RECORDER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getType()).isEqualTo(MetricData.Type.SUMMARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAggregatorFactory() {
|
||||
AggregationFactory minMaxSumCount = AggregationFactory.minMaxSumCount();
|
||||
assertThat(minMaxSumCount.create(InstrumentValueType.LONG).getAggregator())
|
||||
.isInstanceOf(LongMinMaxSumCountAggregator.getInstance().getClass());
|
||||
assertThat(minMaxSumCount.create(InstrumentValueType.DOUBLE).getAggregator())
|
||||
.isInstanceOf(DoubleMinMaxSumCountAggregator.getInstance().getClass());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregation;
|
||||
|
||||
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.accumulation.LongAccumulation;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorHandle;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.DoubleSumAggregator;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.LongSumAggregator;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link AggregationFactory#sum()}. */
|
||||
class SumAggregationTest {
|
||||
|
||||
@Test
|
||||
void toDoubleMetricData() {
|
||||
Aggregation<DoubleAccumulation> sum = DoubleSumAggregation.INSTANCE;
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle = sum.getAggregator().createHandle();
|
||||
aggregatorHandle.recordDouble(10);
|
||||
|
||||
MetricData metricData =
|
||||
sum.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name", "description", "unit", InstrumentType.COUNTER, InstrumentValueType.DOUBLE),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getType()).isEqualTo(MetricData.Type.DOUBLE_SUM);
|
||||
assertThat(metricData.getDoubleSumData().getPoints())
|
||||
.containsExactly(MetricData.DoublePoint.create(0, 100, Labels.empty(), 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toLongMetricData() {
|
||||
Aggregation<LongAccumulation> sum = LongSumAggregation.INSTANCE;
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = sum.getAggregator().createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
sum.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name", "description", "unit", InstrumentType.COUNTER, InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getType()).isEqualTo(MetricData.Type.LONG_SUM);
|
||||
assertThat(metricData.getLongSumData().getPoints())
|
||||
.containsExactly(MetricData.LongPoint.create(0, 100, Labels.empty(), 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAggregatorFactory() {
|
||||
AggregationFactory sum = AggregationFactory.sum();
|
||||
assertThat(sum.create(InstrumentValueType.LONG).getAggregator())
|
||||
.isInstanceOf(LongSumAggregator.getInstance().getClass());
|
||||
assertThat(sum.create(InstrumentValueType.DOUBLE).getAggregator())
|
||||
.isInstanceOf(DoubleSumAggregator.getInstance().getClass());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class AggregatorFactoryTest {
|
||||
@Test
|
||||
void getCountAggregatorFactory() {
|
||||
AggregatorFactory count = AggregatorFactory.count();
|
||||
assertThat(count.create(InstrumentValueType.LONG))
|
||||
.isInstanceOf(CountAggregator.getInstance().getClass());
|
||||
assertThat(count.create(InstrumentValueType.DOUBLE))
|
||||
.isInstanceOf(CountAggregator.getInstance().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLastValueAggregatorFactory() {
|
||||
AggregatorFactory lastValue = AggregatorFactory.lastValue();
|
||||
assertThat(lastValue.create(InstrumentValueType.LONG))
|
||||
.isInstanceOf(LongLastValueAggregator.getInstance().getClass());
|
||||
assertThat(lastValue.create(InstrumentValueType.DOUBLE))
|
||||
.isInstanceOf(DoubleLastValueAggregator.getInstance().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getMinMaxSumCountAggregatorFactory() {
|
||||
AggregatorFactory minMaxSumCount = AggregatorFactory.minMaxSumCount();
|
||||
assertThat(minMaxSumCount.create(InstrumentValueType.LONG))
|
||||
.isInstanceOf(LongMinMaxSumCountAggregator.getInstance().getClass());
|
||||
assertThat(minMaxSumCount.create(InstrumentValueType.DOUBLE))
|
||||
.isInstanceOf(DoubleMinMaxSumCountAggregator.getInstance().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getSumAggregatorFactory() {
|
||||
AggregatorFactory sum = AggregatorFactory.sum();
|
||||
assertThat(sum.create(InstrumentValueType.LONG))
|
||||
.isInstanceOf(LongSumAggregator.getInstance().getClass());
|
||||
assertThat(sum.create(InstrumentValueType.DOUBLE))
|
||||
.isInstanceOf(DoubleSumAggregator.getInstance().getClass());
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,15 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
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;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link CountAggregator}. */
|
||||
|
|
@ -42,4 +50,38 @@ class CountAggregatorTest {
|
|||
aggregatorHandle.recordDouble(12.3);
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<LongAccumulation> count = CountAggregator.getInstance();
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = count.createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
count.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_RECORDER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData)
|
||||
.isEqualTo(
|
||||
MetricData.createLongSum(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
MetricData.LongSumData.create(
|
||||
/* isMonotonic= */ true,
|
||||
MetricData.AggregationTemporality.CUMULATIVE,
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(0, 100, Labels.empty(), 1)))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,15 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
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;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link AggregatorHandle}. */
|
||||
|
|
@ -43,4 +51,36 @@ class DoubleLastValueAggregatorTest {
|
|||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(12.1));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<DoubleAccumulation> lastValue = DoubleLastValueAggregator.getInstance();
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle = lastValue.createHandle();
|
||||
aggregatorHandle.recordDouble(10);
|
||||
|
||||
MetricData metricData =
|
||||
lastValue.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_OBSERVER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData)
|
||||
.isEqualTo(
|
||||
MetricData.createDoubleGauge(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
MetricData.DoubleGaugeData.create(
|
||||
Collections.singletonList(
|
||||
MetricData.DoublePoint.create(0, 100, Labels.empty(), 10)))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,17 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
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.aggregation.AggregationFactory;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
|
@ -62,6 +68,30 @@ class DoubleMinMaxSumCountAggregatorTest {
|
|||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<MinMaxSumCountAccumulation> minMaxSumCount =
|
||||
DoubleMinMaxSumCountAggregator.getInstance();
|
||||
AggregatorHandle<MinMaxSumCountAccumulation> aggregatorHandle = minMaxSumCount.createHandle();
|
||||
aggregatorHandle.recordDouble(10);
|
||||
|
||||
MetricData metricData =
|
||||
minMaxSumCount.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_RECORDER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getType()).isEqualTo(MetricData.Type.SUMMARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultithreadedUpdates() throws Exception {
|
||||
final AggregatorHandle<MinMaxSumCountAccumulation> aggregatorHandle =
|
||||
|
|
@ -126,7 +156,7 @@ class DoubleMinMaxSumCountAggregatorTest {
|
|||
return;
|
||||
}
|
||||
accumulation =
|
||||
AggregationFactory.minMaxSumCount()
|
||||
AggregatorFactory.minMaxSumCount()
|
||||
.create(InstrumentValueType.DOUBLE)
|
||||
.merge(accumulation, other);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,15 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
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;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link DoubleSumAggregator}. */
|
||||
|
|
@ -60,4 +68,34 @@ class DoubleSumAggregatorTest {
|
|||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(DoubleAccumulation.create(-13));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<DoubleAccumulation> sum = DoubleSumAggregator.getInstance();
|
||||
AggregatorHandle<DoubleAccumulation> aggregatorHandle = sum.createHandle();
|
||||
aggregatorHandle.recordDouble(10);
|
||||
|
||||
MetricData metricData =
|
||||
sum.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name", "description", "unit", InstrumentType.COUNTER, InstrumentValueType.DOUBLE),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData)
|
||||
.isEqualTo(
|
||||
MetricData.createDoubleSum(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
MetricData.DoubleSumData.create(
|
||||
/* isMonotonic= */ true,
|
||||
MetricData.AggregationTemporality.CUMULATIVE,
|
||||
Collections.singletonList(
|
||||
MetricData.DoublePoint.create(0, 100, Labels.empty(), 10)))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,15 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
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;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link LongLastValueAggregator}. */
|
||||
|
|
@ -43,4 +51,36 @@ class LongLastValueAggregatorTest {
|
|||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(12));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<LongAccumulation> lastValue = LongLastValueAggregator.getInstance();
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = lastValue.createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
lastValue.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_OBSERVER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData)
|
||||
.isEqualTo(
|
||||
MetricData.createLongGauge(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
MetricData.LongGaugeData.create(
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(0, 100, Labels.empty(), 10)))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,17 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
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.aggregation.AggregationFactory;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
|
@ -59,6 +65,30 @@ class LongMinMaxSumCountAggregatorTest {
|
|||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<MinMaxSumCountAccumulation> minMaxSumCount =
|
||||
LongMinMaxSumCountAggregator.getInstance();
|
||||
AggregatorHandle<MinMaxSumCountAccumulation> aggregatorHandle = minMaxSumCount.createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
minMaxSumCount.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
InstrumentType.VALUE_RECORDER,
|
||||
InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getType()).isEqualTo(MetricData.Type.SUMMARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultithreadedUpdates() throws Exception {
|
||||
final AggregatorHandle<MinMaxSumCountAccumulation> aggregatorHandle =
|
||||
|
|
@ -123,7 +153,7 @@ class LongMinMaxSumCountAggregatorTest {
|
|||
return;
|
||||
}
|
||||
accumulation =
|
||||
AggregationFactory.minMaxSumCount()
|
||||
AggregatorFactory.minMaxSumCount()
|
||||
.create(InstrumentValueType.LONG)
|
||||
.merge(accumulation, other);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,15 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
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;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link LongSumAggregator}. */
|
||||
|
|
@ -61,4 +69,34 @@ class LongSumAggregatorTest {
|
|||
assertThat(aggregatorHandle.accumulateThenReset()).isEqualTo(LongAccumulation.create(-13));
|
||||
assertThat(aggregatorHandle.accumulateThenReset()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toMetricData() {
|
||||
Aggregator<LongAccumulation> sum = LongSumAggregator.getInstance();
|
||||
AggregatorHandle<LongAccumulation> aggregatorHandle = sum.createHandle();
|
||||
aggregatorHandle.recordLong(10);
|
||||
|
||||
MetricData metricData =
|
||||
sum.toMetricData(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
InstrumentDescriptor.create(
|
||||
"name", "description", "unit", InstrumentType.COUNTER, InstrumentValueType.LONG),
|
||||
Collections.singletonMap(Labels.empty(), aggregatorHandle.accumulateThenReset()),
|
||||
0,
|
||||
100);
|
||||
assertThat(metricData)
|
||||
.isEqualTo(
|
||||
MetricData.createLongSum(
|
||||
Resource.getDefault(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
"name",
|
||||
"description",
|
||||
"unit",
|
||||
MetricData.LongSumData.create(
|
||||
/* isMonotonic= */ true,
|
||||
MetricData.AggregationTemporality.CUMULATIVE,
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(0, 100, Labels.empty(), 10)))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue