Skip to content

Commit a96600e

Browse files
authored
[exporters] Native Marshallers should always write SUM (#8107)
1 parent 2381201 commit a96600e

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramDataPointMarshaler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected void writeTo(Serializer output) throws IOException {
124124
output.serializeFixed64(ExponentialHistogramDataPoint.START_TIME_UNIX_NANO, startTimeUnixNano);
125125
output.serializeFixed64(ExponentialHistogramDataPoint.TIME_UNIX_NANO, timeUnixNano);
126126
output.serializeFixed64(ExponentialHistogramDataPoint.COUNT, count);
127-
output.serializeDouble(ExponentialHistogramDataPoint.SUM, sum);
127+
output.serializeDoubleOptional(ExponentialHistogramDataPoint.SUM, sum);
128128
if (hasMin) {
129129
output.serializeDoubleOptional(ExponentialHistogramDataPoint.MIN, min);
130130
}
@@ -161,7 +161,7 @@ private static int calculateSize(
161161
size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.TIME_UNIX_NANO, timeUnixNano);
162162
size += MarshalerUtil.sizeSInt32(ExponentialHistogramDataPoint.SCALE, scale);
163163
size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.COUNT, count);
164-
size += MarshalerUtil.sizeDouble(ExponentialHistogramDataPoint.SUM, sum);
164+
size += MarshalerUtil.sizeDoubleOptional(ExponentialHistogramDataPoint.SUM, sum);
165165
if (hasMin) {
166166
size += MarshalerUtil.sizeDoubleOptional(ExponentialHistogramDataPoint.MIN, min);
167167
}

exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExponentialHistogramDataPointStatelessMarshaler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void writeTo(
3131
ExponentialHistogramDataPoint.START_TIME_UNIX_NANO, point.getStartEpochNanos());
3232
output.serializeFixed64(ExponentialHistogramDataPoint.TIME_UNIX_NANO, point.getEpochNanos());
3333
output.serializeFixed64(ExponentialHistogramDataPoint.COUNT, point.getCount());
34-
output.serializeDouble(ExponentialHistogramDataPoint.SUM, point.getSum());
34+
output.serializeDoubleOptional(ExponentialHistogramDataPoint.SUM, point.getSum());
3535
if (point.hasMin()) {
3636
output.serializeDoubleOptional(ExponentialHistogramDataPoint.MIN, point.getMin());
3737
}
@@ -73,7 +73,7 @@ public int getBinarySerializedSize(
7373
MarshalerUtil.sizeFixed64(
7474
ExponentialHistogramDataPoint.TIME_UNIX_NANO, point.getEpochNanos());
7575
size += MarshalerUtil.sizeFixed64(ExponentialHistogramDataPoint.COUNT, point.getCount());
76-
size += MarshalerUtil.sizeDouble(ExponentialHistogramDataPoint.SUM, point.getSum());
76+
size += MarshalerUtil.sizeDoubleOptional(ExponentialHistogramDataPoint.SUM, point.getSum());
7777
if (point.hasMin()) {
7878
size += MarshalerUtil.sizeDoubleOptional(ExponentialHistogramDataPoint.MIN, point.getMin());
7979
}

exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/metrics/MetricsRequestMarshalerTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,42 @@ void exponentialHistogramDataPoints(MarshalerSource marshalerSource) {
531531
.build());
532532
}
533533

534+
@ParameterizedTest
535+
@EnumSource(MarshalerSource.class)
536+
void exponentialHistogramZeroSum(MarshalerSource marshalerSource) {
537+
assertThat(
538+
toExponentialHistogramDataPoints(
539+
marshalerSource,
540+
ImmutableList.of(
541+
ImmutableExponentialHistogramPointData.create(
542+
0,
543+
0,
544+
0,
545+
/* hasMin= */ false,
546+
0,
547+
/* hasMax= */ false,
548+
0,
549+
ImmutableExponentialHistogramBuckets.create(0, 0, Collections.emptyList()),
550+
ImmutableExponentialHistogramBuckets.create(0, 0, Collections.emptyList()),
551+
123,
552+
456,
553+
Attributes.empty(),
554+
Collections.emptyList()))))
555+
.containsExactly(
556+
ExponentialHistogramDataPoint.newBuilder()
557+
.setStartTimeUnixNano(123)
558+
.setTimeUnixNano(456)
559+
.setCount(0)
560+
.setScale(0)
561+
.setSum(0)
562+
.setZeroCount(0)
563+
.setPositive(
564+
ExponentialHistogramDataPoint.Buckets.newBuilder().setOffset(0)) // no buckets
565+
.setNegative(
566+
ExponentialHistogramDataPoint.Buckets.newBuilder().setOffset(0)) // no buckets
567+
.build());
568+
}
569+
534570
@SuppressWarnings("PointlessArithmeticExpression")
535571
@ParameterizedTest
536572
@EnumSource(MarshalerSource.class)

0 commit comments

Comments
 (0)