Extract HistogramData interface for DoubleHistogramData. (#4219)
* Extract HistogramData interface for DoubleHistogramData. * Fix * javadoc * Fix merge
This commit is contained in:
parent
5cbfe9d93e
commit
17265d0b0d
|
@ -11,7 +11,7 @@ import io.opentelemetry.exporter.internal.marshal.Serializer;
|
|||
import io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler;
|
||||
import io.opentelemetry.proto.metrics.v1.internal.HistogramDataPoint;
|
||||
import io.opentelemetry.sdk.internal.PrimitiveLongList;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -26,16 +26,16 @@ final class HistogramDataPointMarshaler extends MarshalerWithSize {
|
|||
private final ExemplarMarshaler[] exemplars;
|
||||
private final KeyValueMarshaler[] attributes;
|
||||
|
||||
static HistogramDataPointMarshaler[] createRepeated(Collection<DoubleHistogramPointData> points) {
|
||||
static HistogramDataPointMarshaler[] createRepeated(Collection<HistogramPointData> points) {
|
||||
HistogramDataPointMarshaler[] marshalers = new HistogramDataPointMarshaler[points.size()];
|
||||
int index = 0;
|
||||
for (DoubleHistogramPointData point : points) {
|
||||
for (HistogramPointData point : points) {
|
||||
marshalers[index++] = HistogramDataPointMarshaler.create(point);
|
||||
}
|
||||
return marshalers;
|
||||
}
|
||||
|
||||
static HistogramDataPointMarshaler create(DoubleHistogramPointData point) {
|
||||
static HistogramDataPointMarshaler create(HistogramPointData point) {
|
||||
KeyValueMarshaler[] attributeMarshalers =
|
||||
KeyValueMarshaler.createRepeated(point.getAttributes());
|
||||
ExemplarMarshaler[] exemplarMarshalers = ExemplarMarshaler.createRepeated(point.getExemplars());
|
||||
|
|
|
@ -10,14 +10,14 @@ import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize;
|
|||
import io.opentelemetry.exporter.internal.marshal.ProtoEnumInfo;
|
||||
import io.opentelemetry.exporter.internal.marshal.Serializer;
|
||||
import io.opentelemetry.proto.metrics.v1.internal.Histogram;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramData;
|
||||
import java.io.IOException;
|
||||
|
||||
final class HistogramMarshaler extends MarshalerWithSize {
|
||||
private final HistogramDataPointMarshaler[] dataPoints;
|
||||
private final ProtoEnumInfo aggregationTemporality;
|
||||
|
||||
static HistogramMarshaler create(DoubleHistogramData histogram) {
|
||||
static HistogramMarshaler create(HistogramData histogram) {
|
||||
HistogramDataPointMarshaler[] dataPointMarshalers =
|
||||
HistogramDataPointMarshaler.createRepeated(histogram.getPoints());
|
||||
return new HistogramMarshaler(
|
||||
|
|
|
@ -53,7 +53,7 @@ final class MetricMarshaler extends MarshalerWithSize {
|
|||
dataField = Metric.SUMMARY;
|
||||
break;
|
||||
case HISTOGRAM:
|
||||
dataMarshaler = HistogramMarshaler.create(metric.getDoubleHistogramData());
|
||||
dataMarshaler = HistogramMarshaler.create(metric.getHistogramData());
|
||||
dataField = Metric.HISTOGRAM;
|
||||
break;
|
||||
case EXPONENTIAL_HISTOGRAM:
|
||||
|
|
|
@ -42,17 +42,18 @@ import io.opentelemetry.proto.metrics.v1.SummaryDataPoint;
|
|||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.PointData;
|
||||
import io.opentelemetry.sdk.metrics.data.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramBuckets;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData;
|
||||
|
@ -339,9 +340,9 @@ class MetricsRequestMarshalerTest {
|
|||
assertThat(
|
||||
toHistogramDataPoints(
|
||||
ImmutableList.of(
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
123, 456, KV_ATTR, 14.2, ImmutableList.of(1.0), ImmutableList.of(1L, 5L)),
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
123,
|
||||
456,
|
||||
Attributes.empty(),
|
||||
|
@ -733,10 +734,10 @@ class MetricsRequestMarshalerTest {
|
|||
"name",
|
||||
"description",
|
||||
"1",
|
||||
DoubleHistogramData.create(
|
||||
ImmutableHistogramData.create(
|
||||
AggregationTemporality.DELTA,
|
||||
singletonList(
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
123,
|
||||
456,
|
||||
KV_ATTR,
|
||||
|
@ -969,7 +970,7 @@ class MetricsRequestMarshalerTest {
|
|||
}
|
||||
|
||||
private static List<HistogramDataPoint> toHistogramDataPoints(
|
||||
Collection<DoubleHistogramPointData> points) {
|
||||
Collection<HistogramPointData> points) {
|
||||
return points.stream()
|
||||
.map(
|
||||
point ->
|
||||
|
|
|
@ -11,10 +11,10 @@ import io.opentelemetry.api.common.Attributes;
|
|||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.ExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
@ -154,7 +154,7 @@ final class MetricAdapter {
|
|||
break;
|
||||
case HISTOGRAM:
|
||||
addHistogramSamples(
|
||||
(DoubleHistogramPointData) pointData, name, labelNames, labelValues, samples);
|
||||
(HistogramPointData) pointData, name, labelNames, labelValues, samples);
|
||||
break;
|
||||
case EXPONENTIAL_HISTOGRAM:
|
||||
break; // todo
|
||||
|
@ -207,7 +207,7 @@ final class MetricAdapter {
|
|||
}
|
||||
|
||||
private static void addHistogramSamples(
|
||||
DoubleHistogramPointData doubleHistogramPointData,
|
||||
HistogramPointData histogramPointData,
|
||||
String name,
|
||||
List<String> labelNames,
|
||||
List<String> labelValues,
|
||||
|
@ -217,30 +217,30 @@ final class MetricAdapter {
|
|||
name + SAMPLE_SUFFIX_COUNT,
|
||||
labelNames,
|
||||
labelValues,
|
||||
doubleHistogramPointData.getCount(),
|
||||
histogramPointData.getCount(),
|
||||
null,
|
||||
doubleHistogramPointData.getEpochNanos()));
|
||||
histogramPointData.getEpochNanos()));
|
||||
|
||||
samples.add(
|
||||
createSample(
|
||||
name + SAMPLE_SUFFIX_SUM,
|
||||
labelNames,
|
||||
labelValues,
|
||||
doubleHistogramPointData.getSum(),
|
||||
histogramPointData.getSum(),
|
||||
null,
|
||||
doubleHistogramPointData.getEpochNanos()));
|
||||
histogramPointData.getEpochNanos()));
|
||||
|
||||
List<String> labelNamesWithLe = new ArrayList<>(labelNames.size() + 1);
|
||||
labelNamesWithLe.addAll(labelNames);
|
||||
labelNamesWithLe.add(LABEL_NAME_LE);
|
||||
|
||||
long cumulativeCount = 0;
|
||||
List<Long> counts = doubleHistogramPointData.getCounts();
|
||||
List<Long> counts = histogramPointData.getCounts();
|
||||
for (int i = 0; i < counts.size(); i++) {
|
||||
List<String> labelValuesWithLe = new ArrayList<>(labelValues.size() + 1);
|
||||
// This is the upper boundary (inclusive). I.e. all values should be < this value (LE -
|
||||
// Less-then-or-Equal).
|
||||
double boundary = doubleHistogramPointData.getBucketUpperBound(i);
|
||||
double boundary = histogramPointData.getBucketUpperBound(i);
|
||||
labelValuesWithLe.addAll(labelValues);
|
||||
labelValuesWithLe.add(doubleToGoString(boundary));
|
||||
|
||||
|
@ -252,10 +252,10 @@ final class MetricAdapter {
|
|||
labelValuesWithLe,
|
||||
cumulativeCount,
|
||||
filterExemplars(
|
||||
doubleHistogramPointData.getExemplars(),
|
||||
doubleHistogramPointData.getBucketLowerBound(i),
|
||||
histogramPointData.getExemplars(),
|
||||
histogramPointData.getBucketLowerBound(i),
|
||||
boundary),
|
||||
doubleHistogramPointData.getEpochNanos()));
|
||||
histogramPointData.getEpochNanos()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ final class MetricAdapter {
|
|||
case SUMMARY:
|
||||
return metricData.getDoubleSummaryData().getPoints();
|
||||
case HISTOGRAM:
|
||||
return metricData.getDoubleHistogramData().getPoints();
|
||||
return metricData.getHistogramData().getPoints();
|
||||
case EXPONENTIAL_HISTOGRAM:
|
||||
return ExponentialHistogramData.fromMetricData(metricData).getPoints();
|
||||
}
|
||||
|
|
|
@ -25,10 +25,10 @@ import io.opentelemetry.api.common.AttributeKey;
|
|||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.SpanContext;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.ExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
@ -149,7 +149,7 @@ abstract class Serializer {
|
|||
point.getEpochNanos());
|
||||
break;
|
||||
case HISTOGRAM:
|
||||
writeHistogram(writer, name, (DoubleHistogramPointData) point);
|
||||
writeHistogram(writer, name, (HistogramPointData) point);
|
||||
break;
|
||||
case SUMMARY:
|
||||
writeSummary(writer, name, (DoubleSummaryPointData) point);
|
||||
|
@ -160,7 +160,7 @@ abstract class Serializer {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeHistogram(Writer writer, String name, DoubleHistogramPointData point)
|
||||
private void writeHistogram(Writer writer, String name, HistogramPointData point)
|
||||
throws IOException {
|
||||
writePoint(
|
||||
writer, name + "_count", point.getCount(), point.getAttributes(), point.getEpochNanos());
|
||||
|
|
|
@ -15,8 +15,6 @@ import io.opentelemetry.api.trace.TraceFlags;
|
|||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
|
@ -26,6 +24,8 @@ import io.opentelemetry.sdk.metrics.data.MetricData;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricDataType;
|
||||
import io.opentelemetry.sdk.metrics.data.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import io.prometheus.client.Collector;
|
||||
|
@ -200,10 +200,10 @@ class MetricAdapterTest {
|
|||
"instrument.name",
|
||||
"description",
|
||||
"1",
|
||||
DoubleHistogramData.create(
|
||||
ImmutableHistogramData.create(
|
||||
AggregationTemporality.DELTA,
|
||||
Collections.singletonList(
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
1633947011000000000L,
|
||||
1633950672000000000L,
|
||||
KP_VP_ATTR,
|
||||
|
@ -537,7 +537,7 @@ class MetricAdapterTest {
|
|||
"full_name",
|
||||
MetricDataType.HISTOGRAM,
|
||||
ImmutableList.of(
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
1633939689000000000L,
|
||||
1633943350000000000L,
|
||||
KP_VP_ATTR,
|
||||
|
|
|
@ -14,8 +14,6 @@ import io.opentelemetry.api.trace.TraceFlags;
|
|||
import io.opentelemetry.api.trace.TraceState;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
|
@ -24,6 +22,8 @@ import io.opentelemetry.sdk.metrics.data.LongPointData;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -190,10 +190,10 @@ class SerializerTest {
|
|||
"instrument.name",
|
||||
"description",
|
||||
"1",
|
||||
DoubleHistogramData.create(
|
||||
ImmutableHistogramData.create(
|
||||
AggregationTemporality.DELTA,
|
||||
Collections.singletonList(
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
1633947011000000000L,
|
||||
1633950672000000000L,
|
||||
KP_VP_ATTR,
|
||||
|
|
|
@ -23,18 +23,20 @@ import io.opentelemetry.api.trace.TraceState;
|
|||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.ExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.GaugeData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.SumData;
|
||||
import io.opentelemetry.sdk.metrics.data.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.ArrayList;
|
||||
|
@ -155,13 +157,13 @@ public final class MetricAdapter {
|
|||
true, AggregationTemporality.CUMULATIVE, convertDoublePoints(censusMetric));
|
||||
}
|
||||
|
||||
static DoubleHistogramData convertHistogram(Metric censusMetric) {
|
||||
return DoubleHistogramData.create(
|
||||
static HistogramData convertHistogram(Metric censusMetric) {
|
||||
return ImmutableHistogramData.create(
|
||||
AggregationTemporality.CUMULATIVE, convertHistogramPoints(censusMetric));
|
||||
}
|
||||
|
||||
static DoubleHistogramData convertGaugeHistogram(Metric censusMetric) {
|
||||
return DoubleHistogramData.create(
|
||||
static HistogramData convertGaugeHistogram(Metric censusMetric) {
|
||||
return ImmutableHistogramData.create(
|
||||
AggregationTemporality.DELTA, convertHistogramPoints(censusMetric));
|
||||
}
|
||||
|
||||
|
@ -204,25 +206,25 @@ public final class MetricAdapter {
|
|||
return result;
|
||||
}
|
||||
|
||||
static Collection<DoubleHistogramPointData> convertHistogramPoints(Metric censusMetric) {
|
||||
static Collection<HistogramPointData> convertHistogramPoints(Metric censusMetric) {
|
||||
boolean isGauge =
|
||||
censusMetric.getMetricDescriptor().getType() == MetricDescriptor.Type.GAUGE_DISTRIBUTION;
|
||||
// TODO - preallocate array to correct size.
|
||||
List<DoubleHistogramPointData> result = new ArrayList<>();
|
||||
List<HistogramPointData> result = new ArrayList<>();
|
||||
for (TimeSeries ts : censusMetric.getTimeSeriesList()) {
|
||||
long startTimestamp = mapTimestamp(ts.getStartTimestamp());
|
||||
Attributes attributes =
|
||||
mapAttributes(censusMetric.getMetricDescriptor().getLabelKeys(), ts.getLabelValues());
|
||||
for (Point point : ts.getPoints()) {
|
||||
long endTimestamp = mapTimestamp(point.getTimestamp());
|
||||
DoubleHistogramPointData otelPoint =
|
||||
HistogramPointData otelPoint =
|
||||
point
|
||||
.getValue()
|
||||
.match(
|
||||
doubleValue -> null,
|
||||
longValue -> null,
|
||||
distribution ->
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
// Report Gauge histograms as DELTA with "instantaneous" time window.
|
||||
isGauge ? endTimestamp : startTimestamp,
|
||||
endTimestamp,
|
||||
|
|
|
@ -6,22 +6,21 @@
|
|||
package io.opentelemetry.sdk.testing.assertj;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.assertj.core.api.AbstractIterableAssert;
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
/** Test assertions for {@link DoubleHistogramData}. */
|
||||
public class DoubleHistogramAssert
|
||||
extends AbstractAssert<DoubleHistogramAssert, DoubleHistogramData> {
|
||||
/** Test assertions for {@link HistogramData}. */
|
||||
public class HistogramAssert extends AbstractAssert<HistogramAssert, HistogramData> {
|
||||
|
||||
protected DoubleHistogramAssert(DoubleHistogramData actual) {
|
||||
super(actual, DoubleHistogramAssert.class);
|
||||
protected HistogramAssert(HistogramData actual) {
|
||||
super(actual, HistogramAssert.class);
|
||||
}
|
||||
|
||||
/** Ensures that {@code aggregation_temporality} field is {@code CUMULATIVE}. */
|
||||
public DoubleHistogramAssert isCumulative() {
|
||||
public HistogramAssert isCumulative() {
|
||||
isNotNull();
|
||||
if (actual.getAggregationTemporality() != AggregationTemporality.CUMULATIVE) {
|
||||
failWithActualExpectedAndMessage(
|
||||
|
@ -35,7 +34,7 @@ public class DoubleHistogramAssert
|
|||
}
|
||||
|
||||
/** Ensures that {@code aggregation_temporality} field is {@code DELTA}. */
|
||||
public DoubleHistogramAssert isDelta() {
|
||||
public HistogramAssert isDelta() {
|
||||
isNotNull();
|
||||
if (actual.getAggregationTemporality() != AggregationTemporality.DELTA) {
|
||||
failWithActualExpectedAndMessage(
|
||||
|
@ -50,7 +49,7 @@ public class DoubleHistogramAssert
|
|||
|
||||
/** Returns convenience API to assert against the {@code points} field. */
|
||||
public AbstractIterableAssert<
|
||||
?, ? extends Iterable<? extends DoubleHistogramPointData>, DoubleHistogramPointData, ?>
|
||||
?, ? extends Iterable<? extends HistogramPointData>, HistogramPointData, ?>
|
||||
points() {
|
||||
isNotNull();
|
||||
return Assertions.assertThat(actual.getPoints());
|
|
@ -5,34 +5,34 @@
|
|||
|
||||
package io.opentelemetry.sdk.testing.assertj;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import java.util.Arrays;
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
/** Test assertions for {@link DoubleHistogramPointData}. */
|
||||
public class DoubleHistogramPointDataAssert
|
||||
extends AbstractPointDataAssert<DoubleHistogramPointDataAssert, DoubleHistogramPointData> {
|
||||
/** Test assertions for {@link HistogramPointData}. */
|
||||
public class HistogramPointDataAssert
|
||||
extends AbstractPointDataAssert<HistogramPointDataAssert, HistogramPointData> {
|
||||
|
||||
protected DoubleHistogramPointDataAssert(DoubleHistogramPointData actual) {
|
||||
super(actual, DoubleHistogramPointDataAssert.class);
|
||||
protected HistogramPointDataAssert(HistogramPointData actual) {
|
||||
super(actual, HistogramPointDataAssert.class);
|
||||
}
|
||||
|
||||
/** Ensures the {@code sum} field matches the expected value. */
|
||||
public DoubleHistogramPointDataAssert hasSum(double expected) {
|
||||
public HistogramPointDataAssert hasSum(double expected) {
|
||||
isNotNull();
|
||||
Assertions.assertThat(actual.getSum()).as("sum").isEqualTo(expected);
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Ensures the {@code sum} field contains a greater value than the passed {@code boundary}. */
|
||||
public DoubleHistogramPointDataAssert hasSumGreaterThan(double boundary) {
|
||||
public HistogramPointDataAssert hasSumGreaterThan(double boundary) {
|
||||
isNotNull();
|
||||
Assertions.assertThat(actual.getSum()).as("sum").isGreaterThan(boundary);
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Ensures the {@code count} field matches the expected value. */
|
||||
public DoubleHistogramPointDataAssert hasCount(long expected) {
|
||||
public HistogramPointDataAssert hasCount(long expected) {
|
||||
isNotNull();
|
||||
Assertions.assertThat(actual.getCount()).as("count").isEqualTo(expected);
|
||||
return this;
|
||||
|
@ -43,7 +43,7 @@ public class DoubleHistogramPointDataAssert
|
|||
*
|
||||
* @param boundaries The set of bucket boundaries in the same order as the expected collection.
|
||||
*/
|
||||
public DoubleHistogramPointDataAssert hasBucketBoundaries(double... boundaries) {
|
||||
public HistogramPointDataAssert hasBucketBoundaries(double... boundaries) {
|
||||
isNotNull();
|
||||
Double[] bigBoundaries = Arrays.stream(boundaries).boxed().toArray(Double[]::new);
|
||||
Assertions.assertThat(actual.getBoundaries()).as("boundaries").containsExactly(bigBoundaries);
|
||||
|
@ -55,7 +55,7 @@ public class DoubleHistogramPointDataAssert
|
|||
*
|
||||
* @param counts The set of bucket counts in the same order as the expected collection.
|
||||
*/
|
||||
public DoubleHistogramPointDataAssert hasBucketCounts(long... counts) {
|
||||
public HistogramPointDataAssert hasBucketCounts(long... counts) {
|
||||
isNotNull();
|
||||
Long[] bigCounts = Arrays.stream(counts).boxed().toArray(Long[]::new);
|
||||
Assertions.assertThat(actual.getCounts()).as("bucketCounts").containsExactly(bigCounts);
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
package io.opentelemetry.sdk.testing.assertj;
|
||||
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.ExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.GaugeData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.PointData;
|
||||
|
@ -32,9 +32,9 @@ public final class MetricAssertions extends Assertions {
|
|||
return new GaugeAssert<>(metric);
|
||||
}
|
||||
|
||||
/** Returns an assertion for {@link DoubleHistogramData}. */
|
||||
public static DoubleHistogramAssert assertThat(DoubleHistogramData metric) {
|
||||
return new DoubleHistogramAssert(metric);
|
||||
/** Returns an assertion for {@link HistogramData}. */
|
||||
public static HistogramAssert assertThat(HistogramData metric) {
|
||||
return new HistogramAssert(metric);
|
||||
}
|
||||
|
||||
/** Returns an assertion for {@link DoubleSummaryData}. */
|
||||
|
@ -42,9 +42,9 @@ public final class MetricAssertions extends Assertions {
|
|||
return new DoubleSummaryDataAssert(metric);
|
||||
}
|
||||
|
||||
/** Returns an assertion for {@link DoubleHistogramPointData}. */
|
||||
public static DoubleHistogramPointDataAssert assertThat(DoubleHistogramPointData point) {
|
||||
return new DoubleHistogramPointDataAssert(point);
|
||||
/** Returns an assertion for {@link HistogramPointData}. */
|
||||
public static HistogramPointDataAssert assertThat(HistogramPointData point) {
|
||||
return new HistogramPointDataAssert(point);
|
||||
}
|
||||
|
||||
/** Returns an assertion for {@link DoubleSummaryPointData}. */
|
||||
|
|
|
@ -99,7 +99,7 @@ public class MetricDataAssert extends AbstractAssert<MetricDataAssert, MetricDat
|
|||
*
|
||||
* @return convenience API to assert against the {@code DoubleHistogram}.
|
||||
*/
|
||||
public DoubleHistogramAssert hasDoubleHistogram() {
|
||||
public HistogramAssert hasDoubleHistogram() {
|
||||
isNotNull();
|
||||
if (actual.getType() != MetricDataType.HISTOGRAM) {
|
||||
failWithActualExpectedAndMessage(
|
||||
|
@ -109,7 +109,7 @@ public class MetricDataAssert extends AbstractAssert<MetricDataAssert, MetricDat
|
|||
MetricDataType.HISTOGRAM,
|
||||
actual.getType());
|
||||
}
|
||||
return new DoubleHistogramAssert(actual.getDoubleHistogramData());
|
||||
return new HistogramAssert(actual.getHistogramData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,16 +16,17 @@ import io.opentelemetry.api.trace.TraceState;
|
|||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleSummaryPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
@ -45,7 +46,7 @@ public class MetricAssertionsTest {
|
|||
/* name= */ "histogram",
|
||||
/* description= */ "description",
|
||||
/* unit= */ "unit",
|
||||
DoubleHistogramData.create(
|
||||
ImmutableHistogramData.create(
|
||||
AggregationTemporality.CUMULATIVE,
|
||||
// Points
|
||||
Collections.emptyList()));
|
||||
|
@ -57,7 +58,7 @@ public class MetricAssertionsTest {
|
|||
/* name= */ "histogram_delta",
|
||||
/* description= */ "description",
|
||||
/* unit= */ "unit",
|
||||
DoubleHistogramData.create(
|
||||
ImmutableHistogramData.create(
|
||||
AggregationTemporality.DELTA,
|
||||
// Points
|
||||
Collections.emptyList()));
|
||||
|
@ -212,8 +213,8 @@ public class MetricAssertionsTest {
|
|||
DoubleSummaryPointData.create(
|
||||
1, 2, Attributes.empty(), 1, 2, Collections.singletonList(PERCENTILE_VALUE));
|
||||
|
||||
private static final DoubleHistogramPointData DOUBLE_HISTOGRAM_POINT_DATA =
|
||||
DoubleHistogramPointData.create(
|
||||
private static final HistogramPointData DOUBLE_HISTOGRAM_POINT_DATA =
|
||||
ImmutableHistogramPointData.create(
|
||||
1, 2, Attributes.empty(), 15, Collections.singletonList(10.0), Arrays.asList(1L, 2L));
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.data;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* A histogram metric point.
|
||||
*
|
||||
* <p>See:
|
||||
* https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#histogram
|
||||
*
|
||||
* <p><i>Note: This is called "DoubleHistogram" to reflect which primitives are used to record it,
|
||||
* however "Histogram" is the equivalent OTLP type.</i>
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class DoubleHistogramData implements Data<DoubleHistogramPointData> {
|
||||
|
||||
static final DoubleHistogramData EMPTY =
|
||||
DoubleHistogramData.create(AggregationTemporality.CUMULATIVE, Collections.emptyList());
|
||||
|
||||
DoubleHistogramData() {}
|
||||
|
||||
public static DoubleHistogramData create(
|
||||
AggregationTemporality temporality, Collection<DoubleHistogramPointData> points) {
|
||||
return new AutoValue_DoubleHistogramData(temporality, points);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code AggregationTemporality} of this metric,
|
||||
*
|
||||
* <p>AggregationTemporality describes if the aggregator reports delta changes since last report
|
||||
* time, or cumulative changes since a fixed start time.
|
||||
*
|
||||
* @return the {@code AggregationTemporality} of this metric
|
||||
*/
|
||||
public abstract AggregationTemporality getAggregationTemporality();
|
||||
|
||||
@Override
|
||||
public abstract Collection<DoubleHistogramPointData> getPoints();
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.data;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A histogram metric recording.
|
||||
*
|
||||
* <p>See:
|
||||
* https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#histogram
|
||||
*/
|
||||
public interface HistogramData extends Data<HistogramPointData> {
|
||||
/**
|
||||
* Returns the {@code AggregationTemporality} of this metric,
|
||||
*
|
||||
* <p>AggregationTemporality describes if the aggregator reports delta changes since last report
|
||||
* time, or cumulative changes since a fixed start time.
|
||||
*
|
||||
* @return the {@code AggregationTemporality} of this metric
|
||||
*/
|
||||
AggregationTemporality getAggregationTemporality();
|
||||
|
||||
@Override
|
||||
Collection<HistogramPointData> getPoints();
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A histogram metric point.
|
||||
*
|
||||
* <p>See:
|
||||
* https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#histogram
|
||||
*/
|
||||
public interface HistogramPointData extends PointData {
|
||||
/**
|
||||
* The sum of all measurements recorded.
|
||||
*
|
||||
* @return the sum of recorded measurements.
|
||||
*/
|
||||
double getSum();
|
||||
|
||||
/**
|
||||
* The number of measurements taken.
|
||||
*
|
||||
* @return the count of recorded measurements.
|
||||
*/
|
||||
long getCount();
|
||||
|
||||
/**
|
||||
* The bucket boundaries. For a Histogram with N defined boundaries, e.g, [x, y, z]. There are N+1
|
||||
* counts: (-inf, x], (x, y], (y, z], (z, +inf).
|
||||
*
|
||||
* @return the read-only bucket boundaries in increasing order. <b>do not mutate</b> the returned
|
||||
* object.
|
||||
*/
|
||||
List<Double> getBoundaries();
|
||||
|
||||
/**
|
||||
* The counts in each bucket.
|
||||
*
|
||||
* @return the read-only counts in each bucket. <b>do not mutate</b> the returned object.
|
||||
*/
|
||||
List<Long> getCounts();
|
||||
|
||||
/**
|
||||
* Returns the lower bound of a bucket (all values would have been greater than).
|
||||
*
|
||||
* @param bucketIndex The bucket index, should match {@link #getCounts()} index.
|
||||
*/
|
||||
double getBucketLowerBound(int bucketIndex);
|
||||
|
||||
/**
|
||||
* Returns the upper inclusive bound of a bucket (all values would have been less then or equal).
|
||||
*
|
||||
* @param bucketIndex The bucket index, should match {@link #getCounts()} index.
|
||||
*/
|
||||
double getBucketUpperBound(int bucketIndex);
|
||||
}
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.sdk.metrics.data;
|
|||
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
@ -140,7 +141,7 @@ public interface MetricData {
|
|||
String name,
|
||||
String description,
|
||||
String unit,
|
||||
DoubleHistogramData data) {
|
||||
HistogramData data) {
|
||||
return MetricDataImpl.create(
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
|
@ -308,10 +309,10 @@ public interface MetricData {
|
|||
* @return the {@code DoubleHistogramData} if type is {@link MetricDataType#HISTOGRAM}, otherwise
|
||||
* a default empty data.
|
||||
*/
|
||||
default DoubleHistogramData getDoubleHistogramData() {
|
||||
default HistogramData getHistogramData() {
|
||||
if (getType() == MetricDataType.HISTOGRAM) {
|
||||
return (DoubleHistogramData) getData();
|
||||
return (HistogramData) getData();
|
||||
}
|
||||
return DoubleHistogramData.EMPTY;
|
||||
return ImmutableHistogramData.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ import io.opentelemetry.api.common.Attributes;
|
|||
import io.opentelemetry.api.internal.GuardedBy;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.ExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.exemplar.ExemplarReservoir;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.descriptor.MetricDescriptor;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.ArrayList;
|
||||
|
@ -104,7 +104,7 @@ public final class DoubleHistogramAggregator implements Aggregator<HistogramAccu
|
|||
metricDescriptor.getName(),
|
||||
metricDescriptor.getDescription(),
|
||||
metricDescriptor.getUnit(),
|
||||
DoubleHistogramData.create(
|
||||
ImmutableHistogramData.create(
|
||||
temporality,
|
||||
MetricDataUtils.toDoubleHistogramPointList(
|
||||
accumulationByLabels,
|
||||
|
|
|
@ -8,9 +8,10 @@ package io.opentelemetry.sdk.metrics.internal.aggregator;
|
|||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.sdk.internal.PrimitiveLongList;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.data.DoubleHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.DoublePointData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.data.LongPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.exponentialhistogram.ExponentialHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
|
||||
import java.util.ArrayList;
|
||||
|
@ -59,17 +60,17 @@ final class MetricDataUtils {
|
|||
return points;
|
||||
}
|
||||
|
||||
static List<DoubleHistogramPointData> toDoubleHistogramPointList(
|
||||
static List<HistogramPointData> toDoubleHistogramPointList(
|
||||
Map<Attributes, HistogramAccumulation> accumulationMap,
|
||||
long startEpochNanos,
|
||||
long epochNanos,
|
||||
List<Double> boundaries) {
|
||||
List<DoubleHistogramPointData> points = new ArrayList<>(accumulationMap.size());
|
||||
List<HistogramPointData> points = new ArrayList<>(accumulationMap.size());
|
||||
accumulationMap.forEach(
|
||||
(labels, aggregator) -> {
|
||||
List<Long> counts = PrimitiveLongList.wrap(aggregator.getCounts().clone());
|
||||
points.add(
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
startEpochNanos,
|
||||
epochNanos,
|
||||
labels,
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.internal.data;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* A histogram metric point.
|
||||
*
|
||||
* <p>See:
|
||||
* https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#histogram
|
||||
*
|
||||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
|
||||
* at any time.
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class ImmutableHistogramData implements HistogramData {
|
||||
|
||||
private static final ImmutableHistogramData EMPTY =
|
||||
ImmutableHistogramData.create(AggregationTemporality.CUMULATIVE, Collections.emptyList());
|
||||
|
||||
public static ImmutableHistogramData empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
ImmutableHistogramData() {}
|
||||
|
||||
public static ImmutableHistogramData create(
|
||||
AggregationTemporality temporality, Collection<HistogramPointData> points) {
|
||||
return new AutoValue_ImmutableHistogramData(temporality, points);
|
||||
}
|
||||
}
|
|
@ -3,32 +3,36 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.sdk.metrics.data;
|
||||
package io.opentelemetry.sdk.metrics.internal.data;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.sdk.internal.PrimitiveLongList;
|
||||
import io.opentelemetry.sdk.metrics.data.ExemplarData;
|
||||
import io.opentelemetry.sdk.metrics.data.HistogramPointData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* DoubleHistogramPointData represents an approximate representation of the distribution of
|
||||
* measurements.
|
||||
* An approximate representation of the distribution of measurements.
|
||||
*
|
||||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
|
||||
* at any time.
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class DoubleHistogramPointData implements PointData {
|
||||
public abstract class ImmutableHistogramPointData implements HistogramPointData {
|
||||
|
||||
/**
|
||||
* Creates a DoubleHistogramPointData. For a Histogram with N defined boundaries, there should be
|
||||
* N+1 counts.
|
||||
* Creates a HistogramPointData. For a Histogram with N defined boundaries, there should be N+1
|
||||
* counts.
|
||||
*
|
||||
* @return a DoubleHistogramPointData.
|
||||
* @return a HistogramPointData.
|
||||
* @throws IllegalArgumentException if the given boundaries/counts were invalid
|
||||
*/
|
||||
public static DoubleHistogramPointData create(
|
||||
public static ImmutableHistogramPointData create(
|
||||
long startEpochNanos,
|
||||
long epochNanos,
|
||||
Attributes attributes,
|
||||
|
@ -40,13 +44,13 @@ public abstract class DoubleHistogramPointData implements PointData {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a DoubleHistogramPointData. For a Histogram with N defined boundaries, there should be
|
||||
* N+1 counts.
|
||||
* Creates a HistogramPointData. For a Histogram with N defined boundaries, there should be N+1
|
||||
* counts.
|
||||
*
|
||||
* @return a DoubleHistogramPointData.
|
||||
* @return a HistogramPointData.
|
||||
* @throws IllegalArgumentException if the given boundaries/counts were invalid
|
||||
*/
|
||||
public static DoubleHistogramPointData create(
|
||||
public static ImmutableHistogramPointData create(
|
||||
long startEpochNanos,
|
||||
long epochNanos,
|
||||
Attributes attributes,
|
||||
|
@ -73,7 +77,7 @@ public abstract class DoubleHistogramPointData implements PointData {
|
|||
for (long c : PrimitiveLongList.toArray(counts)) {
|
||||
totalCount += c;
|
||||
}
|
||||
return new AutoValue_DoubleHistogramPointData(
|
||||
return new AutoValue_ImmutableHistogramPointData(
|
||||
startEpochNanos,
|
||||
epochNanos,
|
||||
attributes,
|
||||
|
@ -84,51 +88,14 @@ public abstract class DoubleHistogramPointData implements PointData {
|
|||
Collections.unmodifiableList(new ArrayList<>(counts)));
|
||||
}
|
||||
|
||||
DoubleHistogramPointData() {}
|
||||
ImmutableHistogramPointData() {}
|
||||
|
||||
/**
|
||||
* The sum of all measurements recorded.
|
||||
*
|
||||
* @return the sum of recorded measurements.
|
||||
*/
|
||||
public abstract double getSum();
|
||||
|
||||
/**
|
||||
* The number of measurements taken.
|
||||
*
|
||||
* @return the count of recorded measurements.
|
||||
*/
|
||||
public abstract long getCount();
|
||||
|
||||
/**
|
||||
* The bucket boundaries. For a Histogram with N defined boundaries, e.g, [x, y, z]. There are N+1
|
||||
* counts: (-inf, x], (x, y], (y, z], (z, +inf).
|
||||
*
|
||||
* @return the read-only bucket boundaries in increasing order. <b>do not mutate</b> the returned
|
||||
* object.
|
||||
*/
|
||||
public abstract List<Double> getBoundaries();
|
||||
|
||||
/**
|
||||
* The counts in each bucket.
|
||||
*
|
||||
* @return the read-only counts in each bucket. <b>do not mutate</b> the returned object.
|
||||
*/
|
||||
public abstract List<Long> getCounts();
|
||||
|
||||
/**
|
||||
* Returns the lower bound of a bucket (all values would have been greater than).
|
||||
*
|
||||
* @param bucketIndex The bucket index, should match {@link #getCounts()} index.
|
||||
*/
|
||||
@Override
|
||||
public double getBucketLowerBound(int bucketIndex) {
|
||||
return bucketIndex > 0 ? getBoundaries().get(bucketIndex - 1) : Double.NEGATIVE_INFINITY;
|
||||
}
|
||||
/**
|
||||
* Returns the upper inclusive bound of a bucket (all values would have been less then or equal).
|
||||
*
|
||||
* @param bucketIndex The bucket index, should match {@link #getCounts()} index.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public double getBucketUpperBound(int bucketIndex) {
|
||||
return (bucketIndex < getBoundaries().size())
|
||||
? getBoundaries().get(bucketIndex)
|
|
@ -13,6 +13,8 @@ import io.opentelemetry.api.common.AttributeKey;
|
|||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
|
||||
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Arrays;
|
||||
|
@ -46,8 +48,8 @@ class MetricDataImplTest {
|
|||
Arrays.asList(
|
||||
ValueAtPercentile.create(0.0, DOUBLE_VALUE),
|
||||
ValueAtPercentile.create(100, DOUBLE_VALUE)));
|
||||
private static final DoubleHistogramPointData HISTOGRAM_POINT =
|
||||
DoubleHistogramPointData.create(
|
||||
private static final ImmutableHistogramPointData HISTOGRAM_POINT =
|
||||
ImmutableHistogramPointData.create(
|
||||
START_EPOCH_NANOS,
|
||||
EPOCH_NANOS,
|
||||
Attributes.of(KEY, "value"),
|
||||
|
@ -178,18 +180,18 @@ class MetricDataImplTest {
|
|||
"metric_name",
|
||||
"metric_description",
|
||||
"ms",
|
||||
DoubleHistogramData.create(
|
||||
ImmutableHistogramData.create(
|
||||
AggregationTemporality.DELTA, Collections.singleton(HISTOGRAM_POINT)));
|
||||
assertThat(metricData.getDoubleHistogramData().getPoints()).containsExactly(HISTOGRAM_POINT);
|
||||
assertThat(metricData.getHistogramData().getPoints()).containsExactly(HISTOGRAM_POINT);
|
||||
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
0, 0, Attributes.empty(), 0.0, ImmutableList.of(), ImmutableList.of()))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
0,
|
||||
0,
|
||||
Attributes.empty(),
|
||||
|
@ -199,7 +201,7 @@ class MetricDataImplTest {
|
|||
.isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
DoubleHistogramPointData.create(
|
||||
ImmutableHistogramPointData.create(
|
||||
0,
|
||||
0,
|
||||
Attributes.empty(),
|
||||
|
@ -223,7 +225,7 @@ class MetricDataImplTest {
|
|||
assertThat(metricData.getLongGaugeData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getDoubleSumData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getLongGaugeData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getDoubleHistogramData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getHistogramData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getDoubleSummaryData().getPoints()).containsExactly(SUMMARY_POINT);
|
||||
|
||||
metricData =
|
||||
|
@ -238,7 +240,7 @@ class MetricDataImplTest {
|
|||
assertThat(metricData.getLongGaugeData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getDoubleSumData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getLongGaugeData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getDoubleHistogramData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getHistogramData().getPoints()).isEmpty();
|
||||
assertThat(metricData.getDoubleSummaryData().getPoints()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ class DoubleHistogramAggregatorTest {
|
|||
100);
|
||||
assertThat(metricData).isNotNull();
|
||||
assertThat(metricData.getType()).isEqualTo(MetricDataType.HISTOGRAM);
|
||||
assertThat(metricData.getDoubleHistogramData().getAggregationTemporality())
|
||||
assertThat(metricData.getHistogramData().getAggregationTemporality())
|
||||
.isEqualTo(AggregationTemporality.DELTA);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue