Skip to content

Commit 2b4c456

Browse files
committed
Merge branch '1.15.x'
2 parents e8eb3b8 + ef95c11 commit 2b4c456

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ subprojects {
9494
"CollectionUndefinedEquality",
9595
"DefaultCharset",
9696
"DoNotCallSuggester",
97+
"EnumOrdinal",
9798
"EqualsGetClass",
99+
"FallThrough",
98100
"InlineFormatString",
99101
"LongDoubleConversion",
100102
"MissingOverride",

implementations/micrometer-registry-prometheus/src/test/java/io/micrometer/prometheusmetrics/PrometheusMeterRegistryIntegrationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ private void recordMetrics() {
151151
TimeGauge.builder("test.tg", () -> 42, MILLISECONDS).register(registry);
152152

153153
List<Measurement> measurements = new ArrayList<>();
154-
for (int i = 0; i < Statistic.values().length; i++) {
155-
final int value = i;
156-
measurements.add(new Measurement(() -> value + 10, Statistic.values()[i]));
154+
int i = 0;
155+
for (Statistic statistic : Statistic.values()) {
156+
int value = i++;
157+
measurements.add(new Measurement(() -> value + 10, statistic));
157158
}
158159
Meter.builder("test.custom", Meter.Type.OTHER, measurements).register(registry);
159160
}

implementations/micrometer-registry-stackdriver/src/main/java/io/micrometer/stackdriver/StackdriverHistogramUtil.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static Histogram stackdriverHistogram(Clock clock, DistributionStatisticConfig d
3131
if (distributionStatisticConfig.isPublishingHistogram()) {
3232
return new StackdriverFixedBoundaryHistogram(clock, distributionStatisticConfig);
3333
}
34-
return NoopHistogram.INSTANCE;
34+
return new StackdriverInfinityBucketHistogram(clock, distributionStatisticConfig);
3535
}
3636

3737
static class StackdriverClientSidePercentilesHistogram extends TimeWindowPercentileHistogram {
@@ -51,4 +51,12 @@ static class StackdriverFixedBoundaryHistogram extends TimeWindowFixedBoundaryHi
5151

5252
}
5353

54+
static class StackdriverInfinityBucketHistogram extends TimeWindowFixedBoundaryHistogram {
55+
56+
StackdriverInfinityBucketHistogram(Clock clock, DistributionStatisticConfig config) {
57+
super(clock, config, false, false, true);
58+
}
59+
60+
}
61+
5462
}

implementations/micrometer-registry-stackdriver/src/test/java/io/micrometer/stackdriver/StackdriverMeterRegistryTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.micrometer.core.instrument.DistributionSummary;
2121
import io.micrometer.core.instrument.MockClock;
2222
import io.micrometer.core.instrument.Timer;
23+
import io.micrometer.core.instrument.distribution.CountAtBucket;
2324
import io.micrometer.core.instrument.distribution.HistogramSnapshot;
2425
import org.jspecify.annotations.Nullable;
2526
import org.junit.jupiter.api.Test;
@@ -76,11 +77,12 @@ void distributionCountBucketsInfinityBucketIsNotNegative() {
7677
@Test
7778
@Issue("#2045")
7879
void batchDistributionWhenHistogramSnapshotIsEmpty() {
79-
// no SLOs, percentiles, or percentile histogram configured => no-op histogram
80+
// no SLOs, percentiles, or percentile histogram configured
81+
// => only infinity bucket histogram
8082
DistributionSummary ds = DistributionSummary.builder("ds").register(meterRegistry);
8183
StackdriverMeterRegistry.Batch batch = meterRegistry.new Batch();
8284
HistogramSnapshot histogramSnapshot = ds.takeSnapshot();
83-
assertThat(histogramSnapshot.histogramCounts()).isEmpty();
85+
assertThat(histogramSnapshot.histogramCounts()).containsExactly(new CountAtBucket(Double.POSITIVE_INFINITY, 0));
8486
assertThat(histogramSnapshot.percentileValues()).isEmpty();
8587
Distribution distribution = batch.distribution(histogramSnapshot, false);
8688
assertThat(distribution.getBucketOptions().getExplicitBuckets().getBoundsList()).containsExactly(0d);
@@ -196,4 +198,31 @@ void meanIsZeroWhenCountIsZero() {
196198
assertThat(distribution.getMean()).isZero();
197199
}
198200

201+
@Test
202+
@Issue("#6401")
203+
void distributionWithNoBucketsHasCountInHistogramTimeWindow() {
204+
StackdriverMeterRegistry.Batch batch = meterRegistry.new Batch();
205+
206+
// half-way through the first step, example: 30s
207+
clock.add(config.step().dividedBy(2));
208+
DistributionSummary ds = DistributionSummary.builder("ds").register(meterRegistry);
209+
ds.record(3);
210+
211+
// 1/4 through the second step, example: 1m15s
212+
clock.add(config.step().dividedBy(4).multipliedBy(3));
213+
// assert and make count rollover as would happen via scheduled rollover
214+
assertThat(ds.count()).isOne();
215+
ds.record(5);
216+
217+
// 3/4 through the second step, example: 1m45s
218+
clock.add(config.step().dividedBy(2));
219+
assertThat(ds.count()).isOne();
220+
ds.record(7);
221+
222+
Distribution distribution = batch.distribution(ds.takeSnapshot(), false);
223+
// still returns count for the previous step
224+
assertThat(ds.count()).isOne();
225+
assertThat(distribution.getCount()).isEqualTo(2);
226+
}
227+
199228
}

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jersey/server/MetricsRequestEventListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public void onEvent(RequestEvent event) {
7878
if (!isClientError(event)) {
7979
break;
8080
}
81+
// fall through
8182
case REQUEST_MATCHED:
8283
timedAnnotations = annotations(event);
8384

micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jersey/server/ObservationRequestEventListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void onEvent(RequestEvent event) {
7070
if (!isNotFoundException(event)) {
7171
break;
7272
}
73+
// fall through
7374
case REQUEST_MATCHED:
7475
JerseyContext jerseyContext = new JerseyContext(event);
7576
Observation observation = JerseyObservationDocumentation.DEFAULT.start(this.customConvention,

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/jetty/JettyClientMetricsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void handle(String target, org.eclipse.jetty.server.Request baseRequest,
6161
throw new RuntimeException("big boom");
6262
case "/error":
6363
response.setStatus(500);
64+
// fall through
6465
case "/ok":
6566
baseRequest.setHandled(true);
6667
}

0 commit comments

Comments
 (0)