Skip to content

Commit

Permalink
Merge branch '1.14.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Feb 20, 2025
2 parents db40c13 + ebb9cf3 commit 2ad11b3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ spectator-atlas = "1.8.6"
spring5 = "5.3.39"
spring6 = "6.2.3"
spring-javaformat = "0.0.43"
testcontainers = "1.20.4"
testcontainers = "1.20.5"
tomcat = "8.5.100"
wavefront = "3.4.3"
wiremock = "2.35.2"
Expand Down
5 changes: 3 additions & 2 deletions implementations/micrometer-registry-stackdriver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ dependencies {
exclude group: 'com.google.guava', module: 'listenablefuture'
}
api libs.googleOauth2Http
implementation 'org.slf4j:slf4j-api'
compileOnly 'ch.qos.logback:logback-classic'
implementation libs.slf4jApi
compileOnly libs.logback12
testRuntimeOnly libs.logback12
// needed for extending TimeWindowPercentileHistogram in StackdriverHistogramUtil
compileOnly libs.hdrhistogram

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,12 @@ Distribution distribution(HistogramSnapshot snapshot, boolean timeDomain) {
bucketBoundaries.add(0.0);
}

double mean = cumulativeCount == 0 ? 0.0 : timeDomain ? snapshot.mean(getBaseTimeUnit()) : snapshot.mean();

return Distribution.newBuilder()
// is the mean optional? better to not send as it is for a different time
// window than the histogram
.setMean(timeDomain ? snapshot.mean(getBaseTimeUnit()) : snapshot.mean())
.setMean(mean)
.setCount(cumulativeCount)
.setBucketOptions(Distribution.BucketOptions.newBuilder()
.setExplicitBuckets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
*/
class StackdriverMeterRegistryTest {

StackdriverMeterRegistry meterRegistry = new StackdriverMeterRegistry(new StackdriverConfig() {
MockClock clock = new MockClock();

StackdriverConfig config = new StackdriverConfig() {
@Override
public boolean enabled() {
return false;
Expand All @@ -50,7 +52,9 @@ public String projectId() {
public String get(String key) {
return null;
}
}, new MockClock());
};

StackdriverMeterRegistry meterRegistry = new StackdriverMeterRegistry(config, clock);

@Test
@Issue("#1325")
Expand Down Expand Up @@ -177,4 +181,20 @@ void distributionWithOneExplicitBucket() {
assertThat(distribution.getBucketCountsList()).containsExactly(1L, 1L);
}

@Test
@Issue("#5927")
void meanIsZeroWhenCountIsZero() {
StackdriverMeterRegistry.Batch batch = meterRegistry.new Batch();
// halfway through first step
clock.add(config.step().dividedBy(2));
// histogram time window will start here
DistributionSummary ds = DistributionSummary.builder("ds").serviceLevelObjectives(2).register(meterRegistry);
ds.record(3);
// 3/4 through the second step; after histogram rollover
clock.add(config.step().dividedBy(4).multipliedBy(5));
Distribution distribution = batch.distribution(ds.takeSnapshot(), false);
assertThat(distribution.getCount()).isZero();
assertThat(distribution.getMean()).isZero();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
Copyright 2025 VMware, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are by default assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>

</configuration>

0 comments on commit 2ad11b3

Please sign in to comment.