Prefix micrometer metric tags with meter names

This is what is recommended by the observability
team in terms of tag naming with micrometer 1.10+
for consistency between both metrics and tracing.

In #4065, only some metrics have been updated to
follow this tag naming convention, but not all of
them. This commit updates all metrics in a similar
way for consistency.

Related to #4065 and #4098.
This commit is contained in:
Mahmoud Ben Hassine
2022-05-18 20:47:23 +02:00
parent 53eabcdeee
commit c4076e855d
5 changed files with 31 additions and 28 deletions

View File

@@ -310,8 +310,9 @@ InitializingBean, Observation.KeyValuesProviderAware<BatchJobKeyValuesProvider>
}
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())

View File

@@ -47,7 +47,7 @@ import org.springframework.lang.Nullable;
*/
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";

View File

@@ -341,10 +341,11 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
}
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)
));
}

View File

@@ -150,10 +150,11 @@ public class SimpleChunkProvider<I> implements ChunkProvider<I> {
}
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)
));
}

View File

@@ -165,7 +165,7 @@ public class BatchMetricsTests {
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 class BatchMetricsTests {
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 class BatchMetricsTests {
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 class BatchMetricsTests {
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 class BatchMetricsTests {
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 class BatchMetricsTests {
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 class BatchMetricsTests {
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" +