Skip to content

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

Open
@qwazer

Description

@qwazer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions