Replace KeyValuesProvider with ObservationConvention
Related to https://github.com/micrometer-metrics/micrometer/pull/3306
This commit is contained in:
@@ -44,9 +44,9 @@ import org.springframework.batch.core.launch.support.ExitCodeMapper;
|
||||
import org.springframework.batch.core.listener.CompositeJobExecutionListener;
|
||||
import org.springframework.batch.core.observability.BatchJobContext;
|
||||
import org.springframework.batch.core.observability.BatchJobObservation;
|
||||
import org.springframework.batch.core.observability.BatchJobKeyValuesProvider;
|
||||
import org.springframework.batch.core.observability.BatchJobObservationConvention;
|
||||
import org.springframework.batch.core.observability.BatchMetrics;
|
||||
import org.springframework.batch.core.observability.DefaultBatchJobKeyValuesProvider;
|
||||
import org.springframework.batch.core.observability.DefaultBatchJobObservationConvention;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.batch.core.scope.context.JobSynchronizationManager;
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractJob implements Job, StepLocator, BeanNameAware, In
|
||||
|
||||
private StepHandler stepHandler;
|
||||
|
||||
private BatchJobKeyValuesProvider keyValuesProvider = new DefaultBatchJobKeyValuesProvider();
|
||||
private BatchJobObservationConvention observationConvention = new DefaultBatchJobObservationConvention();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@@ -288,8 +288,8 @@ public abstract class AbstractJob implements Job, StepLocator, BeanNameAware, In
|
||||
LongTaskTimer.Sample longTaskTimerSample = longTaskTimer.start();
|
||||
Observation observation = BatchMetrics
|
||||
.createObservation(BatchJobObservation.BATCH_JOB_OBSERVATION.getName(), new BatchJobContext(execution))
|
||||
.contextualName(execution.getJobInstance().getJobName()).keyValuesProvider(this.keyValuesProvider)
|
||||
.start();
|
||||
.contextualName(execution.getJobInstance().getJobName())
|
||||
.observationConvention(this.observationConvention).start();
|
||||
try (Observation.Scope scope = observation.openScope()) {
|
||||
|
||||
jobParametersValidator.validate(execution.getJobParameters());
|
||||
@@ -433,8 +433,8 @@ public abstract class AbstractJob implements Job, StepLocator, BeanNameAware, In
|
||||
jobRepository.update(jobExecution);
|
||||
}
|
||||
|
||||
public void setKeyValuesProvider(BatchJobKeyValuesProvider keyValuesProvider) {
|
||||
this.keyValuesProvider = keyValuesProvider;
|
||||
public void setObservationConvention(BatchJobObservationConvention observationConvention) {
|
||||
this.observationConvention = observationConvention;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,12 +19,13 @@ package org.springframework.batch.core.observability;
|
||||
import io.micrometer.observation.Observation;
|
||||
|
||||
/**
|
||||
* {@link Observation.KeyValuesProvider} for {@link BatchJobContext}.
|
||||
* {@link Observation.ObservationConvention} for {@link BatchJobContext}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface BatchJobKeyValuesProvider extends Observation.KeyValuesProvider<BatchJobContext> {
|
||||
public interface BatchJobObservationConvention extends Observation.ObservationConvention<BatchJobContext> {
|
||||
|
||||
@Override
|
||||
default boolean supportsContext(Observation.Context context) {
|
||||
@@ -19,13 +19,13 @@ package org.springframework.batch.core.observability;
|
||||
import io.micrometer.observation.Observation;
|
||||
|
||||
/**
|
||||
* {@link Observation.KeyValuesProvider} for {@link BatchStepContext}.
|
||||
* {@link Observation.ObservationConvention} for {@link BatchStepContext}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 5.0
|
||||
*/
|
||||
public interface BatchStepKeyValuesProvider extends Observation.KeyValuesProvider<BatchStepContext> {
|
||||
public interface BatchStepObservationConvention extends Observation.ObservationConvention<BatchStepContext> {
|
||||
|
||||
@Override
|
||||
default boolean supportsContext(Observation.Context context) {
|
||||
@@ -20,13 +20,13 @@ import io.micrometer.common.KeyValues;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
|
||||
/**
|
||||
* Default {@link BatchJobKeyValuesProvider} implementation.
|
||||
* Default {@link BatchJobObservationConvention} implementation.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DefaultBatchJobKeyValuesProvider implements BatchJobKeyValuesProvider {
|
||||
public class DefaultBatchJobObservationConvention implements BatchJobObservationConvention {
|
||||
|
||||
@Override
|
||||
public KeyValues getLowCardinalityKeyValues(BatchJobContext context) {
|
||||
@@ -20,13 +20,13 @@ import io.micrometer.common.KeyValues;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
|
||||
/**
|
||||
* Default {@link BatchStepKeyValuesProvider} implementation.
|
||||
* Default {@link BatchStepObservationConvention} implementation.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 5.0
|
||||
*/
|
||||
public class DefaultBatchStepKeyValuesProvider implements BatchStepKeyValuesProvider {
|
||||
public class DefaultBatchStepObservationConvention implements BatchStepObservationConvention {
|
||||
|
||||
@Override
|
||||
public KeyValues getLowCardinalityKeyValues(BatchStepContext context) {
|
||||
@@ -38,8 +38,8 @@ import org.springframework.batch.core.listener.CompositeStepExecutionListener;
|
||||
import org.springframework.batch.core.observability.BatchMetrics;
|
||||
import org.springframework.batch.core.observability.BatchStepContext;
|
||||
import org.springframework.batch.core.observability.BatchStepObservation;
|
||||
import org.springframework.batch.core.observability.BatchStepKeyValuesProvider;
|
||||
import org.springframework.batch.core.observability.DefaultBatchStepKeyValuesProvider;
|
||||
import org.springframework.batch.core.observability.BatchStepObservationConvention;
|
||||
import org.springframework.batch.core.observability.DefaultBatchStepObservationConvention;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.scope.context.StepSynchronizationManager;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -74,7 +74,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
private BatchStepKeyValuesProvider keyValuesProvider = new DefaultBatchStepKeyValuesProvider();
|
||||
private BatchStepObservationConvention observationConvention = new DefaultBatchStepObservationConvention();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@@ -202,7 +202,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
Observation observation = BatchMetrics
|
||||
.createObservation(BatchStepObservation.BATCH_STEP_OBSERVATION.getName(),
|
||||
new BatchStepContext(stepExecution))
|
||||
.contextualName(stepExecution.getStepName()).keyValuesProvider(this.keyValuesProvider).start();
|
||||
.contextualName(stepExecution.getStepName()).observationConvention(this.observationConvention).start();
|
||||
getJobRepository().update(stepExecution);
|
||||
|
||||
// Start with a default value that will be trumped by anything
|
||||
@@ -418,8 +418,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
|
||||
return exitStatus;
|
||||
}
|
||||
|
||||
public void setKeyValuesProvider(BatchStepKeyValuesProvider keyValuesProvider) {
|
||||
this.keyValuesProvider = keyValuesProvider;
|
||||
public void setObservationConvention(BatchStepObservationConvention observationConvention) {
|
||||
this.observationConvention = observationConvention;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user