8000 Merge pull request #872 from prometheus/parse-missing-space · alopezz/client_python@ba34fad · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit ba34fad

Browse files
authored
Merge pull request prometheus#872 from prometheus/parse-missing-space
Allow Prometheus parser to handle missing space
2 parents 781e3e1 + ff23948 commit ba34fad

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

prometheus_client/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def _parse_sample(text):
116116
name = text[:label_start].strip()
117117
# We ignore the starting curly brace
118118
label = text[label_start + 1:label_end]
119-
# The value is after the label end (ignoring curly brace and space)
120-
value, timestamp = _parse_value_and_timestamp(text[label_end + 2:])
119+
# The value is after the label end (ignoring curly brace)
120+
value, timestamp = _parse_value_and_timestamp(text[label_end + 1:])
121121
return Sample(name, _parse_labels(label), value, timestamp)
122122

123123
# We don't have labels

tests/openmetrics/test_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ def test_invalid_input(self):
642642
('a{a""} 1\n# EOF\n'),
643643
('a{a=} 1\n# EOF\n'),
644644
('a{a="} 1\n# EOF\n'),
645+
# Missing delimiters.
646+
('a{a="1"}1\n# EOF\n'),
645647
# Missing or extra commas.
646648
('a{a="1"b="2"} 1\n# EOF\n'),
647649
('a{a="1",,b="2"} 1\n# EOF\n'),

tests/test_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ def test_spaces(self):
146146
a { foo = "buz" } 3
147147
a\t { \t foo\t = "biz"\t } \t 4
148148
a \t{\t foo = "boz"\t}\t 5
149+
a{foo="bez"}6
149150
""")
150151
metric_family = CounterMetricFamily("a", "help", labels=["foo"])
151152
metric_family.add_metric(["bar"], 1)
152153
metric_family.add_metric(["baz"], 2)
153154
metric_family.add_metric(["buz"], 3)
154155
metric_family.add_metric(["biz"], 4)
155156
metric_family.add_metric(["boz"], 5)
157+
metric_family.add_metric(["bez"], 6)
156158
self.assertEqualMetrics([metric_family], list(families))
157159

158160
def test_commas(self):

0 commit comments

Comments
 (0)
0