8000 BugFix: Skip validating and parsing commit lines early (#1108) · wissamir/client_python@f359dbd · GitHub
[go: up one dir, main page]

Skip to content

Commit f359dbd

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

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

prometheus_client/parser.py

Lines 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

tests/test_parser.py

Lines 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