From 69b836e989448fc27c92131ef06b0925803a0df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=BC=C3=9F?= Date: Fri, 5 Sep 2025 13:06:15 +0200 Subject: [PATCH] fix: remove space after comma in openmetrics exposition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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üß --- prometheus_client/openmetrics/exposition.py | 2 +- tests/openmetrics/test_exposition.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/prometheus_client/openmetrics/exposition.py b/prometheus_client/openmetrics/exposition.py index bc24c7cf..1dc05c5b 100644 --- a/prometheus_client/openmetrics/exposition.py +++ b/prometheus_client/openmetrics/exposition.py @@ -72,7 +72,7 @@ def generate_latest(registry, escaping=UNDERSCORES, version="1.0.0"): if escaping == ALLOWUTF8 and not _is_valid_legacy_metric_name(s.name): labelstr = escape_metric_name(s.name, escaping) if s.labels: - labelstr += ', ' + labelstr += ',' else: labelstr = '' diff --git a/tests/openmetrics/test_exposition.py b/tests/openmetrics/test_exposition.py index 6c879ec4..a3ed0d6e 100644 --- a/tests/openmetrics/test_exposition.py +++ b/tests/openmetrics/test_exposition.py @@ -169,7 +169,7 @@ def test_native_histogram_utf8_stress(self) -> None: self.custom_collector(hfm) self.assertEqual(b"""# HELP "native{histogram" Is a basic example of a native histogram # TYPE "native{histogram" histogram -{"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]} +{"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]} # EOF """, generate_latest(self.registry, ALLOWUTF8, version="2.0.0")) @@ -189,7 +189,7 @@ def test_native_histogram_with_labels_utf8(self) -> None: self.custom_collector(hfm) self.assertEqual(b"""# HELP "hist.w.labels" Is a basic example of a native histogram with labels # TYPE "hist.w.labels" histogram -{"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]} +{"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]} # EOF """, generate_latest(self.registry, ALLOWUTF8, version="2.0.0"))