Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f359dbd

Browse filesBrowse files
committed
BugFix: Skip validating and parsing commit lines early (#1108)
Signed-off-by: Wissam Abu Ahmad <xy.wissam@gmail.com>
1 parent 8dfa10e commit f359dbd
Copy full SHA for f359dbd

File tree

Expand file treeCollapse file tree

2 files changed

+13
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-0
lines changed
Open diff view settings
Collapse file

‎prometheus_client/parser.py‎

Copy file name to clipboardExpand all lines: prometheus_client/parser.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ def build_metric(name: str, documentation: str, typ: str, samples: List[Sample])
308308
continue
309309
candidate_name, quoted = '', False
310310
if len(parts) > 2:
311+
if parts[1] != 'TYPE' and parts[1] != 'HELP':
312+
continue
311313
candidate_name, quoted = _unquote_unescape(parts[2])
312314
if not quoted and not _is_valid_legacy_metric_name(candidate_name):
313315
raise ValueError
Collapse file

‎tests/test_parser.py‎

Copy file name to clipboardExpand all lines: tests/test_parser.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ def test_blank_lines_and_comments(self):
120120
""")
121121
self.assertEqualMetrics([CounterMetricFamily("a", "help", value=1)], list(families))
122122

123+
124+
def test_comments_parts_are_not_validated_against_legacy_metric_name(self):
125+
# https://github.com/prometheus/client_python/issues/1108
126+
families = text_string_to_metric_families("""
127+
# A simple. comment line where third token cannot be matched against METRIC_NAME_RE under validation.py
128+
# 3565 12345/4436467 another random comment line where third token cannot be matched against METRIC_NAME_RE under validation.py
129+
""")
130+
self.assertEqualMetrics([], list(families))
131+
132+
133+
123134
def test_tabs(self):
124135
families = text_string_to_metric_families("""#\tTYPE\ta\tcounter
125136
#\tHELP\ta\thelp

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.