Skip to content

Commit 6ed8fd9

Browse files
committed
Merge branch '1.13.x' into 1.14.x
2 parents ba52ad9 + 489d437 commit 6ed8fd9

File tree

15 files changed

+188
-55
lines changed

15 files changed

+188
-55
lines changed

docs/modules/ROOT/pages/concepts/counters.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ Counter counter = Counter
5050

5151
The `micrometer-core` module contains a `@Counted` annotation that frameworks can use to add counting support to either specific types of methods such as those serving web request endpoints or, more generally, to all methods.
5252

53-
WARNING: Micrometer's Spring Boot configuration does _not_ recognize `@Counted` on arbitrary methods.
54-
5553
Also, an incubating AspectJ aspect is included in `micrometer-core`. You can use it in your application either through compile/load time AspectJ weaving or through framework facilities that interpret AspectJ aspects and proxy targeted methods in some other way, such as Spring AOP. Here is a sample Spring AOP configuration:
5654

5755
[source,java]

docs/modules/ROOT/pages/concepts/timers.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ Note how we do not decide the timer to which to accumulate the sample until it i
7373

7474
The `micrometer-core` module contains a `@Timed` annotation that frameworks can use to add timing support to either specific types of methods such as those serving web request endpoints or, more generally, to all methods.
7575

76-
WARNING: Micrometer's Spring Boot configuration does _not_ recognize `@Timed` on arbitrary methods.
77-
7876
Also, an incubating AspectJ aspect is included in `micrometer-core`. You can use it in your application either through compile/load time AspectJ weaving or through framework facilities that interpret AspectJ aspects and proxy targeted methods in some other way, such as Spring AOP. Here is a sample Spring AOP configuration:
7977

8078
[source,java]

docs/src/test/java/io/micrometer/docs/metrics/TimedAspectTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TimedAspectTest {
4040
// end::resolvers[]
4141

4242
@ParameterizedTest
43-
@EnumSource(AnnotatedTestClass.class)
43+
@EnumSource
4444
void meterTagsWithText(AnnotatedTestClass annotatedClass) {
4545
MeterRegistry registry = new SimpleMeterRegistry();
4646
TimedAspect timedAspect = new TimedAspect(registry);
@@ -63,7 +63,7 @@ void meterTagsWithText(AnnotatedTestClass annotatedClass) {
6363
}
6464

6565
@ParameterizedTest
66-
@EnumSource(AnnotatedTestClass.class)
66+
@EnumSource
6767
void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
6868
MeterRegistry registry = new SimpleMeterRegistry();
6969
TimedAspect timedAspect = new TimedAspect(registry);
@@ -88,7 +88,7 @@ void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
8888
}
8989

9090
@ParameterizedTest
91-
@EnumSource(AnnotatedTestClass.class)
91+
@EnumSource
9292
void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
9393
MeterRegistry registry = new SimpleMeterRegistry();
9494
TimedAspect timedAspect = new TimedAspect(registry);

implementations/micrometer-registry-statsd/src/test/java/io/micrometer/statsd/StatsdMeterRegistryPublishTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void cleanUp() {
8080
}
8181

8282
@ParameterizedTest
83-
@EnumSource(StatsdProtocol.class)
83+
@EnumSource
8484
void receiveAllBufferedMetricsAfterCloseSuccessfully(StatsdProtocol protocol) throws InterruptedException {
8585
skipUdsTestOnWindows(protocol);
8686
serverLatch = new CountDownLatch(3);
@@ -98,7 +98,7 @@ void receiveAllBufferedMetricsAfterCloseSuccessfully(StatsdProtocol protocol) th
9898
}
9999

100100
@ParameterizedTest
101-
@EnumSource(StatsdProtocol.class)
101+
@EnumSource
102102
void receiveMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
103103
skipUdsTestOnWindows(protocol);
104104
serverLatch = new CountDownLatch(3);
@@ -116,7 +116,7 @@ void receiveMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedExcep
116116
}
117117

