Skip to content

Commit

Permalink
Remove boxed primitives from aggregations (#5184)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Feb 12, 2023
1 parent 8f5ddf2 commit 7bb2f0d
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,20 @@ void histogramDataPoints() {
456,
KV_ATTR,
14.2,
null,
null,
/* hasMin= */ false,
0,
/* hasMax= */ false,
0,
ImmutableList.of(1.0),
ImmutableList.of(1L, 5L)),
ImmutableHistogramPointData.create(
123,
456,
Attributes.empty(),
15.3,
/* hasMin= */ true,
3.3,
/* hasMax= */ true,
12.0,
ImmutableList.of(),
ImmutableList.of(7L),
Expand Down Expand Up @@ -420,8 +424,10 @@ void exponentialHistogramDataPoints() {
0,
123.4,
1,
null,
null,
/* hasMin= */ false,
0,
/* hasMax= */ false,
0,
ImmutableExponentialHistogramBuckets.create(0, 0, Collections.emptyList()),
ImmutableExponentialHistogramBuckets.create(0, 0, Collections.emptyList()),
123,
Expand All @@ -432,7 +438,9 @@ void exponentialHistogramDataPoints() {
0,
123.4,
1,
/* hasMin= */ true,
3.3,
/* hasMax= */ true,
80.1,
ImmutableExponentialHistogramBuckets.create(
0, 1, ImmutableList.of(1L, 0L, 2L)),
Expand Down Expand Up @@ -787,7 +795,9 @@ void toProtoMetric_histogram() {
456,
KV_ATTR,
4.0,
/* hasMin= */ true,
1.0,
/* hasMax= */ true,
3.0,
ImmutableList.of(),
ImmutableList.of(33L)))))))
Expand Down Expand Up @@ -836,7 +846,9 @@ void toProtoMetric_exponentialHistogram() {
20,
123.4,
257,
/* hasMin= */ true,
20.1,
/* hasMax= */ true,
44.3,
ImmutableExponentialHistogramBuckets.create(
20, -1, ImmutableList.of(0L, 128L, 1L << 32)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ class SerializerTest {
1633950672000000000L,
Attributes.empty(),
1.0,
null,
null,
/* hasMin= */ false,
0,
/* hasMax= */ false,
0,
Collections.emptyList(),
Collections.singletonList(2L),
Collections.emptyList()))));
Expand All @@ -245,8 +247,10 @@ class SerializerTest {
1633950672000000000L,
Attributes.empty(),
1.0,
null,
null,
/* hasMin= */ false,
0,
/* hasMax= */ false,
0,
Collections.emptyList(),
Collections.singletonList(2L),
Collections.singletonList(
Expand Down Expand Up @@ -277,8 +281,10 @@ class SerializerTest {
1633950672000000000L,
Attributes.of(TYPE, "hs"),
1.0,
null,
null,
/* hasMin= */ false,
0,
/* hasMax= */ false,
0,
Collections.emptyList(),
Collections.singletonList(2L),
Collections.singletonList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ static Collection<HistogramPointData> convertHistogramPoints(Metric censusMetric
endTimestamp,
attributes,
distribution.getSum(),
null,
null,
/* hasMin= */ false,
0,
/* hasMax= */ false,
0,
mapBoundaries(distribution.getBucketOptions()),
mapCounts(distribution.getBuckets()),
mapExemplars(distribution.getBuckets())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ protected synchronized ExponentialHistogramPointData doAggregateThenMaybeReset(
scale,
sum,
zeroCount,
this.count > 0 ? this.min : null,
this.count > 0 ? this.max : null,
this.count > 0,
this.min,
this.count > 0,
this.max,
resolveBuckets(this.positiveBuckets, scale, reset),
resolveBuckets(this.negativeBuckets, scale, reset),
startEpochNanos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ protected HistogramPointData doAggregateThenMaybeReset(
epochNanos,
attributes,
sum,
this.count > 0 ? this.min : null,
this.count > 0 ? this.max : null,
this.count > 0,
this.min,
this.count > 0,
this.max,
boundaryList,
PrimitiveLongList.wrap(Arrays.copyOf(counts, counts.length)),
exemplars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets;
import io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
Expand All @@ -37,8 +36,10 @@ public static ExponentialHistogramPointData create(
int scale,
double sum,
long zeroCount,
@Nullable Double min,
@Nullable Double max,
boolean hasMin,
double min,
boolean hasMax,
double max,
ExponentialHistogramBuckets positiveBuckets,
ExponentialHistogramBuckets negativeBuckets,
long startEpochNanos,
Expand All @@ -56,10 +57,10 @@ public static ExponentialHistogramPointData create(
sum,
count,
zeroCount,
min != null,
min != null ? min : -1,
max != null,
max != null ? max : -1,
hasMin,
min,
hasMax,
max,
positiveBuckets,
negativeBuckets,
exemplars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
Expand All @@ -33,21 +32,26 @@ public abstract class ImmutableHistogramPointData implements HistogramPointData
* @return a HistogramPointData.
* @throws IllegalArgumentException if the given boundaries/counts were invalid
*/
@SuppressWarnings("TooManyParameters")
public static ImmutableHistogramPointData create(
long startEpochNanos,
long epochNanos,
Attributes attributes,
double sum,
@Nullable Double min,
@Nullable Double max,
boolean hasMin,
double min,
boolean hasMax,
double max,
List<Double> boundaries,
List<Long> counts) {
return create(
startEpochNanos,
epochNanos,
attributes,
sum,
hasMin,
min,
hasMax,
max,
boundaries,
counts,
Expand All @@ -61,13 +65,16 @@ public static ImmutableHistogramPointData create(
* @return a HistogramPointData.
* @throws IllegalArgumentException if the given boundaries/counts were invalid
*/
@SuppressWarnings("TooManyParameters")
public static ImmutableHistogramPointData create(
long startEpochNanos,
long epochNanos,
Attributes attributes,
double sum,
@Nullable Double min,
@Nullable Double max,
boolean hasMin,
double min,
boolean hasMax,
double max,
List<Double> boundaries,
List<Long> counts,
List<DoubleExemplarData> exemplars) {
Expand Down Expand Up @@ -96,10 +103,10 @@ public static ImmutableHistogramPointData create(
attributes,
sum,
totalCount,
min != null,
min != null ? min : -1,
max != null,
max != null ? max : -1,
hasMin,
min,
hasMax,
max,
Collections.unmodifiableList(new ArrayList<>(boundaries)),
Collections.unmodifiableList(new ArrayList<>(counts)),
exemplars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class ImmutableMetricDataTest {
EPOCH_NANOS,
Attributes.of(KEY, "value"),
DOUBLE_VALUE,
/* hasMin= */ true,
DOUBLE_VALUE_MIN,
/* hasMax= */ true,
DOUBLE_VALUE_MAX,
ImmutableList.of(1.0),
ImmutableList.of(1L, 1L));
Expand Down Expand Up @@ -203,7 +205,9 @@ void metricData_HistogramPoints() {
0,
Attributes.empty(),
0.0,
/* hasMin= */ false,
0.0,
/* hasMax= */ false,
0.0,
ImmutableList.of(),
ImmutableList.of()))
Expand All @@ -215,7 +219,9 @@ void metricData_HistogramPoints() {
0,
Attributes.empty(),
0.0,
/* hasMin= */ false,
0.0,
/* hasMax= */ false,
0.0,
ImmutableList.of(1.0, 1.0),
ImmutableList.of(0L, 0L, 0L)))
Expand All @@ -227,7 +233,9 @@ void metricData_HistogramPoints() {
0,
Attributes.empty(),
0.0,
/* hasMin= */ false,
0.0,
/* hasMax= */ false,
0.0,
ImmutableList.of(Double.NEGATIVE_INFINITY),
ImmutableList.of(0L, 0L)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ void testRecordings() {
1,
Attributes.empty(),
2175,
/* hasMin= */ true,
5d,
/* hasMax= */ true,
2000d,
boundariesList,
Arrays.asList(1L, 1L, 1L, 1L)));
Expand Down Expand Up @@ -110,7 +112,9 @@ void aggregateThenMaybeReset_WithExemplars() {
1,
Attributes.empty(),
0,
/* hasMin= */ true,
0.0,
/* hasMax= */ true,
0.0,
boundariesList,
Arrays.asList(1L, 0L, 0L, 0L),
Expand All @@ -131,7 +135,9 @@ void aggregateThenMaybeReset() {
1,
Attributes.empty(),
100,
/* hasMin= */ true,
100d,
/* hasMax= */ true,
100d,
boundariesList,
Arrays.asList(0L, 1L, 0L, 0L)));
Expand All @@ -145,7 +151,9 @@ void aggregateThenMaybeReset() {
1,
Attributes.empty(),
0,
/* hasMin= */ true,
0d,
/* hasMax= */ true,
0d,
boundariesList,
Arrays.asList(1L, 0L, 0L, 0L)));
Expand Down Expand Up @@ -191,7 +199,9 @@ void toMetricDataWithExemplars() {
1,
Attributes.empty(),
2,
/* hasMin= */ true,
2d,
/* hasMax= */ true,
2d,
boundariesList,
Arrays.asList(1L, 0L, 0L, 0L),
Expand Down Expand Up @@ -261,7 +271,9 @@ void testMultithreadedUpdates() throws InterruptedException {
1,
Attributes.empty(),
1010000,
/* hasMin= */ true,
1d,
/* hasMax= */ true,
23d,
boundariesList,
Arrays.asList(50000L, 50000L, 0L, 0L)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ class MetricAssertionsTest {
2,
Attributes.empty(),
15,
/* hasMin= */ true,
4.0,
/* hasMax= */ true,
7.0,
Collections.singletonList(10.0),
Arrays.asList(1L, 2L));
Expand Down Expand Up @@ -241,7 +243,9 @@ class MetricAssertionsTest {
1,
10.0,
1,
/* hasMin= */ true,
2.0,
/* hasMax= */ true,
4.0,
ImmutableExponentialHistogramBuckets.create(1, 10, Arrays.asList(1L, 2L)),
ImmutableExponentialHistogramBuckets.create(1, 0, Collections.emptyList()),
Expand Down

0 comments on commit 7bb2f0d

Please sign in to comment.