Skip to content

Commit

Permalink
Merge pull request #872 from prometheus/parse-missing-space
Browse files Browse the repository at this point in the history
Allow Prometheus parser to handle missing space
  • Loading branch information
csmarchbanks committed Dec 22, 2022
2 parents 781e3e1 + ff23948 commit ba34fad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prometheus_client/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def _parse_sample(text):
name = text[:label_start].strip()
# We ignore the starting curly brace
label = text[label_start + 1:label_end]
# The value is after the label end (ignoring curly brace and space)
value, timestamp = _parse_value_and_timestamp(text[label_end + 2:])
# The value is after the label end (ignoring curly brace)
value, timestamp = _parse_value_and_timestamp(text[label_end + 1:])
return Sample(name, _parse_labels(label), value, timestamp)

# We don't have labels
Expand Down
2 changes: 2 additions & 0 deletions tests/openmetrics/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ def test_invalid_input(self):
('a{a""} 1\n# EOF\n'),
('a{a=} 1\n# EOF\n'),
('a{a="} 1\n# EOF\n'),
# Missing delimiters.
('a{a="1"}1\n# EOF\n'),
# Missing or extra commas.
('a{a="1"b="2"} 1\n# EOF\n'),
('a{a="1",,b="2"} 1\n# EOF\n'),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,15 @@ def test_spaces(self):
a { foo = "buz" } 3
a\t { \t foo\t = "biz"\t } \t 4
a \t{\t foo = "boz"\t}\t 5
a{foo="bez"}6
""")
metric_family = CounterMetricFamily("a", "help", labels=["foo"])
metric_family.add_metric(["bar"], 1)
metric_family.add_metric(["baz"], 2)
metric_family.add_metric(["buz"], 3)
metric_family.add_metric(["biz"], 4)
metric_family.add_metric(["boz"], 5)
metric_family.add_metric(["bez"], 6)
self.assertEqualMetrics([metric_family], list(families))

def test_commas(self):
Expand Down

0 comments on commit ba34fad

Please sign in to comment.