Skip to content

Commit 9caaa69

Browse files
MikeGoldsmithclaude
andcommitted
Add tests for recordMinMax=false behavior
Verifies min/max not tracked when disabled. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent e8ac7c7 commit 9caaa69

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleBase2ExponentialHistogramAggregatorTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,4 +574,27 @@ public void reusablePoint_emptyFirstThenRecordAndCheck() {
574574
assertThat(point.getPositiveBuckets().getBucketCounts()).isNotEmpty();
575575
assertThat(point.getNegativeBuckets().getBucketCounts()).isNotEmpty();
576576
}
577+
578+
@ParameterizedTest
579+
@EnumSource(MemoryMode.class)
580+
void testRecordMinMaxDisabled(MemoryMode memoryMode) {
581+
DoubleBase2ExponentialHistogramAggregator aggregator =
582+
new DoubleBase2ExponentialHistogramAggregator(
583+
ExemplarReservoirFactory.noSamples(), 160, 20, /* recordMinMax= */ false, memoryMode);
584+
AggregatorHandle<ExponentialHistogramPointData> aggregatorHandle = aggregator.createHandle();
585+
aggregatorHandle.recordDouble(0.5, Attributes.empty(), Context.current());
586+
aggregatorHandle.recordDouble(1.0, Attributes.empty(), Context.current());
587+
aggregatorHandle.recordDouble(12.0, Attributes.empty(), Context.current());
588+
aggregatorHandle.recordDouble(15.213, Attributes.empty(), Context.current());
589+
aggregatorHandle.recordDouble(-13.2, Attributes.empty(), Context.current());
590+
aggregatorHandle.recordDouble(-2.01, Attributes.empty(), Context.current());
591+
592+
ExponentialHistogramPointData point =
593+
aggregatorHandle.aggregateThenMaybeReset(0, 1, Attributes.empty(), /* reset= */ true);
594+
assertThat(point).isNotNull();
595+
assertThat(point.hasMin()).isFalse();
596+
assertThat(point.hasMax()).isFalse();
597+
assertThat(point.getSum()).isCloseTo(13.503, Offset.offset(0.0001));
598+
assertThat(point.getCount()).isEqualTo(6);
599+
}
577600
}

sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/internal/aggregator/DoubleExplicitBucketHistogramAggregatorTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,27 @@ void testReusableDataMemoryMode() {
287287
// The point data instance should be reused
288288
assertThat(anotherPointData).isSameAs(pointData);
289289
}
290+
291+
@ParameterizedTest
292+
@EnumSource(MemoryMode.class)
293+
void testRecordMinMaxDisabled(MemoryMode memoryMode) {
294+
DoubleExplicitBucketHistogramAggregator aggregator =
295+
new DoubleExplicitBucketHistogramAggregator(
296+
boundaries,
297+
/* recordMinMax= */ false,
298+
ExemplarReservoirFactory.noSamples(),
299+
memoryMode);
300+
AggregatorHandle<HistogramPointData> aggregatorHandle = aggregator.createHandle();
301+
aggregatorHandle.recordLong(20, Attributes.empty(), Context.current());
302+
aggregatorHandle.recordLong(5, Attributes.empty(), Context.current());
303+
aggregatorHandle.recordLong(150, Attributes.empty(), Context.current());
304+
aggregatorHandle.recordLong(2000, Attributes.empty(), Context.current());
305+
HistogramPointData point =
306+
aggregatorHandle.aggregateThenMaybeReset(0, 1, Attributes.empty(), /* reset= */ true);
307+
assertThat(point.getSum()).isEqualTo(2175);
308+
assertThat(point.hasMin()).isFalse();
309+
assertThat(point.hasMax()).isFalse();
310+
assertThat(point.getBoundaries()).isEqualTo(boundariesList);
311+
assertThat(point.getCounts()).isEqualTo(Arrays.asList(1L, 1L, 1L, 1L));
312+
}
290313
}

0 commit comments

Comments
 (0)