Skip to content

Commit 69b836e

Browse files
committed
fix: remove space after comma in openmetrics exposition
OpenMetrics doesn't allow for spaces between labels and prometheus fails with a parsing error. Removing this fixes UTF8 metrics exposition Signed-off-by: Dominik Süß <dominik@suess.wtf>
1 parent 3586355 commit 69b836e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

prometheus_client/openmetrics/exposition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def generate_latest(registry, escaping=UNDERSCORES, version="1.0.0"):
7272
if escaping == ALLOWUTF8 and not _is_valid_legacy_metric_name(s.name):
7373
labelstr = escape_metric_name(s.name, escaping)
7474
if s.labels:
75-
labelstr += ', '
75+
labelstr += ','
7676
else:
7777
labelstr = ''
7878

tests/openmetrics/test_exposition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_native_histogram_utf8_stress(self) -> None:
169169
self.custom_collector(hfm)
170170
self.assertEqual(b"""# HELP "native{histogram" Is a basic example of a native histogram
171171
# TYPE "native{histogram" histogram
172-
{"native{histogram", "xx{} # {}"=" EOF # {}}}"} {count:24,sum:100,schema:0,zero_threshold:0.001,zero_count:4,negative_spans:[0:2,1:2],negative_deltas:[2,1,-2,3],positive_spans:[0:2,1:2],positive_deltas:[2,1,-3,3]}
172+
{"native{histogram","xx{} # {}"=" EOF # {}}}"} {count:24,sum:100,schema:0,zero_threshold:0.001,zero_count:4,negative_spans:[0:2,1:2],negative_deltas:[2,1,-2,3],positive_spans:[0:2,1:2],positive_deltas:[2,1,-3,3]}
173173
# EOF
174174
""", generate_latest(self.registry, ALLOWUTF8, version="2.0.0"))
175175

@@ -189,7 +189,7 @@ def test_native_histogram_with_labels_utf8(self) -> None:
189189
self.custom_collector(hfm)
190190
self.assertEqual(b"""# HELP "hist.w.labels" Is a basic example of a native histogram with labels
191191
# TYPE "hist.w.labels" histogram
192-
{"hist.w.labels", baz="qux",foo="bar"} {count:24,sum:100,schema:0,zero_threshold:0.001,zero_count:4,negative_spans:[0:2,1:2],negative_deltas:[2,1,-2,3],positive_spans:[0:2,1:2],positive_deltas:[2,1,-3,3]}
192+
{"hist.w.labels",baz="qux",foo="bar"} {count:24,sum:100,schema:0,zero_threshold:0.001,zero_count:4,negative_spans:[0:2,1:2],negative_deltas:[2,1,-2,3],positive_spans:[0:2,1:2],positive_deltas:[2,1,-3,3]}
193193
# EOF
194194
""", generate_latest(self.registry, ALLOWUTF8, version="2.0.0"))
195195

0 commit comments

Comments
 (0)