Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions prometheus_client/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _parse_sample(text):
value.append(char)
state = 'value'
elif state == 'startoflabelname':
if char == ' ' or char == '\t':
if char == ' ' or char == '\t' or char == ',':
pass
elif char == '}':
state = 'endoflabels'
Expand Down Expand Up @@ -121,7 +121,7 @@ def _parse_sample(text):
labelvalue.append('\\' + char)
elif state == 'nextlabel':
if char == ',':
state = 'labelname'
state = 'startoflabelname'
elif char == '}':
state = 'endoflabels'
elif char == ' ' or char == '\t':
Expand Down
20 changes: 20 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ def test_spaces(self):
metric_family.add_metric(["baz"], 2)
self.assertEqual([metric_family], list(families))

def test_commas(self):
families = text_string_to_metric_families("""# TYPE a counter
# HELP a help
a{foo="bar",} 1
# TYPE b counter
# HELP b help
b{,} 2
""")
a = CounterMetricFamily("a", "help", labels=["foo"])
a.add_metric(["bar"], 1)
b = CounterMetricFamily("b", "help", value=2)
self.assertEqual([a, b], list(families))

def test_empty_brackets(self):
families = text_string_to_metric_families("""# TYPE a counter
# HELP a help
a{} 1
""")
self.assertEqual([CounterMetricFamily("a", "help", value=1)], list(families))

def test_nan(self):
families = text_string_to_metric_families("""a NaN
""")
Expand Down