See this part of code (taken from commit at v1.16.5):
|
@Override |
|
public Counter newCounter(Meter.Id id) { |
|
PrometheusCounter counter = new PrometheusCounter(id, exemplarSamplerFactory); |
|
long createdTimestampMillis = clock.wallTime(); |
|
applyToCollector(id, (collector) -> { |
|
List<String> tagValues = tagValues(id); |
|
collector |
|
.add(tagValues, (conventionName, tagKeys) -> Stream.of(new MicrometerCollector.Family<>(conventionName, |
|
family -> new CounterSnapshot(family.metadata, family.dataPointSnapshots), |
|
getMetadata(conventionName, id.getDescription()), new CounterDataPointSnapshot(counter.count(), |
|
Labels.of(tagKeys, tagValues), counter.exemplar(), createdTimestampMillis)))); |
|
}); |
|
return counter; |
|
} |
getMetadata and Labels.of are called within the inner lambda, the one that implements Child and is called on every scrape. These calls construct the same Metadata and Labels objects over and over, which in turn also performs repeated validation (PrometheusNaming.validateMetricName and PrometheusNaming.validateLabelName), verifying on each scrape that the metric name and label names are valid UTF-8.
The Metadata and Labels can in fact be created and validated once, because the conventionName and tagKeys are stored in the MicrometerCollector and not modified during its lifetime. This will make scraping more efficient in terms of performance and garbage.
The same applies to all meter types, not only to counters.
If the maintainers agree with the idea of this change, I can open a PR to implement it.
See this part of code (taken from commit at v1.16.5):
micrometer/implementations/micrometer-registry-prometheus/src/main/java/io/micrometer/prometheusmetrics/PrometheusMeterRegistry.java
Lines 209 to 222 in cf727d0
getMetadataandLabels.ofare called within the inner lambda, the one that implementsChildand is called on every scrape. These calls construct the sameMetadataandLabelsobjects over and over, which in turn also performs repeated validation (PrometheusNaming.validateMetricNameandPrometheusNaming.validateLabelName), verifying on each scrape that the metric name and label names are valid UTF-8.The
MetadataandLabelscan in fact be created and validated once, because theconventionNameandtagKeysare stored in theMicrometerCollectorand not modified during its lifetime. This will make scraping more efficient in terms of performance and garbage.The same applies to all meter types, not only to counters.
If the maintainers agree with the idea of this change, I can open a PR to implement it.