From 8260fbb6adcc6f7f03d15c8a2864b017dbd88cc1 Mon Sep 17 00:00:00 2001 From: Brad Cowie Date: Thu, 5 Jun 2025 10:56:41 +1200 Subject: [PATCH 1/2] Upgrade python3-prometheus-client to v0.22.1 --- prometheus_client/parser.py | 6 +++--- pyproject.toml | 11 +++++++---- tests/test_parser.py | 11 +++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/prometheus_client/parser.py b/prometheus_client/parser.py index 92d6672..0434edf 100644 --- a/prometheus_client/parser.py +++ b/prometheus_client/parser.py @@ -308,6 +308,9 @@ def build_metric(name: str, documentation: str, typ: str, samples: List[Sample]) continue candidate_name, quoted = '', False if len(parts) > 2: + # Ignore comment tokens + if parts[1] != 'TYPE' and parts[1] != 'HELP': + continue candidate_name, quoted = _unquote_unescape(parts[2]) if not quoted and not _is_valid_legacy_metric_name(candidate_name): raise ValueError @@ -342,9 +345,6 @@ def build_metric(name: str, documentation: str, typ: str, samples: List[Sample]) 'histogram': ['_count', '_sum', '_bucket'], }.get(typ, ['']) allowed_names = [name + n for n in allowed_names] - else: - # Ignore other comment tokens - pass elif line == '': # Ignore blank lines pass diff --git a/pyproject.toml b/pyproject.toml index 5305e38..0c76250 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,17 @@ [build-system] -requires = ["setuptools"] +requires = ["setuptools>=77.0.0"] build-backend = "setuptools.build_meta" [project] name = "prometheus_client" -version = "0.22.0" +version = "0.22.1" description = "Python client for the Prometheus monitoring system." readme = "README.md" -license = { file = "LICENSE" } +license = "Apache-2.0 AND BSD-2-Clause" +license-files = [ + "LICENSE", + "NOTICE", +] requires-python = ">=3.9" authors = [ { name = "The Prometheus Authors", email = "prometheus-developers@googlegroups.com" }, @@ -33,7 +37,6 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: System :: Monitoring", - "License :: OSI Approved :: Apache Software License", ] [project.optional-dependencies] diff --git a/tests/test_parser.py b/tests/test_parser.py index 10a2fc9..e18a878 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -120,6 +120,17 @@ def test_blank_lines_and_comments(self): """) self.assertEqualMetrics([CounterMetricFamily("a", "help", value=1)], list(families)) + + def test_comments_parts_are_not_validated_against_legacy_metric_name(self): + # https://github.com/prometheus/client_python/issues/1108 + families = text_string_to_metric_families(""" +# A simple. comment line where third token cannot be matched against METRIC_NAME_RE under validation.py +# 3565 12345/4436467 another random comment line where third token cannot be matched against METRIC_NAME_RE under validation.py +""") + self.assertEqualMetrics([], list(families)) + + + def test_tabs(self): families = text_string_to_metric_families("""#\tTYPE\ta\tcounter #\tHELP\ta\thelp From 46a960100e791e557197b5790e3c64fcdebc1cd0 Mon Sep 17 00:00:00 2001 From: Brad Cowie Date: Thu, 5 Jun 2025 11:37:48 +1200 Subject: [PATCH 2/2] Update d/p/0002-Update-pyproject.toml.patch --- debian/patches/0002-Update-pyproject.toml.patch | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/debian/patches/0002-Update-pyproject.toml.patch b/debian/patches/0002-Update-pyproject.toml.patch index c379c4b..720624b 100644 --- a/debian/patches/0002-Update-pyproject.toml.patch +++ b/debian/patches/0002-Update-pyproject.toml.patch @@ -2,7 +2,20 @@ Index: python3-prometheus-client/pyproject.toml =================================================================== --- python3-prometheus-client.orig/pyproject.toml +++ python3-prometheus-client/pyproject.toml -@@ -47,3 +47,17 @@ Documentation = "https://prometheus.gith +@@ -7,11 +7,7 @@ name = "prometheus_client" + version = "0.22.1" + description = "Python client for the Prometheus monitoring system." + readme = "README.md" +-license = "Apache-2.0 AND BSD-2-Clause" +-license-files = [ +- "LICENSE", +- "NOTICE", +-] ++license = { file = "LICENSE" } + requires-python = ">=3.9" + authors = [ + { name = "The Prometheus Authors", email = "prometheus-developers@googlegroups.com" }, +@@ -50,3 +46,17 @@ Documentation = "https://prometheus.gith [tool.setuptools.package-data] prometheus_client = ['py.typed']