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)
));
}