Fix metrics collection in FaultTolerantChunkProcessor

Before this commit, metrics were not collected in a fault-tolerant step.
This commit updates the FaultTolerantChunkProcessor to collect metrics.

For the record, chunk scanning is not covered for two reasons:

1. When scanning a chunk, there is a single item in each write operation,
so it would be incorrect to report a metric called "chunk.write" for a
single item. We could argue that it is a singleton chunk, but still..
If we want to time scanned (aka individual) items, we need a more fine
grained timer called "scanned.item.write" for example.

2. The end result can be confusing and might distort the overall metrics
view in case of errors (because of the noisy metrics of additional transactions
for individual items).

As a reminder, the goal of the "chunk.write" metric is to give an overview
of the write operation time of the whole chunk and not to time each item
individually (this could be done using an `ItemWriteListener` if needed).

Resolves #3664
This commit is contained in:
Mahmoud Ben Hassine
2020-02-17 14:10:02 +01:00
parent d933e4d7df
commit 6cca32fde0
4 changed files with 94 additions and 24 deletions

View File

@@ -27,6 +27,8 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.ItemListenerSupport;
@@ -55,7 +57,7 @@ public class FaultTolerantChunkProcessorTests {
private FaultTolerantChunkProcessor<String, String> processor;
private StepContribution contribution = new StepExecution("foo",
new JobExecution(0L)).createStepContribution();
new JobExecution(new JobInstance(0L, "job"), new JobParameters())).createStepContribution();
@Before
public void setUp() {