Skip to content

Commit 6d73a1c

Browse files
committed
ReApply "Adapt observability code to latest changes in Micrometer"
This reverts commit a774fac.
1 parent 58ce4fe commit 6d73a1c

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchJobContext.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
import org.springframework.batch.core.JobExecution;
2222

23+
import java.util.function.Supplier;
24+
2325
/**
2426
* Observation context for batch jobs.
2527
*
2628
* @author Marcin Grzejszczak
2729
* @since 5.0
2830
*/
29-
public class BatchJobContext extends Observation.Context {
31+
public class BatchJobContext extends Observation.Context implements Supplier<BatchJobContext> {
3032

3133
private final JobExecution jobExecution;
3234

@@ -38,4 +40,9 @@ public JobExecution getJobExecution() {
3840
return jobExecution;
3941
}
4042

43+
@Override
44+
public BatchJobContext get() {
45+
return this;
46+
}
47+
4148
}

spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchJobObservation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.batch.core.observability;
1818

1919
import io.micrometer.common.docs.KeyName;
20-
import io.micrometer.observation.docs.DocumentedObservation;
20+
import io.micrometer.observation.docs.ObservationDocumentation;
2121

2222
/**
2323
* Observation created around a Job execution.
@@ -26,7 +26,7 @@
2626
* @author Mahmoud Ben Hassine
2727
* @since 5.0
2828
*/
29-
public enum BatchJobObservation implements DocumentedObservation {
29+
public enum BatchJobObservation implements ObservationDocumentation {
3030

3131
BATCH_JOB_OBSERVATION {
3232
@Override

spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,27 @@ public static Timer createTimer(String name, String description, Tag... tags) {
9090
* {@code Metrics.globalRegistry.withTimerObservationHandler()} in the user code.
9191
* Otherwise you won't observe any metrics.
9292
* @param name of the observation
93-
* @param context of the observation
93+
* @param context of the batch job observation
9494
* @return a new observation instance
9595
* @since 5.0
9696
*/
97-
public static Observation createObservation(String name, Observation.Context context) {
97+
public static Observation createObservation(String name, BatchJobContext context) {
98+
return Observation.createNotStarted(name, context, observationRegistry);
99+
}
100+
101+
/**
102+
* Create a new {@link Observation}. It's not started, you must explicitly call
103+
* {@link Observation#start()} to start it.
104+
*
105+
* Remember to register the {@link DefaultMeterObservationHandler} via the
106+
* {@code Metrics.globalRegistry.withTimerObservationHandler()} in the user code.
107+
* Otherwise you won't observe any metrics.
108+
* @param name of the observation
109+
* @param context of the observation step context
110+
* @return a new observation instance
111+
* @since 5.0
112+
*/
113+
public static Observation createObservation(String name, BatchStepContext context) {
98114
return Observation.createNotStarted(name, context, observationRegistry);
99115
}
100116

spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchStepContext.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
import org.springframework.batch.core.StepExecution;
2222

23+
import java.util.function.Supplier;
24+
2325
/**
2426
* Observation context for batch steps.
2527
*
2628
* @author Marcin Grzejszczak
2729
* @since 5.0
2830
*/
29-
public class BatchStepContext extends Observation.Context {
31+
public class BatchStepContext extends Observation.Context implements Supplier<BatchStepContext> {
3032

3133
private final StepExecution stepExecution;
3234

@@ -38,4 +40,9 @@ public StepExecution getStepExecution() {
3840
return stepExecution;
3941
}
4042

43+
@Override
44+
public BatchStepContext get() {
45+
return this;
46+
}
47+
4148
}

spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchStepObservation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.batch.core.observability;
1818

1919
import io.micrometer.common.docs.KeyName;
20-
import io.micrometer.observation.docs.DocumentedObservation;
20+
import io.micrometer.observation.docs.ObservationDocumentation;
2121

2222
/**
2323
* Observation created around a step execution.
@@ -26,7 +26,7 @@
2626
* @author Mahmoud Ben Hassine
2727
* @since 5.0
2828
*/
29-
public enum BatchStepObservation implements DocumentedObservation {
29+
public enum BatchStepObservation implements ObservationDocumentation {
3030

3131
BATCH_STEP_OBSERVATION {
3232
@Override

0 commit comments

Comments
 (0)