Skip to content

Commit

Permalink
Stop ignoring long measurements in HistogramExemplarReservoir (#5216)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Feb 15, 2023
1 parent f183114 commit 5d2855b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class HistogramExemplarReservoir extends FixedSizeExemplarReservoir<DoubleExempl
ReservoirCell::getAndResetDouble);
}

@Override
public void offerLongMeasurement(long value, Attributes attributes, Context context) {
super.offerDoubleMeasurement((double) value, attributes, context);
}

static class HistogramCellSelector implements ReservoirCellSelector {

private final double[] boundaries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

class HistogramExemplarReservoirTest {
@Test
public void noMeasurement_returnsEmpty() {
void noMeasurement_returnsEmpty() {
TestClock clock = TestClock.create();
ExemplarReservoir<DoubleExemplarData> reservoir =
new HistogramExemplarReservoir(clock, Collections.emptyList());
assertThat(reservoir.collectAndReset(Attributes.empty())).isEmpty();
}

@Test
public void oneBucket_samplesEverything() {
void oneBucket_samplesEverything() {
TestClock clock = TestClock.create();
ExemplarReservoir<DoubleExemplarData> reservoir =
new HistogramExemplarReservoir(clock, Collections.emptyList());
Expand Down Expand Up @@ -66,7 +66,7 @@ public void oneBucket_samplesEverything() {
}

@Test
public void multipleBuckets_samplesIntoCorrectBucket() {
void multipleBuckets_samplesIntoCorrectBucket() {
TestClock clock = TestClock.create();
AttributeKey<Long> bucketKey = AttributeKey.longKey("bucket");
ExemplarReservoir<DoubleExemplarData> reservoir =
Expand Down Expand Up @@ -95,4 +95,31 @@ public void multipleBuckets_samplesIntoCorrectBucket() {
assertThat(e.getFilteredAttributes()).isEqualTo(Attributes.of(bucketKey, 3L));
});
}

@Test
void longMeasurement_CastsToDouble() {
TestClock clock = TestClock.create();
ExemplarReservoir<DoubleExemplarData> reservoir =
new HistogramExemplarReservoir(clock, Collections.emptyList());
reservoir.offerLongMeasurement(1L, Attributes.empty(), Context.root());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(1)
.satisfiesExactly(
exemplar -> {
assertThat(exemplar.getEpochNanos()).isEqualTo(clock.now());
assertThat(exemplar.getValue()).isEqualTo(1);
assertThat(exemplar.getFilteredAttributes()).isEmpty();
});
// Measurement count is reset, we should sample a new measurement (and only one)
clock.advance(Duration.ofSeconds(1));
reservoir.offerLongMeasurement(2, Attributes.empty(), Context.root());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(1)
.satisfiesExactly(
exemplar -> {
assertThat(exemplar.getEpochNanos()).isEqualTo(clock.now());
assertThat(exemplar.getValue()).isEqualTo(2);
assertThat(exemplar.getFilteredAttributes()).isEmpty();
});
}
}

0 comments on commit 5d2855b

Please sign in to comment.