我正在尝试为“摘要”编写单元测试。但不确定我需要检查哪些变量?
from prometheus_client import Counter, Summary
import unittest
import time
from prometheus_client import REGISTRY
my_summary = Summary('my_summary', 'A useful help string.')
def my_function():
time.sleep(1)
my_summary.observe(5)
class TestMyFunction(unittest.TestCase):
def test_metric_incremented(self):
print 'here'
before = REGISTRY.get_sample_value('my_summary')
print 'summary before == ', before
my_function()
after = REGISTRY.get_sample_value('my_summary')
print 'summary after == ', after
self.assertEqual(0, after - before)
if __name__ == '__main__':
unittest.main()
这是我的代码我观察功能5秒。不确定这是否是正确的方法。任何测试示例都会很棒。
我尝试关注此博客 - https://www.robustperception.io/how-to-unit-test-prometheus-instrumentation/
答案 0 :(得分:1)
您想要的时间序列为2.45.0
和my_summary_count
。