diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-04 19:22:14 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-12 16:24:50 +0000 |
commit | 72625f2f4d633e9fe59e61bb371a118927e5c66c (patch) | |
tree | 61bd096a6e62897622b3b2d0bba6c86da68d880f /tests/metrics | |
parent | Delete a couple of TODO markers of monitoring stats now done (diff) | |
download | synapse-72625f2f4d633e9fe59e61bb371a118927e5c66c.tar.xz |
Initial hack at a TimerMetric; for storing counts + duration accumulators
Diffstat (limited to 'tests/metrics')
-rw-r--r-- | tests/metrics/test_metric.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/metrics/test_metric.py b/tests/metrics/test_metric.py index b7facb8587..b25520821d 100644 --- a/tests/metrics/test_metric.py +++ b/tests/metrics/test_metric.py @@ -16,7 +16,7 @@ from tests import unittest from synapse.metrics.metric import ( - CounterMetric, CallbackMetric, CacheMetric + CounterMetric, CallbackMetric, TimerMetric, CacheMetric ) @@ -97,6 +97,40 @@ class CallbackMetricTestCase(unittest.TestCase): ]) +class TimerMetricTestCase(unittest.TestCase): + + def test_scalar(self): + metric = TimerMetric("thing") + + self.assertEquals(metric.render(), [ + "thing:count 0", + "thing:msec 0", + ]) + + metric.inc_time(500) + + self.assertEquals(metric.render(), [ + "thing:count 1", + "thing:msec 500", + ]) + + def test_vector(self): + metric = TimerMetric("queries", keys=["verb"]) + + self.assertEquals(metric.render(), []) + + metric.inc_time(300, "SELECT") + metric.inc_time(200, "SELECT") + metric.inc_time(800, "INSERT") + + self.assertEquals(metric.render(), [ + "queries{verb=INSERT}:count 1", + "queries{verb=INSERT}:msec 800", + "queries{verb=SELECT}:count 2", + "queries{verb=SELECT}:msec 500", + ]) + + class CacheMetricTestCase(unittest.TestCase): def test_cache(self): |