Skip to content

Commit f0fe58f

Browse files
committed
Move observation support classes to scheduling.support package
Avoids a package cycle between config and support (only config->support allowed). See gh-29883
1 parent 8fb412e commit f0fe58f

9 files changed

+43
-38
lines changed

Diff for: framework-docs/modules/ROOT/pages/integration/observability.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ This can be done by declaring a `SchedulingConfigurer` bean that sets the observ
9191

9292
include-code::./ObservationSchedulingConfigurer[]
9393

94-
It is using the `org.springframework.scheduling.config.DefaultScheduledTaskObservationConvention` by default, backed by the `ScheduledTaskObservationContext`.
94+
It is using the `org.springframework.scheduling.support.DefaultScheduledTaskObservationConvention` by default, backed by the `ScheduledTaskObservationContext`.
9595
You can configure a custom implementation on the `ObservationRegistry` directly.
9696
During the execution of the scheduled method, the current observation is restored in the `ThreadLocal` context or the Reactor context (if the scheduled method returns a `Mono` or `Flux` type).
9797

Diff for: spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
import org.springframework.core.ReactiveAdapter;
3939
import org.springframework.core.ReactiveAdapterRegistry;
4040
import org.springframework.lang.Nullable;
41-
import org.springframework.scheduling.config.DefaultScheduledTaskObservationConvention;
42-
import org.springframework.scheduling.config.ScheduledTaskObservationContext;
43-
import org.springframework.scheduling.config.ScheduledTaskObservationConvention;
41+
import org.springframework.scheduling.support.DefaultScheduledTaskObservationConvention;
42+
import org.springframework.scheduling.support.ScheduledTaskObservationContext;
43+
import org.springframework.scheduling.support.ScheduledTaskObservationConvention;
4444
import org.springframework.util.Assert;
4545
import org.springframework.util.ClassUtils;
4646
import org.springframework.util.ReflectionUtils;
4747
import org.springframework.util.StringUtils;
4848

49-
import static org.springframework.scheduling.config.ScheduledTaskObservationDocumentation.TASKS_SCHEDULED_EXECUTION;
49+
import static org.springframework.scheduling.support.ScheduledTaskObservationDocumentation.TASKS_SCHEDULED_EXECUTION;
5050

