Skip to content

Commit bdf89b8

Browse files
committed
Merge branch '1.13.x' into 1.14.x
2 parents 0310222 + 1ab3e85 commit bdf89b8

File tree

4 files changed

+195
-3
lines changed

4 files changed

+195
-3
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ jobs:
100100
name: Deployment
101101
command: sh ./gradle/deploy.sh
102102

103+
stackdriver-it:
104+
executor: circle-jdk-executor
105+
steps:
106+
- run:
107+
name: Setup Google Cloud auth
108+
command: |
109+
echo "$GCLOUD_SERVICE_KEY" >> "$HOME"/gcloud-service-key.json
110+
echo 'export GOOGLE_APPLICATION_CREDENTIALS="$HOME"/gcloud-service-key.json' >> "$BASH_ENV"
111+
- gradlew-build:
112+
command: stackdriverTest
113+
103114
workflows:
104115
version: 2
105116
build_prs_deploy_snapshots:
@@ -109,6 +120,14 @@ workflows:
109120
- build-jdk17
110121
- concurrency-tests
111122
- docker-tests
123+
- stackdriver-it:
124+
context:
125+
- gcp-metrics-writer
126+
filters:
127+
branches:
128+
only:
129+
- main
130+
- /\d+\.\d+\.x/
112131
- deploy:
113132
context:
114133
- deploy
@@ -118,6 +137,7 @@ workflows:
118137
- build-jdk17
119138
- concurrency-tests
120139
- docker-tests
140+
- stackdriver-it
121141
filters:
122142
branches:
123143
only:
@@ -155,6 +175,14 @@ workflows:
155175
ignore: /.*/
156176
tags:
157177
only: /^v\d+\.\d+\.\d+(-(RC|M)\d+)?$/
178+
- stackdriver-it:
179+
context:
180+
- gcp-metrics-writer
181+
filters:
182+
branches:
183+
ignore: /.*/
184+
tags:
185+
only: /^v\d+\.\d+\.\d+(-(RC|M)\d+)?$/
158186
- deploy:
159187
context:
160188
- deploy

