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
2 changes: 1 addition & 1 deletion prometheus_client/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Timestamp(object):

def __init__(self, sec, nsec):
if nsec < 0 or nsec >= 1e9:
raise ValueError("Invalid value for nanoseconds in Timestamp: {}".format(nsec))
raise ValueError("Invalid value for nanoseconds in Timestamp: {0}".format(nsec))
if sec < 0:
nsec = -nsec
self.sec = int(sec)
Expand Down
4 changes: 2 additions & 2 deletions prometheus_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def floatToGoString(d):
# Go switches to exponents sooner than Python.
# We only need to care about positive values for le/quantile.
if d > 0 and dot > 6:
mantissa = '{}.{}{}'.format(s[0], s[1:dot], s[dot+1:]).rstrip('0.')
return '{}e+0{}'.format(mantissa, dot-1)
mantissa = '{0}.{1}{2}'.format(s[0], s[1:dot], s[dot+1:]).rstrip('0.')
return '{0}e+0{1}'.format(mantissa, dot-1)
return s
12 changes: 10 additions & 2 deletions tests/openmetrics/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,6 @@ def test_invalid_input(self):
('# TYPE a histogram\na_count 1\na_bucket{le="+Inf"} 0\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="+Inf"} 0\na_count 1\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="1"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="9.999999999999999e+22"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="1.5555555555555201e+06"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="1e-04"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="1e+05"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="+INF"} 0\n# EOF\n'),
Expand All @@ -590,6 +588,16 @@ def test_invalid_input(self):
with self.assertRaises(ValueError):
list(text_string_to_metric_families(case))

@unittest.skipIf(sys.version_info < (2, 7), "float repr changed from 2.6 to 2.7")
def test_invalid_float_input(self):
for case in [
# Bad histograms.
('# TYPE a histogram\na_bucket{le="9.999999999999999e+22"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="1.5555555555555201e+06"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
]:
with self.assertRaises(ValueError):
list(text_string_to_metric_families(case))


if __name__ == '__main__':
unittest.main()