diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index a7bf0008e6..148baefd3b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -310,8 +310,9 @@ public final void execute(JobExecution execution) { } JobSynchronizationManager.register(execution); - LongTaskTimer longTaskTimer = BatchMetrics.createLongTaskTimer("job.active", "Active jobs", - Tag.of("name", execution.getJobInstance().getJobName())); + String activeJobMeterName = "job.active"; + LongTaskTimer longTaskTimer = BatchMetrics.createLongTaskTimer(activeJobMeterName, "Active jobs", + Tag.of(BatchMetrics.METRICS_PREFIX + activeJobMeterName + ".name", execution.getJobInstance().getJobName())); LongTaskTimer.Sample longTaskTimerSample = longTaskTimer.start(); Observation observation = BatchMetrics.createObservation(BatchJobObservation.BATCH_JOB_OBSERVATION.getName(), new BatchJobContext(execution)) .contextualName(execution.getJobInstance().getJobName()) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java b/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java index a5508ca54e..1bf4b4c755 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java @@ -47,7 +47,7 @@ */ public final class BatchMetrics { - private static final String METRICS_PREFIX = "spring.batch."; + public static final String METRICS_PREFIX = "spring.batch."; public static final String STATUS_SUCCESS = "SUCCESS"; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java index bffc779c5e..f5be9ee111 100755 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProcessor.java @@ -341,10 +341,11 @@ protected Chunk transform(StepContribution contribution, Chunk inputs) thr } protected void stopTimer(Timer.Sample sample, StepExecution stepExecution, String metricName, String status, String description) { + String fullyQualifiedMetricName = BatchMetrics.METRICS_PREFIX + metricName; sample.stop(BatchMetrics.createTimer(metricName, description + " duration", - Tag.of("job.name", stepExecution.getJobExecution().getJobInstance().getJobName()), - Tag.of("step.name", stepExecution.getStepName()), - Tag.of("status", status) + Tag.of(fullyQualifiedMetricName + ".job.name", stepExecution.getJobExecution().getJobInstance().getJobName()), + Tag.of(fullyQualifiedMetricName + ".step.name", stepExecution.getStepName()), + Tag.of(fullyQualifiedMetricName + ".status", status) )); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProvider.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProvider.java index e836e73305..910e781755 100755 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProvider.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProvider.java @@ -150,10 +150,11 @@ public RepeatStatus doInIteration(final RepeatContext context) throws Exception } private void stopTimer(Timer.Sample sample, StepExecution stepExecution, String status) { + String fullyQualifiedMetricName = BatchMetrics.METRICS_PREFIX + "item.read"; sample.stop(BatchMetrics.createTimer("item.read", "Item reading duration", - Tag.of("job.name", stepExecution.getJobExecution().getJobInstance().getJobName()), - Tag.of("step.name", stepExecution.getStepName()), - Tag.of("status", status) + Tag.of(fullyQualifiedMetricName + ".job.name", stepExecution.getJobExecution().getJobInstance().getJobName()), + Tag.of(fullyQualifiedMetricName + ".step.name", stepExecution.getStepName()), + Tag.of(fullyQualifiedMetricName + ".status", status) )); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java index 4256cfe117..391dd35266 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/observability/BatchMetricsTests.java @@ -165,7 +165,7 @@ public void testBatchMetrics() throws Exception { try { Metrics.globalRegistry.get("spring.batch.job.active") - .tag("name", "job") + .tag("spring.batch.job.active.name", "job") .longTaskTimer(); } catch (Exception e) { fail("There should be a meter of type LONG_TASK_TIMER named spring.batch.job.active" + @@ -200,9 +200,9 @@ public void testBatchMetrics() throws Exception { try { Metrics.globalRegistry.get("spring.batch.item.read") - .tag("job.name", "job") - .tag("step.name", "step2") - .tag("status", "SUCCESS") + .tag("spring.batch.item.read.job.name", "job") + .tag("spring.batch.item.read.step.name", "step2") + .tag("spring.batch.item.read.status", "SUCCESS") .timer(); } catch (Exception e) { fail("There should be a meter of type TIMER named spring.batch.item.read" + @@ -211,9 +211,9 @@ public void testBatchMetrics() throws Exception { try { Metrics.globalRegistry.get("spring.batch.item.process") - .tag("job.name", "job") - .tag("step.name", "step2") - .tag("status", "SUCCESS") + .tag("spring.batch.item.process.job.name", "job") + .tag("spring.batch.item.process.step.name", "step2") + .tag("spring.batch.item.process.status", "SUCCESS") .timer(); } catch (Exception e) { fail("There should be a meter of type TIMER named spring.batch.item.process" + @@ -222,9 +222,9 @@ public void testBatchMetrics() throws Exception { try { Metrics.globalRegistry.get("spring.batch.chunk.write") - .tag("job.name", "job") - .tag("step.name", "step2") - .tag("status", "SUCCESS") + .tag("spring.batch.chunk.write.job.name", "job") + .tag("spring.batch.chunk.write.step.name", "step2") + .tag("spring.batch.chunk.write.status", "SUCCESS") .timer(); } catch (Exception e) { fail("There should be a meter of type TIMER named spring.batch.chunk.write" + @@ -246,9 +246,9 @@ public void testBatchMetrics() throws Exception { try { Metrics.globalRegistry.get("spring.batch.item.read") - .tag("job.name", "job") - .tag("step.name", "step3") - .tag("status", "SUCCESS") + .tag("spring.batch.item.read.job.name", "job") + .tag("spring.batch.item.read.step.name", "step3") + .tag("spring.batch.item.read.status", "SUCCESS") .timer(); } catch (Exception e) { fail("There should be a meter of type TIMER named spring.batch.item.read" + @@ -257,9 +257,9 @@ public void testBatchMetrics() throws Exception { try { Metrics.globalRegistry.get("spring.batch.item.process") - .tag("job.name", "job") - .tag("step.name", "step3") - .tag("status", "SUCCESS") + .tag("spring.batch.item.process.job.name", "job") + .tag("spring.batch.item.process.step.name", "step3") + .tag("spring.batch.item.process.status", "SUCCESS") .timer(); } catch (Exception e) { fail("There should be a meter of type TIMER named spring.batch.item.process" + @@ -268,9 +268,9 @@ public void testBatchMetrics() throws Exception { try { Metrics.globalRegistry.get("spring.batch.chunk.write") - .tag("job.name", "job") - .tag("step.name", "step3") - .tag("status", "SUCCESS") + .tag("spring.batch.chunk.write.job.name", "job") + .tag("spring.batch.chunk.write.step.name", "step3") + .tag("spring.batch.chunk.write.status", "SUCCESS") .timer(); } catch (Exception e) { fail("There should be a meter of type TIMER named spring.batch.chunk.write" +