5151
/**
5252
* Helper class for @{@link ScheduledAnnotationBeanPostProcessor} to support reactive

Diff for: spring-context/src/main/java/org/springframework/scheduling/config/DefaultScheduledTaskObservationConvention.java renamed to spring-context/src/main/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConvention.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.scheduling.config;
17+
package org.springframework.scheduling.support;
1818

1919
import io.micrometer.common.KeyValue;
2020
import io.micrometer.common.KeyValues;
2121

2222
import org.springframework.util.StringUtils;
2323

24-
import static org.springframework.scheduling.config.ScheduledTaskObservationDocumentation.LowCardinalityKeyNames;
24+
import static org.springframework.scheduling.support.ScheduledTaskObservationDocumentation.LowCardinalityKeyNames;
2525

2626
/**
2727
* Default implementation for {@link ScheduledTaskObservationConvention}.

Diff for: spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
import io.micrometer.observation.Observation;
2525
import io.micrometer.observation.ObservationRegistry;
2626

27-
import org.springframework.scheduling.config.DefaultScheduledTaskObservationConvention;
28-
import org.springframework.scheduling.config.ScheduledTaskObservationContext;
29-
import org.springframework.scheduling.config.ScheduledTaskObservationConvention;
30-
import org.springframework.scheduling.config.ScheduledTaskObservationDocumentation;
3127
import org.springframework.util.ReflectionUtils;
3228

3329
/**
@@ -42,14 +38,16 @@
4238
*/
4339
public class ScheduledMethodRunnable implements Runnable {
4440

45-
private static final ScheduledTaskObservationConvention DEFAULT_CONVENTION = new DefaultScheduledTaskObservationConvention();
41+
private static final ScheduledTaskObservationConvention DEFAULT_CONVENTION =
42+
new DefaultScheduledTaskObservationConvention();
4643

4744
private final Object target;
4845

4946
private final Method method;
5047

5148
private final Supplier<ObservationRegistry> observationRegistrySupplier;
5249

50+
5351
/**
5452
* Create a {@code ScheduledMethodRunnable} for the given target instance,
5553
* calling the specified method.

Diff for: spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskObservationContext.java renamed to spring-context/src/main/java/org/springframework/scheduling/support/ScheduledTaskObservationContext.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.scheduling.config;
17+
package org.springframework.scheduling.support;
1818

1919
import java.lang.reflect.Method;
2020

@@ -23,8 +23,9 @@
2323
import org.springframework.util.ClassUtils;
2424

2525
/**
26-
* Context that holds information for observation metadata collection
27-
* during the {@link ScheduledTaskObservationDocumentation#TASKS_SCHEDULED_EXECUTION execution of scheduled tasks}.
26+
* Context that holds information for observation metadata collection during the
27+
* {@link ScheduledTaskObservationDocumentation#TASKS_SCHEDULED_EXECUTION execution of scheduled tasks}.
28+
*
2829
* @author Brian Clozel
2930
* @since 6.1
3031
*/
@@ -36,6 +37,7 @@ public class ScheduledTaskObservationContext extends Observation.Context {
3637

3738
private boolean complete;
3839

40+
3941
/**
4042
* Create a new observation context for a task, given the target object
4143
* and the method to be called.
@@ -47,6 +49,7 @@ public ScheduledTaskObservationContext(Object target, Method method) {
4749
this.method = method;
4850
}
4951

52+
5053
/**
5154
* Return the type of the target object.
5255
*/
@@ -77,4 +80,5 @@ public boolean isComplete() {
7780
public void setComplete(boolean complete) {
7881
this.complete = complete;
7982
}
83+
8084
}

Diff for: spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskObservationConvention.java renamed to spring-context/src/main/java/org/springframework/scheduling/support/ScheduledTaskObservationConvention.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.scheduling.config;
17+
package org.springframework.scheduling.support;
1818

1919
import io.micrometer.observation.Observation;
2020
import io.micrometer.observation.ObservationConvention;
2121

2222
/**
2323
* Interface for an {@link ObservationConvention} for
2424
* {@link ScheduledTaskObservationDocumentation#TASKS_SCHEDULED_EXECUTION scheduled task executions}.
25+
*
2526
* @author Brian Clozel
2627
* @since 6.1
2728
*/

Diff for: spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskObservationDocumentation.java renamed to spring-context/src/main/java/org/springframework/scheduling/support/ScheduledTaskObservationDocumentation.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.scheduling.config;
17+
package org.springframework.scheduling.support;
1818

1919
import io.micrometer.common.KeyValue;
2020
import io.micrometer.common.docs.KeyName;
@@ -24,8 +24,10 @@
2424

2525
/**
2626
* Documented {@link io.micrometer.common.KeyValue KeyValues} for the observations on
27-
* executions of {@link org.springframework.scheduling.annotation.Scheduled scheduled tasks}.
28-
* <p>This class is used by automated tools to document KeyValues attached to the {@code @Scheduled} observations.
27+
* executions of {@link org.springframework.scheduling.annotation.Scheduled scheduled tasks}
28+
*
29+
* <p>This class is used by automated tools to document KeyValues attached to the
30+
* {@code @Scheduled} observations.
2931
*
3032
* @author Brian Clozel
3133
* @since 6.1
@@ -40,19 +42,17 @@ public enum ScheduledTaskObservationDocumentation implements ObservationDocument
4042
public Class<? extends ObservationConvention<? extends Observation.Context>> getDefaultConvention() {
4143
return DefaultScheduledTaskObservationConvention.class;
4244
}
43-
4445
@Override
4546
public KeyName[] getLowCardinalityKeyNames() {
4647
return LowCardinalityKeyNames.values();
4748
}
48-
4949
@Override
5050
public KeyName[] getHighCardinalityKeyNames() {
5151
return new KeyName[] {};
5252
}
53-
5453
};
5554

55+
5656
public enum LowCardinalityKeyNames implements KeyName {
5757

5858
/**

Diff for: spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorObservabilityTests.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import org.springframework.core.task.SimpleAsyncTaskExecutor;
3737
import org.springframework.scheduling.config.ScheduledTask;
3838
import org.springframework.scheduling.config.ScheduledTaskHolder;
39-
import org.springframework.scheduling.config.ScheduledTaskObservationContext;
4039
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
40+
import org.springframework.scheduling.support.ScheduledTaskObservationContext;
4141

4242
import static org.assertj.core.api.Assertions.assertThat;
4343

@@ -55,11 +55,13 @@ class ScheduledAnnotationBeanPostProcessorObservabilityTests {
5555

5656
private final TestObservationRegistry observationRegistry = TestObservationRegistry.create();
5757

58+
5859
@AfterEach
5960
void closeContext() {
6061
context.close();
6162
}
6263

64+
6365
@Test
6466
void shouldRecordSuccessObservationsForTasks() throws Exception {
6567
registerScheduledBean(FixedDelayBean.class);
@@ -185,6 +187,7 @@ private TestObservationRegistryAssert.TestObservationRegistryAssertReturningObse
185187
.hasObservationWithNameEqualTo("tasks.scheduled.execution").that();
186188
}
187189

190+
188191
static abstract class TaskTester {
189192

190193
ObservationRegistry observationRegistry;
@@ -200,13 +203,13 @@ public void await() throws InterruptedException {
200203
}
201204
}
202205

206+
203207
static class FixedDelayBean extends TaskTester {
204208

205209
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
206210
public void fixedDelay() {
207211
this.latch.countDown();
208212
}
209-
210213
}
211214

212215

@@ -217,28 +220,28 @@ public void error() {
217220
this.latch.countDown();
218221
throw new IllegalStateException("test error");
219222
}
220-
221223
}
222224

225+
223226
static class FixedDelayReactiveBean extends TaskTester {
224227

225228
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
226229
public Mono<Object> fixedDelay() {
227230
return Mono.empty().doOnTerminate(() -> this.latch.countDown());
228231
}
229-
230232
}
231233

234+
232235
static class FixedDelayReactiveErrorBean extends TaskTester {
233236

234237
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
235238
public Mono<Object> error() {
236239
return Mono.error(new IllegalStateException("test error"))
237240
.doOnTerminate(() -> this.latch.countDown());
238241
}
239-
240242
}
241243

244+
242245
static class CancelledTaskBean extends TaskTester {
243246

244247
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
@@ -251,19 +254,19 @@ public void cancelled() {
251254
// ignore cancelled task
252255
}
253256
}
254-
255257
}
256258

259+
257260
static class CancelledReactiveTaskBean extends TaskTester {
258261

259262
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
260263
public Flux<Long> cancelled() {
261264
return Flux.interval(Duration.ZERO, Duration.ofSeconds(1))
262265
.doOnNext(el -> this.latch.countDown());
263266
}
264-
265267
}
266268

269+
267270
static class CurrentObservationBean extends TaskTester {
268271

269272
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
@@ -272,9 +275,9 @@ public void hasCurrentObservation() {
272275
assertThat(this.observationRegistry.getCurrentObservation().getContext()).isInstanceOf(ScheduledTaskObservationContext.class);
273276
this.latch.countDown();
274277
}
275-
276278
}
277279

280+
278281
static class CurrentObservationReactiveBean extends TaskTester {
279282

280283
@Scheduled(fixedDelay = 10_000, initialDelay = 5_000)
@@ -290,7 +293,6 @@ public void doFirst() throws Throwable {
290293
})
291294
.doOnTerminate(() -> this.latch.countDown());
292295
}
293-
294296
}
295297

296298
}

Diff for: spring-context/src/test/java/org/springframework/scheduling/config/DefaultScheduledTaskObservationConventionTests.java renamed to spring-context/src/test/java/org/springframework/scheduling/support/DefaultScheduledTaskObservationConventionTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.scheduling.config;
17+
package org.springframework.scheduling.support;
1818

1919

2020
import java.lang.reflect.Method;
@@ -37,6 +37,7 @@ class DefaultScheduledTaskObservationConventionTests {
3737

3838
private final ScheduledTaskObservationConvention convention = new DefaultScheduledTaskObservationConvention();
3939

40+
4041
@Test
4142
void observationShouldHaveDefaultName() {
4243
assertThat(convention.getName()).isEqualTo("tasks.scheduled.execution");
@@ -92,17 +93,16 @@ void observationShouldHaveUnknownOutcome() {
9293
}
9394

9495

95-
static class BeanWithScheduledMethods implements TaskProcessor {
96-
97-
public void process() {
96+
interface TaskProcessor {
9897

99-
}
98+
void process();
10099
}
101100

102-
interface TaskProcessor {
103101

104-
void process();
102+
static class BeanWithScheduledMethods implements TaskProcessor {
105103

104+
public void process() {
105+
}
106106
}
107107

108108
}

0 commit comments

Comments
 (0)