implementations/micrometer-registry-stackdriver/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ dependencies {
1616

1717
testImplementation project(':micrometer-test')
1818
}
19+
20+
test {
21+
useJUnitPlatform {
22+
excludeTags 'gcp-it'
23+
}
24+
}
25+
26+
task stackdriverTest(type: Test) {
27+
useJUnitPlatform {
28+
includeTags 'gcp-it'
29+
}
30+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.google.monitoring.v3.*;
2626
import com.google.protobuf.Timestamp;
2727
import io.micrometer.common.lang.Nullable;
28+
import io.micrometer.common.util.internal.logging.InternalLogger;
29+
import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
2830
import io.micrometer.core.instrument.Timer;
2931
import io.micrometer.core.instrument.*;
3032
import io.micrometer.core.instrument.distribution.CountAtBucket;
@@ -35,8 +37,6 @@
3537
import io.micrometer.core.instrument.step.StepMeterRegistry;
3638
import io.micrometer.core.instrument.util.DoubleFormat;
3739
import io.micrometer.core.instrument.util.NamedThreadFactory;
38-
import org.slf4j.Logger;
39-
import org.slf4j.LoggerFactory;
4040

4141
import java.util.*;
4242
import java.util.concurrent.Callable;
@@ -69,7 +69,7 @@ public class StackdriverMeterRegistry extends StepMeterRegistry {
6969
*/
7070
private static final int TIMESERIES_PER_REQUEST_LIMIT = 200;
7171

72-
private final Logger logger = LoggerFactory.getLogger(StackdriverMeterRegistry.class);
72+
private final InternalLogger logger = InternalLoggerFactory.getInstance(StackdriverMeterRegistry.class);
7373

7474
private final StackdriverConfig config;
7575

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright 2025 VMware, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micrometer.stackdriver;
17+
18+
import io.micrometer.common.util.internal.logging.InternalLogLevel;
19+
import io.micrometer.common.util.internal.logging.MockLogger;
20+
import io.micrometer.common.util.internal.logging.MockLoggerFactory;
21+
import io.micrometer.core.instrument.Clock;
22+
import io.micrometer.core.instrument.DistributionSummary;
23+
import io.micrometer.core.instrument.Timer;
24+
import org.junit.jupiter.api.Tag;
25+
import org.junit.jupiter.api.Test;
26+
27+
import java.time.Duration;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
/**
32+
* When running this integration test locally, authentication can be done by configuring
33+
* the env var GOOGLE_APPLICATION_CREDENTIALS with the location of the service key JSON
34+
* file.
35+
*/
36+
@Tag("gcp-it")
37+
class StackdriverIntegrationTest {
38+
39+
static final MockLoggerFactory LOGGER_FACTORY = new MockLoggerFactory();
40+
41+
MockLogger mockLogger = LOGGER_FACTORY.getLogger(StackdriverMeterRegistry.class);
42+
43+
static final StackdriverConfig CONFIG = new StackdriverConfig() {
44+
@Override
45+
public String projectId() {
46+
return "micrometer-gcp";
47+
}
48+
49+
@Override
50+
public String get(String key) {
51+
return null;
52+
}
53+
};
54+
55+
StackdriverMeterRegistry registry = LOGGER_FACTORY
56+
.injectLogger(() -> new StackdriverMeterRegistry(CONFIG, Clock.SYSTEM));
57+
58+
StackdriverMeterRegistry.Batch batch = registry.new Batch();
59+
60+
void publishAndVerify() {
61+
registry.close();
62+
assertThat(mockLogger.getLogEvents()
63+
.stream()
64+
.filter(log -> log.getLevel() == InternalLogLevel.WARN || log.getLevel() == InternalLogLevel.ERROR))
65+
.as("There should be no WARN or ERROR logs if metrics publish to Stackdriver successfully")
66+
.isEmpty();
67+
}
68+
69+
@Test
70+
void timerWithSlos() {
71+
Timer slos = Timer.builder("micrometer.stackdriver.it.timer.slo")
72+
.maximumExpectedValue(Duration.ofMillis(2))
73+
.serviceLevelObjectives(Duration.ofMillis(1), Duration.ofMillis(2))
74+
.register(registry);
75+
slos.record(Duration.ofMillis(1));
76+
slos.record(Duration.ofMillis(2));
77+
slos.record(Duration.ofMillis(3));
78+
79+
System.out.println(slos.getId().toString() + batch.distribution(slos.takeSnapshot(), true));
80+
publishAndVerify();
81+
}
82+
83+
@Test
84+
void timerWithPercentileHistogram() {
85+
Timer percentileHistogram = Timer.builder("micrometer.stackdriver.it.timer.percentilehistogram")
86+
.publishPercentileHistogram()
87+
.register(registry);
88+
89+
percentileHistogram.record(Duration.ofMillis(1));
90+
percentileHistogram.record(Duration.ofMillis(2));
91+
percentileHistogram.record(Duration.ofMillis(3));
92+
93+
System.out.println(
94+
percentileHistogram.getId().toString() + batch.distribution(percentileHistogram.takeSnapshot(), true));
95+
publishAndVerify();
96+
}
97+
98+
@Test
99+
void timerWithClientPercentiles() {
100+
Timer clientPercentiles = Timer.builder("micrometer.stackdriver.it.timer.clientpercentiles")
101+
.publishPercentiles(0.5, 0.99)
102+
.register(registry);
103+
clientPercentiles.record(Duration.ofMillis(1));
104+
clientPercentiles.record(Duration.ofMillis(2));
105+
clientPercentiles.record(Duration.ofMillis(3));
106+
107+
System.out
108+
.println(clientPercentiles.getId().toString() + batch.distribution(clientPercentiles.takeSnapshot(), true));
109+
publishAndVerify();
110+
}
111+
112+
@Test
113+
void timerWithClientPercentilesAndSlo() {
114+
Timer clientPercentilesAndSlos = Timer.builder("micrometer.stackdriver.it.timer.clientpercentilesandslo")
115+
.serviceLevelObjectives(Duration.ofMillis(2))
116+
.publishPercentiles(0.5, 0.99)
117+
.register(registry);
118+
clientPercentilesAndSlos.record(Duration.ofMillis(1));
119+
clientPercentilesAndSlos.record(Duration.ofMillis(2));
120+
clientPercentilesAndSlos.record(Duration.ofMillis(3));
121+
122+
System.out.println(clientPercentilesAndSlos.getId().toString()
123+
+ batch.distribution(clientPercentilesAndSlos.takeSnapshot(), true));
124+
publishAndVerify();
125+
}
126+
127+
@Test
128+
void summary() {
129+
DistributionSummary summary = DistributionSummary.builder("micrometer.stackdriver.it.summary")
130+
.register(registry);
131+
summary.record(10d);
132+
summary.record(20d);
133+
summary.record(30d);
134+
135+
System.out.println(summary.getId().toString() + batch.distribution(summary.takeSnapshot(), false));
136+
publishAndVerify();
137+
}
138+
139+
@Test
140+
void summaryWithOneSlo() {
141+
DistributionSummary oneSlo = DistributionSummary.builder("micrometer.stackdriver.it.summaryoneslo")
142+
.serviceLevelObjectives(20)
143+
.register(registry);
144+
oneSlo.record(10d);
145+
oneSlo.record(20d);
146+
oneSlo.record(30d);
147+
148+
System.out.println(oneSlo.getId().toString() + batch.distribution(oneSlo.takeSnapshot(), false));
149+
publishAndVerify();
150+
}
151+
152+
}

0 commit comments

Comments
 (0)