Skip to content

Commit 2ad11b3

Browse files
committed
Merge branch '1.14.x'
2 parents db40c13 + ebb9cf3 commit 2ad11b3

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

gradle/libs.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ spectator-atlas = "1.8.6"
7575
spring5 = "5.3.39"
7676
spring6 = "6.2.3"
7777
spring-javaformat = "0.0.43"
78-
testcontainers = "1.20.4"
78+
testcontainers = "1.20.5"
7979
tomcat = "8.5.100"
8080
wavefront = "3.4.3"
8181
wiremock = "2.35.2"

implementations/micrometer-registry-stackdriver/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ dependencies {
88
exclude group: 'com.google.guava', module: 'listenablefuture'
99
}
1010
api libs.googleOauth2Http
11-
implementation 'org.slf4j:slf4j-api'
12-
compileOnly 'ch.qos.logback:logback-classic'
11+
implementation libs.slf4jApi
12+
compileOnly libs.logback12
13+
testRuntimeOnly libs.logback12
1314
// needed for extending TimeWindowPercentileHistogram in StackdriverHistogramUtil
1415
compileOnly libs.hdrhistogram
1516

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,12 @@ Distribution distribution(HistogramSnapshot snapshot, boolean timeDomain) {
557557
bucketBoundaries.add(0.0);
558558
}
559559

560+
double mean = cumulativeCount == 0 ? 0.0 : timeDomain ? snapshot.mean(getBaseTimeUnit()) : snapshot.mean();
561+
560562
return Distribution.newBuilder()
561563
// is the mean optional? better to not send as it is for a different time
562564
// window than the histogram
563-
.setMean(timeDomain ? snapshot.mean(getBaseTimeUnit()) : snapshot.mean())
565+
.setMean(mean)
564566
.setCount(cumulativeCount)
565567
.setBucketOptions(Distribution.BucketOptions.newBuilder()
566568
.setExplicitBuckets(

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
*/
3535
class StackdriverMeterRegistryTest {
3636

37-
StackdriverMeterRegistry meterRegistry = new StackdriverMeterRegistry(new StackdriverConfig() {
37+
MockClock clock = new MockClock();
38+
39+
StackdriverConfig config = new StackdriverConfig() {
3840
@Override
3941
public boolean enabled() {
4042
return false;
@@ -50,7 +52,9 @@ public String projectId() {
5052
public String get(String key) {
5153
return null;
5254
}
53-
}, new MockClock());
55+
};
56+
57+
StackdriverMeterRegistry meterRegistry = new StackdriverMeterRegistry(config, clock);
5458

5559
@Test
5660
@Issue("#1325")
@@ -177,4 +181,20 @@ void distributionWithOneExplicitBucket() {
177181
assertThat(distribution.getBucketCountsList()).containsExactly(1L, 1L);
178182
}
179183

184+
@Test
185+
@Issue("#5927")
186+
void meanIsZeroWhenCountIsZero() {
187+
StackdriverMeterRegistry.Batch batch = meterRegistry.new Batch();
188+
// halfway through first step
189+
clock.add(config.step().dividedBy(2));
190+
// histogram time window will start here
191+
DistributionSummary ds = DistributionSummary.builder("ds").serviceLevelObjectives(2).register(meterRegistry);
192+
ds.record(3);
193+
// 3/4 through the second step; after histogram rollover
194+
clock.add(config.step().dividedBy(4).multipliedBy(5));
195+
Distribution distribution = batch.distribution(ds.takeSnapshot(), false);
196+
assertThat(distribution.getCount()).isZero();
197+
assertThat(distribution.getMean()).isZero();
198+
}
199+
180200
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
3+
Copyright 2025 VMware, Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
-->
18+
<configuration>
19+
20+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
21+
<!-- encoders are by default assigned the type
22+
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
23+
<encoder>
24+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
25+
</encoder>
26+
</appender>
27+
28+
<root level="info">
29+
<appender-ref ref="STDOUT" />
30+
</root>
31+
32+
</configuration>

0 commit comments

Comments
 (0)