Skip to content

Commit 551d6c6

Browse files
committed
fix prometheus name check
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent cc6571f commit 551d6c6

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricMetadata.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.prometheus.metrics.model.snapshots;
22

3-
import io.prometheus.metrics.config.ValidationScheme;
4-
53
/** Immutable container for metric metadata: name, help, unit. */
64
public final class MetricMetadata {
75

@@ -20,8 +18,11 @@ public final class MetricMetadata {
2018
private final String name;
2119

2220
/**
23-
* Same as name, except if name contains dots, then the prometheusName is {@code name.replace(".",
24-
* "_")}.
21+
* Same as name that all invalid char (without Unicode support) are replaced by _
22+
*
23+
* <p>Multiple metrics with the same prometheusName are not allowed, because they would end up in
24+
* the same time series in Prometheus if {@link EscapingScheme#UNDERSCORE_ESCAPING} or {@link
25+
* EscapingScheme#DOTS_ESCAPING} is used.
2526
*/
2627
private final String prometheusName;
2728

@@ -54,12 +55,8 @@ public MetricMetadata(String name, String help, Unit unit) {
5455
this.name = name;
5556
this.help = help;
5657
this.unit = unit;
58+
this.prometheusName = PrometheusNaming.prometheusName(name);
5759
validate();
58-
this.prometheusName =
59-
name.contains(".")
60-
&& PrometheusNaming.getValidationScheme() == ValidationScheme.LEGACY_VALIDATION
61-
? PrometheusNaming.prometheusName(name)
62-
: name;
6360
}
6461

6562
/**

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/PrometheusNaming.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public static String validateUnitName(String name) {
218218
* @return the name with dots replaced by underscores.
219219
*/
220220
public static String prometheusName(String name) {
221-
return name.replace(".", "_");
221+
return PrometheusNaming.escapeName(name, EscapingScheme.UNDERSCORE_ESCAPING);
222222
}
223223

224224
/**

0 commit comments

Comments
 (0)