spring-projects / spring-projects/spring-batch
Spring batch metrics is not aware of JobExecutionListener that modify job status
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
I have a Spring Boot 2.5.2 app with spring-batch-4.3.3
The app has a multi-step job and a custom JobStatusReportingListener
@Component
public class JobStatusReportingListener implements JobExecutionListener {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void beforeJob(JobExecution jobExecution) {
}
@Override
public void afterJob(JobExecution jobExecution) {
List<StepExecution> failedSteps = jobExecution
.getStepExecutions()
.stream().filter(v -> !v.getExitStatus().equals(COMPLETED))
.collect(Collectors.toList());
if (!failedSteps.isEmpty()) {
jobExecution.setStatus(BatchStatus.FAILED);
jobExecution.setExitStatus(ExitStatus.FAILED);
logger.error("Job failed on steps {}", failedSteps);
}
}
}
The problem is that metrics at actuator/metrics/spring.batch.job doesn't contain tags with status="FAILED" that is set by JobExecutionListener
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the multi-step job with the provided JobStatusReportingListener and inspect actuator/metrics/spring.batch.job after the listener changes the JobExecution status. Trace when the Spring Batch job metric records its status, then verify that a job changed to FAILED exposes a status="FAILED" tag in the metric output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100