Skip to content

Commit c7af7ec

Browse files
fmbenhassinelcmarvin
authored andcommitted
Refine contribution spring-projects#4065
* Fix tests * Update Javadocs * Update year in license headers * Move observability APIs to a separate package
1 parent 74c3b15 commit c7af7ec

File tree

22 files changed

+182
-132
lines changed

22 files changed

+182
-132
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
<spring-retry.version>1.3.1</spring-retry.version>
5656
<spring-integration.version>6.0.0-SNAPSHOT</spring-integration.version>
5757
<micrometer.version>2.0.0-SNAPSHOT</micrometer.version>
58-
<micrometer-tracing.version>1.0.0-SNAPSHOT</micrometer-tracing.version>
5958
<jackson.version>2.13.1</jackson.version>
6059

6160
<!-- optional production dependencies -->
@@ -80,6 +79,7 @@
8079
<junit-jupiter.version>5.8.2</junit-jupiter.version>
8180

8281
<!-- test dependencies -->
82+
<micrometer-tracing.version>1.0.0-SNAPSHOT</micrometer-tracing.version>
8383
<junit.version>4.13.2</junit.version>
8484
<hamcrest.version>2.2</hamcrest.version>
8585
<assertj.version>3.21.0</assertj.version>

spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,11 @@
4141
import org.springframework.batch.core.launch.NoSuchJobException;
4242
import org.springframework.batch.core.launch.support.ExitCodeMapper;
4343
import org.springframework.batch.core.listener.CompositeJobExecutionListener;
44-
import org.springframework.batch.core.metrics.BatchMetrics;
44+
import org.springframework.batch.core.observability.BatchMetrics;
45+
import org.springframework.batch.core.observability.BatchJobContext;
46+
import org.springframework.batch.core.observability.BatchJobObservation;
47+
import org.springframework.batch.core.observability.BatchJobTagsProvider;
48+
import org.springframework.batch.core.observability.DefaultBatchJobTagsProvider;
4549
import org.springframework.batch.core.repository.JobRepository;
4650
import org.springframework.batch.core.repository.JobRestartException;
4751
import org.springframework.batch.core.scope.context.JobSynchronizationManager;

spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.springframework.batch.core.JobParametersInvalidException;
2929
import org.springframework.batch.core.StepExecution;
3030
import org.springframework.batch.core.launch.JobLauncher;
31-
import org.springframework.batch.core.metrics.BatchMetrics;
31+
import org.springframework.batch.core.observability.BatchMetrics;
3232
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
3333
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
3434
import org.springframework.batch.core.repository.JobRepository;

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,12 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.batch.core.job;
17+
package org.springframework.batch.core.observability;
1818

1919
import io.micrometer.core.instrument.observation.Observation;
2020

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