118118
@ParameterizedTest
119-
@EnumSource(StatsdProtocol.class)
119+
@EnumSource
120120
void resumeSendingMetrics_whenServerIntermittentlyFails(StatsdProtocol protocol) throws InterruptedException {
121121
skipUdsTestOnWindows(protocol);
122122
serverLatch = new CountDownLatch(1);
@@ -163,7 +163,7 @@ void resumeSendingMetrics_whenServerIntermittentlyFails(StatsdProtocol protocol)
163163
}
164164

165165
@ParameterizedTest
166-
@EnumSource(StatsdProtocol.class)
166+
@EnumSource
167167
@Issue("#1676")
168168
void stopAndStartMeterRegistrySendsMetrics(StatsdProtocol protocol) throws InterruptedException {
169169
skipUdsTestOnWindows(protocol);
@@ -206,7 +206,7 @@ void stopAndStartMeterRegistryWithLineSink() throws InterruptedException {
206206
}
207207

208208
@ParameterizedTest
209-
@EnumSource(StatsdProtocol.class)
209+
@EnumSource
210210
void whenBackendInitiallyDown_metricsSentAfterBackendStarts(StatsdProtocol protocol) throws InterruptedException {
211211
skipUdsTestOnWindows(protocol);
212212
AtomicInteger writeCount = new AtomicInteger();
@@ -245,7 +245,7 @@ void whenBackendInitiallyDown_metricsSentAfterBackendStarts(StatsdProtocol proto
245245
}
246246

247247
@ParameterizedTest
248-
@EnumSource(StatsdProtocol.class)
248+
@EnumSource
249249
void whenRegistryStopped_doNotConnectToBackend(StatsdProtocol protocol) throws InterruptedException {
250250
skipUdsTestOnWindows(protocol);
251251
serverLatch = new CountDownLatch(3);
@@ -264,7 +264,7 @@ void whenRegistryStopped_doNotConnectToBackend(StatsdProtocol protocol) throws I
264264
}
265265

266266
@ParameterizedTest
267-
@EnumSource(StatsdProtocol.class)
267+
@EnumSource
268268
@Issue("#2177")
269269
void whenSendError_reconnectsAndWritesNewMetrics(StatsdProtocol protocol) throws InterruptedException {
270270
skipUdsTestOnWindows(protocol);
@@ -296,7 +296,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
296296

297297
@Issue("#2880")
298298
@ParameterizedTest
299-
@EnumSource(StatsdProtocol.class)
299+
@EnumSource
300300
void receiveParallelMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
301301
final int n = 10;
302302

implementations/micrometer-registry-statsd/src/test/java/io/micrometer/statsd/StatsdMeterRegistryTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public StatsdFlavor flavor() {
7979
}
8080

8181
@ParameterizedTest
82-
@EnumSource(StatsdFlavor.class)
82+
@EnumSource
8383
void counterLineProtocol(StatsdFlavor flavor) {
8484
String line = null;
8585
switch (flavor) {
@@ -112,7 +112,7 @@ void counterLineProtocol(StatsdFlavor flavor) {
112112
}
113113

114114
@ParameterizedTest
115-
@EnumSource(StatsdFlavor.class)
115+
@EnumSource
116116
void gaugeLineProtocol(StatsdFlavor flavor) {
117117
final AtomicInteger n = new AtomicInteger(2);
118118
final StatsdConfig config = configWithFlavor(flavor);
@@ -145,7 +145,7 @@ void gaugeLineProtocol(StatsdFlavor flavor) {
145145
}
146146

147147
@ParameterizedTest
148-
@EnumSource(StatsdFlavor.class)
148+
@EnumSource
149149
void timerLineProtocol(StatsdFlavor flavor) {
150150
String line = null;
151151
switch (flavor) {
@@ -178,7 +178,7 @@ void timerLineProtocol(StatsdFlavor flavor) {
178178
}
179179

180180
@ParameterizedTest
181-
@EnumSource(StatsdFlavor.class)
181+
@EnumSource
182182
void summaryLineProtocol(StatsdFlavor flavor) {
183183
String line = null;
184184
switch (flavor) {
@@ -211,7 +211,7 @@ void summaryLineProtocol(StatsdFlavor flavor) {
211211
}
212212

213213
@ParameterizedTest
214-
@EnumSource(StatsdFlavor.class)
214+
@EnumSource
215215
void longTaskTimerLineProtocol(StatsdFlavor flavor) {
216216
final StatsdConfig config = configWithFlavor(flavor);
217217
long stepMillis = config.step().toMillis();
@@ -286,7 +286,7 @@ void counterIncrementDoesNotCauseStackOverflow() {
286286
}
287287

288288
@ParameterizedTest
289-
@EnumSource(StatsdFlavor.class)
289+
@EnumSource
290290
@Issue("#370")
291291
void serviceLevelObjectivesOnlyNoPercentileHistogram(StatsdFlavor flavor) {
292292
StatsdConfig config = configWithFlavor(flavor);
@@ -390,7 +390,7 @@ void interactWithStoppedRegistry() {
390390
}
391391

392392
@ParameterizedTest
393-
@EnumSource(StatsdFlavor.class)
393+
@EnumSource
394394
@Issue("#600")
395395
void memoryPerformanceOfNamingConventionInHotLoops(StatsdFlavor flavor) {
396396
AtomicInteger namingConventionUses = new AtomicInteger();

micrometer-core/src/main/java/io/micrometer/core/aop/CountedAspect.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
* @author Jonatan Ivanov
7272
* @author Johnny Lim
7373
* @author Yanming Zhou
74+
* @author Jeonggi Kim
7475
* @since 1.2.0
7576
* @see Counted
7677
*/
@@ -237,8 +238,17 @@ private Object perform(ProceedingJoinPoint pjp, Counted counted) throws Throwabl
237238

238239
if (stopWhenCompleted) {
239240
try {
240-
return ((CompletionStage<?>) pjp.proceed())
241-
.whenComplete((result, throwable) -> recordCompletionResult(pjp, counted, throwable));
241+
Object result = pjp.proceed();
242+
if (result == null) {
243+
if (!counted.recordFailuresOnly()) {
244+
record(pjp, counted, DEFAULT_EXCEPTION_TAG_VALUE, RESULT_TAG_SUCCESS_VALUE);
245+
}
246+
return result;
247+
}
248+
else {
249+
CompletionStage<?> stage = ((CompletionStage<?>) result);
250+
return stage.whenComplete((res, throwable) -> recordCompletionResult(pjp, counted, throwable));
251+
}
242252
}
243253
catch (Throwable e) {
244254
record(pjp, counted, e.getClass().getSimpleName(), RESULT_TAG_FAILURE_VALUE);

micrometer-core/src/main/java/io/micrometer/core/aop/TimedAspect.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
* @author Nejc Korasa
8383
* @author Jonatan Ivanov
8484
* @author Yanming Zhou
85+
* @author Jeonggi Kim
8586
* @since 1.0.0
8687
*/
8788
@Aspect
@@ -235,8 +236,16 @@ private Object processWithTimer(ProceedingJoinPoint pjp, Timed timed, String met
235236

236237
if (stopWhenCompleted) {
237238
try {
238-
return ((CompletionStage<?>) pjp.proceed()).whenComplete(
239-
(result, throwable) -> record(pjp, timed, metricName, sample, getExceptionTag(throwable)));
239+
Object result = pjp.proceed();
240+
if (result == null) {
241+
record(pjp, timed, metricName, sample, DEFAULT_EXCEPTION_TAG_VALUE);
242+
return result;
243+
}
244+
else {
245+
CompletionStage<?> stage = ((CompletionStage<?>) result);
246+
return stage.whenComplete(
247+
(res, throwable) -> record(pjp, timed, metricName, sample, getExceptionTag(throwable)));
248+
}
240249
}
241250
catch (Throwable e) {
242251
record(pjp, timed, metricName, sample, e.getClass().getSimpleName());
@@ -307,8 +316,15 @@ private Object processWithLongTaskTimer(ProceedingJoinPoint pjp, Timed timed, St
307316

308317
if (stopWhenCompleted) {
309318
try {
310-
return ((CompletionStage<?>) pjp.proceed())
311-
.whenComplete((result, throwable) -> sample.ifPresent(this::stopTimer));
319+
Object result = pjp.proceed();
320+
if (result == null) {
321+
sample.ifPresent(this::stopTimer);
322+
return result;
323+
}
324+
else {
325+
CompletionStage<?> stage = ((CompletionStage<?>) result);
326+
return stage.whenComplete((res, throwable) -> sample.ifPresent(this::stopTimer));
327+
}
312328
}
313329
catch (Throwable e) {
314330
sample.ifPresent(this::stopTimer);

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/cache/CaffeineStatsCounterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void loadFailure() {
9494
}
9595

9696
@ParameterizedTest
97-
@EnumSource(RemovalCause.class)
97+
@EnumSource
9898
void evictionWithCause(RemovalCause cause) {
9999
stats.recordEviction(3, cause);
100100
DistributionSummary summary = fetch("cache.evictions", "cause", cause.name()).summary();

micrometer-observation/src/main/java/io/micrometer/observation/aop/ObservedAspect.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
*
7171
* @author Jonatan Ivanov
7272
* @author Yanming Zhou
73+
* @author Jeonggi Kim
7374
* @since 1.10.0
7475
*/
7576
@Aspect
@@ -148,8 +149,15 @@ private Object observe(ProceedingJoinPoint pjp, Method method, Observed observed
148149
observation.start();
149150
Observation.Scope scope = observation.openScope();
150151
try {
151-
return ((CompletionStage<?>) pjp.proceed())
152-
.whenComplete((result, error) -> stopObservation(observation, scope, error));
152+
Object result = pjp.proceed();
153+
if (result == null) {
154+
stopObservation(observation, scope, null);
155+
return result;
156+
}
157+
else {
158+
CompletionStage<?> stage = (CompletionStage<?>) result;
159+
return stage.whenComplete((res, error) -> stopObservation(observation, scope, error));
160+
}
153161
}
154162
catch (Throwable error) {
155163
stopObservation(observation, scope, error);

micrometer-test/src/main/java/io/micrometer/core/instrument/HttpClientTimingInstrumentationVerificationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected String substitutePathVariables(String templatedPath, String... pathVar
144144
}
145145

146146
@ParameterizedTest
147-
@EnumSource(TestType.class)
147+
@EnumSource
148148
void getTemplatedPathForUri(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
149149
checkAndSetupTestForTestType(testType);
150150

@@ -162,7 +162,7 @@ void getTemplatedPathForUri(TestType testType, WireMockRuntimeInfo wmRuntimeInfo
162162
}
163163

164164
@ParameterizedTest
165-
@EnumSource(TestType.class)
165+
@EnumSource
166166
@Disabled("apache/jetty http client instrumentation currently fails this test")
167167
void timedWhenServerIsMissing(TestType testType) throws IOException {
168168
checkAndSetupTestForTestType(testType);
@@ -186,7 +186,7 @@ void timedWhenServerIsMissing(TestType testType) throws IOException {
186186
}
187187

188188
@ParameterizedTest
189-
@EnumSource(TestType.class)
189+
@EnumSource
190190
void serverException(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
191191
checkAndSetupTestForTestType(testType);
192192

@@ -203,7 +203,7 @@ void serverException(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
203203
}
204204

205205
@ParameterizedTest
206-
@EnumSource(TestType.class)
206+
@EnumSource
207207
void clientException(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
208208
checkAndSetupTestForTestType(testType);
209209

@@ -223,7 +223,7 @@ void clientException(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
223223
// TODO this test doesn't need to be parameterized but the custom resolver for
224224
// Before/After methods doesn't like when it isn't.
225225
@ParameterizedTest
226-
@EnumSource(TestType.class)
226+
@EnumSource
227227
void headerIsPropagatedFromContext(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
228228
checkAndSetupTestForTestType(testType);
229229

0 commit comments

Comments
 (0)