diff --git a/framework-docs/modules/ROOT/pages/integration/observability.adoc b/framework-docs/modules/ROOT/pages/integration/observability.adoc index 05f85aabd752..39c9fdc77bb1 100644 --- a/framework-docs/modules/ROOT/pages/integration/observability.adoc +++ b/framework-docs/modules/ROOT/pages/integration/observability.adoc @@ -103,8 +103,8 @@ By default, the following `KeyValues` are created: |Name | Description |`code.function` _(required)_|Name of Java `Method` that is scheduled for execution. |`code.namespace` _(required)_|Canonical name of the class of the bean instance that holds the scheduled method. -|`exception` _(required)_|Name of the exception thrown during the execution, or `KeyValue#NONE_VALUE`} if no exception happened. -|`outcome` _(required)_|Outcome of the method execution. Can be `"SUCCESS"`, `"ERROR"` or `"UNKNOWN"` (if for example the operation was cancelled during execution. +|`exception` _(required)_|Name of the exception thrown during the execution, or `"none"` if no exception happened. +|`outcome` _(required)_|Outcome of the method execution. Can be `"SUCCESS"`, `"ERROR"` or `"UNKNOWN"` (if for example the operation was cancelled during execution). |=== @@ -135,7 +135,7 @@ By default, the following `KeyValues` are created: [cols="a,a"] |=== |Name | Description -|`exception` _(required)_|Name of the exception thrown during the exchange, or `KeyValue#NONE_VALUE`} if no exception happened. +|`exception` _(required)_|Name of the exception thrown during the exchange, or `"none"` if no exception happened. |`method` _(required)_|Name of HTTP request method or `"none"` if the request was not received properly. |`outcome` _(required)_|Outcome of the HTTP server exchange. |`status` _(required)_|HTTP response raw status code, or `"UNKNOWN"` if no response was created. diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConvention.java b/spring-context/src/main/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConvention.java index 837f00572455..46c0385757ff 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConvention.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConvention.java @@ -75,7 +75,7 @@ protected KeyValue outcome(ScheduledTaskObservationContext context) { if (context.getError() != null) { return OUTCOME_ERROR; } - else if (!context.isComplete()) { + if (!context.isComplete()) { return OUTCOME_UNKNOWN; } return OUTCOME_SUCCESS; diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorObservabilityTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorObservabilityTests.java index 681a2ff5a17b..8b16f4084e86 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorObservabilityTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorObservabilityTests.java @@ -36,7 +36,6 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.scheduling.config.ScheduledTask; import org.springframework.scheduling.config.ScheduledTaskHolder; -import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.scheduling.support.ScheduledTaskObservationContext; import static org.assertj.core.api.Assertions.assertThat; @@ -155,14 +154,7 @@ private void registerScheduledBean(Class beanClass) { targetDefinition.getPropertyValues().add("observationRegistry", this.observationRegistry); context.registerBeanDefinition("postProcessor", processorDefinition); context.registerBeanDefinition("target", targetDefinition); - context.registerBean("schedulingConfigurer", SchedulingConfigurer.class, () -> { - return new SchedulingConfigurer() { - @Override - public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { - taskRegistrar.setObservationRegistry(observationRegistry); - } - }; - }); + context.registerBean("schedulingConfigurer", SchedulingConfigurer.class, () -> taskRegistrar -> taskRegistrar.setObservationRegistry(observationRegistry)); context.refresh(); } @@ -198,7 +190,7 @@ public void setObservationRegistry(ObservationRegistry observationRegistry) { this.observationRegistry = observationRegistry; } - public void await() throws InterruptedException { + void await() throws InterruptedException { this.latch.await(3, TimeUnit.SECONDS); } } @@ -207,7 +199,7 @@ public void await() throws InterruptedException { static class FixedDelayBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public void fixedDelay() { + void fixedDelay() { this.latch.countDown(); } } @@ -216,7 +208,7 @@ public void fixedDelay() { static class FixedDelayErrorBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public void error() { + void error() { this.latch.countDown(); throw new IllegalStateException("test error"); } @@ -226,7 +218,7 @@ public void error() { static class FixedDelayReactiveBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public Mono fixedDelay() { + Mono fixedDelay() { return Mono.empty().doOnTerminate(() -> this.latch.countDown()); } } @@ -235,7 +227,7 @@ public Mono fixedDelay() { static class FixedDelayReactiveErrorBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public Mono error() { + Mono error() { return Mono.error(new IllegalStateException("test error")) .doOnTerminate(() -> this.latch.countDown()); } @@ -245,7 +237,7 @@ public Mono error() { static class CancelledTaskBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public void cancelled() { + void cancelled() { this.latch.countDown(); try { Thread.sleep(5000); @@ -260,7 +252,7 @@ public void cancelled() { static class CancelledReactiveTaskBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public Flux cancelled() { + Flux cancelled() { return Flux.interval(Duration.ZERO, Duration.ofSeconds(1)) .doOnNext(el -> this.latch.countDown()); } @@ -270,9 +262,10 @@ public Flux cancelled() { static class CurrentObservationBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public void hasCurrentObservation() { - assertThat(this.observationRegistry.getCurrentObservation()).isNotNull(); - assertThat(this.observationRegistry.getCurrentObservation().getContext()).isInstanceOf(ScheduledTaskObservationContext.class); + void hasCurrentObservation() { + Observation observation = this.observationRegistry.getCurrentObservation(); + assertThat(observation).isNotNull(); + assertThat(observation.getContext()).isInstanceOf(ScheduledTaskObservationContext.class); this.latch.countDown(); } } @@ -281,7 +274,7 @@ public void hasCurrentObservation() { static class CurrentObservationReactiveBean extends TaskTester { @Scheduled(fixedDelay = 10_000, initialDelay = 5_000) - public Mono hasCurrentObservation() { + Mono hasCurrentObservation() { return Mono.just("test") .tap(() -> new DefaultSignalListener() { @Override diff --git a/spring-context/src/test/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConventionTests.java b/spring-context/src/test/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConventionTests.java index 91203377bb5b..6f00d0a495f3 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConventionTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConventionTests.java @@ -101,6 +101,7 @@ interface TaskProcessor { static class BeanWithScheduledMethods implements TaskProcessor { + @Override public void process() { } }