Skip to content

Commit

Permalink
Merge branch '1.13.x' into 1.14.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Dec 16, 2024
2 parents ba52ad9 + 489d437 commit 6ed8fd9
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 55 deletions.
2 changes: 0 additions & 2 deletions docs/modules/ROOT/pages/concepts/counters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ Counter counter = Counter

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.

WARNING: Micrometer's Spring Boot configuration does _not_ recognize `@Counted` on arbitrary methods.

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:

[source,java]
Expand Down
2 changes: 0 additions & 2 deletions docs/modules/ROOT/pages/concepts/timers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ Note how we do not decide the timer to which to accumulate the sample until it i

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.

WARNING: Micrometer's Spring Boot configuration does _not_ recognize `@Timed` on arbitrary methods.

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:

[source,java]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TimedAspectTest {
// end::resolvers[]

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithText(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
Expand All @@ -63,7 +63,7 @@ void meterTagsWithText(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
Expand All @@ -88,7 +88,7 @@ void meterTagsWithResolver(AnnotatedTestClass annotatedClass) {
}

@ParameterizedTest
@EnumSource(AnnotatedTestClass.class)
@EnumSource
void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void cleanUp() {
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void receiveAllBufferedMetricsAfterCloseSuccessfully(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(3);
Expand All @@ -98,7 +98,7 @@ void receiveAllBufferedMetricsAfterCloseSuccessfully(StatsdProtocol protocol) th
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void receiveMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(3);
Expand All @@ -116,7 +116,7 @@ void receiveMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedExcep
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void resumeSendingMetrics_whenServerIntermittentlyFails(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(1);
Expand Down Expand Up @@ -163,7 +163,7 @@ void resumeSendingMetrics_whenServerIntermittentlyFails(StatsdProtocol protocol)
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
@Issue("#1676")
void stopAndStartMeterRegistrySendsMetrics(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
Expand Down Expand Up @@ -206,7 +206,7 @@ void stopAndStartMeterRegistryWithLineSink() throws InterruptedException {
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void whenBackendInitiallyDown_metricsSentAfterBackendStarts(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
AtomicInteger writeCount = new AtomicInteger();
Expand Down Expand Up @@ -245,7 +245,7 @@ void whenBackendInitiallyDown_metricsSentAfterBackendStarts(StatsdProtocol proto
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void whenRegistryStopped_doNotConnectToBackend(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
serverLatch = new CountDownLatch(3);
Expand All @@ -264,7 +264,7 @@ void whenRegistryStopped_doNotConnectToBackend(StatsdProtocol protocol) throws I
}

@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
@Issue("#2177")
void whenSendError_reconnectsAndWritesNewMetrics(StatsdProtocol protocol) throws InterruptedException {
skipUdsTestOnWindows(protocol);
Expand Down Expand Up @@ -296,7 +296,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

@Issue("#2880")
@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@EnumSource
void receiveParallelMetricsSuccessfully(StatsdProtocol protocol) throws InterruptedException {
final int n = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public StatsdFlavor flavor() {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void counterLineProtocol(StatsdFlavor flavor) {
String line = null;
switch (flavor) {
Expand Down Expand Up @@ -112,7 +112,7 @@ void counterLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void gaugeLineProtocol(StatsdFlavor flavor) {
final AtomicInteger n = new AtomicInteger(2);
final StatsdConfig config = configWithFlavor(flavor);
Expand Down Expand Up @@ -145,7 +145,7 @@ void gaugeLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void timerLineProtocol(StatsdFlavor flavor) {
String line = null;
switch (flavor) {
Expand Down Expand Up @@ -178,7 +178,7 @@ void timerLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void summaryLineProtocol(StatsdFlavor flavor) {
String line = null;
switch (flavor) {
Expand Down Expand Up @@ -211,7 +211,7 @@ void summaryLineProtocol(StatsdFlavor flavor) {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
void longTaskTimerLineProtocol(StatsdFlavor flavor) {
final StatsdConfig config = configWithFlavor(flavor);
long stepMillis = config.step().toMillis();
Expand Down Expand Up @@ -286,7 +286,7 @@ void counterIncrementDoesNotCauseStackOverflow() {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
@Issue("#370")
void serviceLevelObjectivesOnlyNoPercentileHistogram(StatsdFlavor flavor) {
StatsdConfig config = configWithFlavor(flavor);
Expand Down Expand Up @@ -390,7 +390,7 @@ void interactWithStoppedRegistry() {
}

@ParameterizedTest
@EnumSource(StatsdFlavor.class)
@EnumSource
@Issue("#600")
void memoryPerformanceOfNamingConventionInHotLoops(StatsdFlavor flavor) {
AtomicInteger namingConventionUses = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* @author Jonatan Ivanov
* @author Johnny Lim
* @author Yanming Zhou
* @author Jeonggi Kim
* @since 1.2.0
* @see Counted
*/
Expand Down Expand Up @@ -237,8 +238,17 @@ private Object perform(ProceedingJoinPoint pjp, Counted counted) throws Throwabl

if (stopWhenCompleted) {
try {
return ((CompletionStage<?>) pjp.proceed())
.whenComplete((result, throwable) -> recordCompletionResult(pjp, counted, throwable));
Object result = pjp.proceed();
if (result == null) {
if (!counted.recordFailuresOnly()) {
record(pjp, counted, DEFAULT_EXCEPTION_TAG_VALUE, RESULT_TAG_SUCCESS_VALUE);
}
return result;
}
else {
CompletionStage<?> stage = ((CompletionStage<?>) result);
return stage.whenComplete((res, throwable) -> recordCompletionResult(pjp, counted, throwable));
}
}
catch (Throwable e) {
record(pjp, counted, e.getClass().getSimpleName(), RESULT_TAG_FAILURE_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
* @author Nejc Korasa
* @author Jonatan Ivanov
* @author Yanming Zhou
* @author Jeonggi Kim
* @since 1.0.0
*/
@Aspect
Expand Down Expand Up @@ -235,8 +236,16 @@ private Object processWithTimer(ProceedingJoinPoint pjp, Timed timed, String met

if (stopWhenCompleted) {
try {
return ((CompletionStage<?>) pjp.proceed()).whenComplete(
(result, throwable) -> record(pjp, timed, metricName, sample, getExceptionTag(throwable)));
Object result = pjp.proceed();
if (result == null) {
record(pjp, timed, metricName, sample, DEFAULT_EXCEPTION_TAG_VALUE);
return result;
}
else {
CompletionStage<?> stage = ((CompletionStage<?>) result);
return stage.whenComplete(
(res, throwable) -> record(pjp, timed, metricName, sample, getExceptionTag(throwable)));
}
}
catch (Throwable e) {
record(pjp, timed, metricName, sample, e.getClass().getSimpleName());
Expand Down Expand Up @@ -307,8 +316,15 @@ private Object processWithLongTaskTimer(ProceedingJoinPoint pjp, Timed timed, St

if (stopWhenCompleted) {
try {
return ((CompletionStage<?>) pjp.proceed())
.whenComplete((result, throwable) -> sample.ifPresent(this::stopTimer));
Object result = pjp.proceed();
if (result == null) {
sample.ifPresent(this::stopTimer);
return result;
}
else {
CompletionStage<?> stage = ((CompletionStage<?>) result);
return stage.whenComplete((res, throwable) -> sample.ifPresent(this::stopTimer));
}
}
catch (Throwable e) {
sample.ifPresent(this::stopTimer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void loadFailure() {
}

@ParameterizedTest
@EnumSource(RemovalCause.class)
@EnumSource
void evictionWithCause(RemovalCause cause) {
stats.recordEviction(3, cause);
DistributionSummary summary = fetch("cache.evictions", "cause", cause.name()).summary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
*
* @author Jonatan Ivanov
* @author Yanming Zhou
* @author Jeonggi Kim
* @since 1.10.0
*/
@Aspect
Expand Down Expand Up @@ -148,8 +149,15 @@ private Object observe(ProceedingJoinPoint pjp, Method method, Observed observed
observation.start();
Observation.Scope scope = observation.openScope();
try {
return ((CompletionStage<?>) pjp.proceed())
.whenComplete((result, error) -> stopObservation(observation, scope, error));
Object result = pjp.proceed();
if (result == null) {
stopObservation(observation, scope, null);
return result;
}
else {
CompletionStage<?> stage = (CompletionStage<?>) result;
return stage.whenComplete((res, error) -> stopObservation(observation, scope, error));
}
}
catch (Throwable error) {
stopObservation(observation, scope, error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected String substitutePathVariables(String templatedPath, String... pathVar
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void getTemplatedPathForUri(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
checkAndSetupTestForTestType(testType);

Expand All @@ -162,7 +162,7 @@ void getTemplatedPathForUri(TestType testType, WireMockRuntimeInfo wmRuntimeInfo
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
@Disabled("apache/jetty http client instrumentation currently fails this test")
void timedWhenServerIsMissing(TestType testType) throws IOException {
checkAndSetupTestForTestType(testType);
Expand All @@ -186,7 +186,7 @@ void timedWhenServerIsMissing(TestType testType) throws IOException {
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void serverException(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
checkAndSetupTestForTestType(testType);

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

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void clientException(TestType testType, WireMockRuntimeInfo wmRuntimeInfo) {
checkAndSetupTestForTestType(testType);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ void afterEach() throws Exception {
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void uriIsNotFound_whenRouteIsUnmapped(TestType testType) throws Throwable {
sender.get(baseUri + "notFound").send();
checkTimer(rs -> rs.tags("uri", "NOT_FOUND", "status", "404", "method", "GET").timer().count() == 1);
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void uriTemplateIsTagged(TestType testType) throws Throwable {
sender.get(baseUri + "hello/world").send();
checkTimer(rs -> rs.tags("uri", InstrumentedRoutes.TEMPLATED_ROUTE, "status", "200", "method", "GET")
Expand All @@ -136,7 +136,7 @@ void uriTemplateIsTagged(TestType testType) throws Throwable {
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void redirect(TestType testType) throws Throwable {
sender.get(baseUri + "foundRedirect").send();
checkTimer(rs -> rs.tags("uri", InstrumentedRoutes.REDIRECT, "status", "302", "method", "GET")
Expand All @@ -145,15 +145,15 @@ void redirect(TestType testType) throws Throwable {
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void errorResponse(TestType testType) throws Throwable {
sender.post(baseUri + "error").send();
checkTimer(
rs -> rs.tags("uri", InstrumentedRoutes.ERROR, "status", "500", "method", "POST").timer().count() == 1);
}

@ParameterizedTest
@EnumSource(TestType.class)
@EnumSource
void canExtractContextFromHeaders(TestType testType) throws Throwable {
sender.get(baseUri + "hello/micrometer").withHeader("Test-Propagation", "someValue").send();

Expand Down
Loading

0 comments on commit 6ed8fd9

Please sign in to comment.