Skip to content

Commit f39d9be

Browse files
committed
fix escaping
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 6c11f86 commit f39d9be

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ public void testGaugeUTF8() throws IOException {
507507
.labels(Labels.builder().label("name.1", "Björn").label("name*2", "佖佥").build())
508508
.build())
509509
.build();
510-
assertPrometheusText(prometheusText, gauge);
510+
ByteArrayOutputStream out = new ByteArrayOutputStream();
511+
getPrometheusWriter(PrometheusTextFormatWriter.builder().setIncludeCreatedTimestamps(true))
512+
.write(out, MetricSnapshots.of((MetricSnapshot) gauge), EscapingScheme.NO_ESCAPING);
513+
assertThat(out).hasToString(prometheusText);
511514
}
512515

513516
@Test
@@ -2830,7 +2833,7 @@ private void assertOpenMetricsText(String expected, MetricSnapshot snapshot) thr
28302833
ByteArrayOutputStream out = new ByteArrayOutputStream();
28312834
OpenMetricsTextFormatWriter writer =
28322835
OpenMetricsTextFormatWriter.builder().setCreatedTimestampsEnabled(true).build();
2833-
writer.write(out, MetricSnapshots.of(snapshot), EscapingScheme.NO_ESCAPING);
2836+
writer.write(out, MetricSnapshots.of(snapshot), EscapingScheme.UNDERSCORE_ESCAPING);
28342837
assertThat(out).hasToString(expected);
28352838
}
28362839

@@ -2842,22 +2845,22 @@ private void assertOpenMetricsTextWithExemplarsOnAllTimeSeries(
28422845
.setCreatedTimestampsEnabled(true)
28432846
.setExemplarsOnAllMetricTypesEnabled(true)
28442847
.build();
2845-
writer.write(out, MetricSnapshots.of(snapshot), EscapingScheme.NO_ESCAPING);
2848+
writer.write(out, MetricSnapshots.of(snapshot), EscapingScheme.UNDERSCORE_ESCAPING);
28462849
assertThat(out).hasToString(expected);
28472850
}
28482851

28492852
private void assertOpenMetricsTextWithoutCreated(String expected, MetricSnapshot snapshot)
28502853
throws IOException {
28512854
ByteArrayOutputStream out = new ByteArrayOutputStream();
28522855
OpenMetricsTextFormatWriter writer = OpenMetricsTextFormatWriter.create();
2853-
writer.write(out, MetricSnapshots.of(snapshot), EscapingScheme.NO_ESCAPING);
2856+
writer.write(out, MetricSnapshots.of(snapshot), EscapingScheme.UNDERSCORE_ESCAPING);
28542857
assertThat(out).hasToString(expected);
28552858
}
28562859

28572860
private void assertPrometheusText(String expected, MetricSnapshot snapshot) throws IOException {
28582861
ByteArrayOutputStream out = new ByteArrayOutputStream();
28592862
getPrometheusWriter(PrometheusTextFormatWriter.builder().setIncludeCreatedTimestamps(true))
2860-
.write(out, MetricSnapshots.of(snapshot), EscapingScheme.NO_ESCAPING);
2863+
.write(out, MetricSnapshots.of(snapshot), EscapingScheme.UNDERSCORE_ESCAPING);
28612864
assertThat(out).hasToString(expected);
28622865
}
28632866

@@ -2871,7 +2874,7 @@ private void assertPrometheusTextWithoutCreated(String expected, MetricSnapshot
28712874
throws IOException {
28722875
ByteArrayOutputStream out = new ByteArrayOutputStream();
28732876
getPrometheusWriter(PrometheusTextFormatWriter.builder())
2874-
.write(out, MetricSnapshots.of(snapshot), EscapingScheme.NO_ESCAPING);
2877+
.write(out, MetricSnapshots.of(snapshot), EscapingScheme.UNDERSCORE_ESCAPING);
28752878
assertThat(out).hasToString(expected);
28762879
}
28772880

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
@@ -46,7 +46,7 @@ public class PrometheusNaming {
4646

4747
/** Legal characters for metric names, including dot. */
4848
private static final Pattern LEGACY_METRIC_NAME_PATTERN =
49-
Pattern.compile("^[a-zA-Z_.:][a-zA-Z0-9_.:]*$");
49+
Pattern.compile("^[a-zA-Z_:][a-zA-Z0-9_:]*$");
5050

5151
private static final Pattern METRIC_NAME_PATTERN = Pattern.compile("^[a-zA-Z_:][a-zA-Z0-9_:]*$");
5252

0 commit comments

Comments
 (0)