mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-11 23:42:38 +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
|
import mock
|
||||||
|
from prometheus_client.openmetrics import parser
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from allmydata.web.status import Statistics
|
from allmydata.web.status import Statistics
|
||||||
|
|
||||||
@ -8,18 +9,21 @@ class FakeStatsProvider(object):
|
|||||||
return stats
|
return stats
|
||||||
|
|
||||||
class OpenMetrics(unittest.TestCase):
|
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()
|
req = mock.Mock()
|
||||||
stats = mock.Mock()
|
stats = mock.Mock()
|
||||||
stats._provider = FakeStatsProvider()
|
stats._provider = FakeStatsProvider()
|
||||||
metrics = Statistics.render_OPENMETRICS(stats, req)
|
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")
|
req.setHeader.assert_called_with("content-type", "application/openmetrics-text; version=1.0.0; charset=utf-8")
|
||||||
|
|
||||||
def test_spec_compliance(self):
|
# The parser throws if it can't parse.
|
||||||
req = mock.Mock()
|
# Wrap in a list() to drain the generator.
|
||||||
stats = mock.Mock()
|
families = list(parser.text_string_to_metric_families(metrics))
|
||||||
stats._provider = FakeStatsProvider()
|
|
||||||
metrics = Statistics.render_OPENMETRICS(stats, req)
|
|
||||||
# TODO test that output adheres to spec
|
|
||||||
# TODO add more realistic stats, incl. missing (None) values
|
# TODO add more realistic stats, incl. missing (None) values
|
||||||
|
|
||||||
|
2
tox.ini
2
tox.ini
@ -52,6 +52,8 @@ deps =
|
|||||||
certifi
|
certifi
|
||||||
# VCS hooks support
|
# VCS hooks support
|
||||||
py36,!coverage: pre-commit
|
py36,!coverage: pre-commit
|
||||||
|
# Does our OpenMetrics endpoint adhere to the spec:
|
||||||
|
prometheus-client==0.11.0
|
||||||
|
|
||||||
# We add usedevelop=False because testing against a true installation gives
|
# We add usedevelop=False because testing against a true installation gives
|
||||||
# more useful results.
|
# more useful results.
|
||||||
|
Loading…
Reference in New Issue
Block a user