mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 23:02:25 +00:00
OpenMetrics test: Add parser to check against spec
This commit is contained in:
parent
fca1482b35
commit
d04157d18a
@ -1,4 +1,5 @@
|
||||
import mock
|
||||
from prometheus_client.openmetrics import parser
|
||||
from twisted.trial import unittest
|
||||
from allmydata.web.status import Statistics
|
||||
|
||||
@ -8,18 +9,21 @@ class FakeStatsProvider(object):
|
||||
return stats
|
||||
|
||||
class OpenMetrics(unittest.TestCase):
|
||||
def test_header(self):
|
||||
def test_spec_compliance(self):
|
||||
"""
|
||||
Does our output adhere to the OpenMetrics spec?
|
||||
https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md
|
||||
"""
|
||||
req = mock.Mock()
|
||||
stats = mock.Mock()
|
||||
stats._provider = FakeStatsProvider()
|
||||
metrics = Statistics.render_OPENMETRICS(stats, req)
|
||||
|
||||
# "The content type MUST be..."
|
||||
req.setHeader.assert_called_with("content-type", "application/openmetrics-text; version=1.0.0; charset=utf-8")
|
||||
|
||||
def test_spec_compliance(self):
|
||||
req = mock.Mock()
|
||||
stats = mock.Mock()
|
||||
stats._provider = FakeStatsProvider()
|
||||
metrics = Statistics.render_OPENMETRICS(stats, req)
|
||||
# TODO test that output adheres to spec
|
||||
# The parser throws if it can't parse.
|
||||
# Wrap in a list() to drain the generator.
|
||||
families = list(parser.text_string_to_metric_families(metrics))
|
||||
# TODO add more realistic stats, incl. missing (None) values
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user