Skip to content

Commit

Permalink
Refine contribution #4065
Browse files Browse the repository at this point in the history
* Fix tests
* Update Javadocs
* Update year in license headers
* Move observability APIs to a separate package
  • Loading branch information
fmbenhassine committed Mar 16, 2022
1 parent e917d75 commit ae6c0b9
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 132 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<spring-retry.version>1.3.1</spring-retry.version>
<spring-integration.version>6.0.0-SNAPSHOT</spring-integration.version>
<micrometer.version>2.0.0-SNAPSHOT</micrometer.version>
<micrometer-tracing.version>1.0.0-SNAPSHOT</micrometer-tracing.version>
<jackson.version>2.13.1</jackson.version>

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

<!-- test dependencies -->
<micrometer-tracing.version>1.0.0-SNAPSHOT</micrometer-tracing.version>
<junit.version>4.13.2</junit.version>
<hamcrest.version>2.2</hamcrest.version>
<assertj.version>3.21.0</assertj.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,11 @@
import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.batch.core.launch.support.ExitCodeMapper;
import org.springframework.batch.core.listener.CompositeJobExecutionListener;
import org.springframework.batch.core.metrics.BatchMetrics;
import org.springframework.batch.core.observability.BatchMetrics;
import org.springframework.batch.core.observability.BatchJobContext;
import org.springframework.batch.core.observability.BatchJobObservation;
import org.springframework.batch.core.observability.BatchJobTagsProvider;
import org.springframework.batch.core.observability.DefaultBatchJobTagsProvider;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.scope.context.JobSynchronizationManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.metrics.BatchMetrics;
import org.springframework.batch.core.observability.BatchMetrics;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,18 @@
* limitations under the License.
*/

package org.springframework.batch.core.job;
package org.springframework.batch.core.observability;

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

import org.springframework.batch.core.JobExecution;

/**
* Observation context for batch jobs.
*
* @author Marcin Grzejszczak
* @since 5.0
*/
public class BatchJobContext extends Observation.Context {

private final JobExecution jobExecution;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,16 +14,20 @@
* limitations under the License.
*/

package org.springframework.batch.core.job;
package org.springframework.batch.core.observability;

import io.micrometer.core.instrument.docs.DocumentedObservation;
import io.micrometer.core.instrument.docs.TagKey;

enum BatchJobObservation implements DocumentedObservation {
/**
* Observation created around a Job execution.
*
* @author Marcin Grzejszczak
* @author Mahmoud Ben Hassine
* @since 5.0
*/
public enum BatchJobObservation implements DocumentedObservation {

/**
* Observation created around a Job execution.
*/
BATCH_JOB_OBSERVATION {
@Override
public String getName() {
Expand Down Expand Up @@ -88,7 +92,7 @@ public String getKey() {
},

/**
* ID of the Spring Batch execution.
* ID of the Spring Batch job execution.
*/
JOB_EXECUTION_ID {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
/*
* Copyright 2006-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.batch.core.job;

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

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StartLimitExceededException;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRestartException;

/**
* {@link Observation.TagsProvider} for {@link BatchJobContext}.
*
* @author Marcin Grzejszczak
*/
public interface BatchJobTagsProvider extends Observation.TagsProvider<BatchJobContext> {

@Override
default boolean supportsContext(Observation.Context context) {
return context instanceof BatchJobContext;
}
}
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.batch.core.observability;

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

/**
* {@link Observation.TagsProvider} for {@link BatchJobContext}.
*
* @author Marcin Grzejszczak
* @since 5.0
*/
public interface BatchJobTagsProvider extends Observation.TagsProvider<BatchJobContext> {

@Override
default boolean supportsContext(Observation.Context context) {
return context instanceof BatchJobContext;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.metrics;
package org.springframework.batch.core.observability;

import java.time.Duration;
import java.util.Arrays;
Expand Down Expand Up @@ -75,7 +75,10 @@ public static Timer createTimer(String name, String description, Tag... tags) {
* Remember to register the {@link TimerObservationHandler}
* via the {@code Metrics.globalRegistry.withTimerObservationHandler()}
* in the user code. Otherwise you won't observe any metrics.
* @param name of the observation
* @param context of the observation
* @return a new observation instance
* @since 5.0
*/
public static Observation createObservation(String name, Observation.Context context) {
return Observation.createNotStarted(name, context, Metrics.globalRegistry);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,18 @@
* limitations under the License.
*/

package org.springframework.batch.core.step;
package org.springframework.batch.core.observability;

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

import org.springframework.batch.core.StepExecution;

/**
* Observation context for batch steps.
*
* @author Marcin Grzejszczak
* @since 5.0
*/
public class BatchStepContext extends Observation.Context {

private final StepExecution stepExecution;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,16 +14,20 @@
* limitations under the License.
*/

package org.springframework.batch.core.step;
package org.springframework.batch.core.observability;

import io.micrometer.core.instrument.docs.DocumentedObservation;
import io.micrometer.core.instrument.docs.TagKey;

enum BatchStepObservation implements DocumentedObservation {
/**
* Observation created around a step execution.
*
* @author Marcin Grzejszczak
* @author Mahmoud Ben Hassine
* @since 5.0
*/
public enum BatchStepObservation implements DocumentedObservation {

/**
* Observation created around a Job execution.
*/
BATCH_STEP_OBSERVATION {
@Override
public String getName() {
Expand Down Expand Up @@ -54,7 +58,7 @@ public String getPrefix() {
enum StepLowCardinalityTags implements TagKey {

/**
* Name of the Spring Batch job.
* Name of the Spring Batch step.
*/
STEP_NAME {
@Override
Expand All @@ -64,7 +68,7 @@ public String getKey() {
},

/**
* Type of the Spring Batch job.
* Type of the Spring Batch step.
*/
STEP_TYPE {
@Override
Expand All @@ -74,12 +78,12 @@ public String getKey() {
},

/**
* Name of the Spring Batch job.
* Name of the Spring Batch job enclosing the step.
*/
JOB_NAME {
@Override
public String getKey() {
return "spring.batch.job.name";
return "spring.batch.step.job.name";
}
},

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

/**
* ID of the Spring Batch execution.
* ID of the Spring Batch step execution.
*/
STEP_EXECUTION_ID {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
/*
* Copyright 2006-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.batch.core.step;

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

/**
* {@link Observation.TagsProvider} for {@link BatchStepContext}.
*
* @author Marcin Grzejszczak
*/
public interface BatchStepTagsProvider extends Observation.TagsProvider<BatchStepContext> {

@Override
default boolean supportsContext(Observation.Context context) {
return context instanceof BatchStepContext;
}
}
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.batch.core.observability;

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

/**
* {@link Observation.TagsProvider} for {@link BatchStepContext}.
*
* @author Marcin Grzejszczak
* @since 5.0
*/
public interface BatchStepTagsProvider extends Observation.TagsProvider<BatchStepContext> {

@Override
default boolean supportsContext(Observation.Context context) {
return context instanceof BatchStepContext;
}
}
Loading

0 comments on commit ae6c0b9

Please sign in to comment.