spring-projects / spring-projects/spring-batch

Spring batch metrics is not aware of JobExecutionListener that modify job status

Open
#3,963 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: need-help-to-reproduce status: waiting-for-reporter type: bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.