23+
/**
24+
* Observation context for batch jobs.
25+
*
26+
* @author Marcin Grzejszczak
27+
* @since 5.0
28+
*/
2329
public class BatchJobContext extends Observation.Context {
2430

2531
private final JobExecution jobExecution;

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,16 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.batch.core.job;
17+
package org.springframework.batch.core.observability;
1818

1919
import io.micrometer.core.instrument.docs.DocumentedObservation;
2020
import io.micrometer.core.instrument.docs.TagKey;
2121

22-
enum BatchJobObservation implements DocumentedObservation {
22+
/**
23+
* Observation created around a Job execution.
24+
*
25+
* @author Marcin Grzejszczak
26+
* @author Mahmoud Ben Hassine
27+
* @since 5.0
28+
*/
29+
public enum BatchJobObservation implements DocumentedObservation {
2330

24-
/**
25-
* Observation created around a Job execution.
26-
*/
2731
BATCH_JOB_OBSERVATION {
2832
@Override
2933
public String getName() {
@@ -88,7 +92,7 @@ public String getKey() {
8892
},
8993

9094
/**
91-
* ID of the Spring Batch execution.
95+
* ID of the Spring Batch job execution.
9296
*/
9397
JOB_EXECUTION_ID {
9498
@Override
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
1-
/*
2-
* Copyright 2006-2009 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
package org.springframework.batch.core.job;
18-
19-
import io.micrometer.core.instrument.observation.Observation;
20-
21-
import org.springframework.batch.core.Job;
22-
import org.springframework.batch.core.JobExecution;
23-
import org.springframework.batch.core.JobInterruptedException;
24-
import org.springframework.batch.core.StartLimitExceededException;
25-
import org.springframework.batch.core.Step;
26-
import org.springframework.batch.core.StepExecution;
27-
import org.springframework.batch.core.repository.JobRestartException;
28-
29-
/**
30-
* {@link Observation.TagsProvider} for {@link BatchJobContext}.
31-
*
32-
* @author Marcin Grzejszczak
33-
*/
34-
public interface BatchJobTagsProvider extends Observation.TagsProvider<BatchJobContext> {
35-
36-
@Override
37-
default boolean supportsContext(Observation.Context context) {
38-
return context instanceof BatchJobContext;
39-
}
40-
}
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.batch.core.observability;
18+
19+
import io.micrometer.core.instrument.observation.Observation;
20+
21+
/**
22+
* {@link Observation.TagsProvider} for {@link BatchJobContext}.
23+
*
24+
* @author Marcin Grzejszczak
25+
* @since 5.0
26+
*/
27+
public interface BatchJobTagsProvider extends Observation.TagsProvider<BatchJobContext> {
28+
29+
@Override
30+
default boolean supportsContext(Observation.Context context) {
31+
return context instanceof BatchJobContext;
32+
}
33+
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.batch.core.metrics;
16+
package org.springframework.batch.core.observability;
1717

1818
import java.time.Duration;
1919
import java.util.Arrays;
@@ -75,7 +75,10 @@ public static Timer createTimer(String name, String description, Tag... tags) {
7575
* Remember to register the {@link TimerObservationHandler}
7676
* via the {@code Metrics.globalRegistry.withTimerObservationHandler()}
7777
* in the user code. Otherwise you won't observe any metrics.
78+
* @param name of the observation
79+
* @param context of the observation
7880
* @return a new observation instance
81+
* @since 5.0
7982
*/
8083
public static Observation createObservation(String name, Observation.Context context) {
8184
return Observation.createNotStarted(name, context, Metrics.globalRegistry);

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,12 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.batch.core.step;
17+
package org.springframework.batch.core.observability;
1818

1919
import io.micrometer.core.instrument.observation.Observation;
2020

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

23+
/**
24+
* Observation context for batch steps.
25+
*
26+
* @author Marcin Grzejszczak
27+
* @since 5.0
28+
*/
2329
public class BatchStepContext extends Observation.Context {
2430

2531
private final StepExecution stepExecution;

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

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,16 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.batch.core.step;
17+
package org.springframework.batch.core.observability;
1818

1919
import io.micrometer.core.instrument.docs.DocumentedObservation;
2020
import io.micrometer.core.instrument.docs.TagKey;
2121

22-
enum BatchStepObservation implements DocumentedObservation {
22+
/**
23+
* Observation created around a step execution.
24+
*
25+
* @author Marcin Grzejszczak
26+
* @author Mahmoud Ben Hassine
27+
* @since 5.0
28+
*/
29+
public enum BatchStepObservation implements DocumentedObservation {
2330

24-
/**
25-
* Observation created around a Job execution.
26-
*/
2731
BATCH_STEP_OBSERVATION {
2832
@Override
2933
public String getName() {
@@ -54,7 +58,7 @@ public String getPrefix() {
5458
enum StepLowCardinalityTags implements TagKey {
5559

5660
/**
57-
* Name of the Spring Batch job.
61+
* Name of the Spring Batch step.
5862
*/
5963
STEP_NAME {
6064
@Override
@@ -64,7 +68,7 @@ public String getKey() {
6468
},
6569

6670
/**
67-
* Type of the Spring Batch job.
71+
* Type of the Spring Batch step.
6872
*/
6973
STEP_TYPE {
7074
@Override
@@ -74,12 +78,12 @@ public String getKey() {
7478
},
7579

7680
/**
77-
* Name of the Spring Batch job.
81+
* Name of the Spring Batch job enclosing the step.
7882
*/
7983
JOB_NAME {
8084
@Override
8185
public String getKey() {
82-
return "spring.batch.job.name";
86+
return "spring.batch.step.job.name";
8387
}
8488
},
8589

@@ -98,7 +102,7 @@ public String getKey() {
98102
enum StepHighCardinalityTags implements TagKey {
99103

100104
/**
101-
* ID of the Spring Batch execution.
105+
* ID of the Spring Batch step execution.
102106
*/
103107
STEP_EXECUTION_ID {
104108
@Override
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
/*
2-
* Copyright 2006-2009 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
package org.springframework.batch.core.step;
18-
19-
import io.micrometer.core.instrument.observation.Observation;
20-
21-
/**
22-
* {@link Observation.TagsProvider} for {@link BatchStepContext}.
23-
*
24-
* @author Marcin Grzejszczak
25-
*/
26-
public interface BatchStepTagsProvider extends Observation.TagsProvider<BatchStepContext> {
27-
28-
@Override
29-
default boolean supportsContext(Observation.Context context) {
30-
return context instanceof BatchStepContext;
31-
}
32-
}
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.batch.core.observability;
18+
19+
import io.micrometer.core.instrument.observation.Observation;
20+
21+
/**
22+
* {@link Observation.TagsProvider} for {@link BatchStepContext}.
23+
*
24+
* @author Marcin Grzejszczak
25+
* @since 5.0
26+
*/
27+
public interface BatchStepTagsProvider extends Observation.TagsProvider<BatchStepContext> {
28+
29+
@Override
30+
default boolean supportsContext(Observation.Context context) {
31+
return context instanceof BatchStepContext;
32+
}
33+
}

0 commit comments

Comments
 (0)