Commit 149834e6 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

metrics: Add function to collect repeated metrics.

Bug: 897394
Change-Id: Iece4507c7bf92d7a8aad045d31b4f06e54b3af15
Reviewed-on: https://chromium-review.googlesource.com/c/1292243Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 98f1e59b
......@@ -161,6 +161,11 @@ class MetricsCollector(object):
with self._metrics_lock:
self._reported_metrics[name] = value
def add_repeated(self, name, value):
if self._collect_custom_metrics:
with self._metrics_lock:
self._reported_metrics.setdefault(name, []).append(value)
@contextlib.contextmanager
def pause_metrics_collection(self):
collect_custom_metrics = self._collect_custom_metrics
......
......@@ -574,6 +574,23 @@ class MetricsCollectorTest(unittest.TestCase):
self.config_file,
{'is-googler': True, 'countdown': 0, 'opt-in': None, 'version': 5})
def test_add_repeated(self):
"""Tests that we can add repeated metrics."""
self.FileRead.side_effect = [
'{"is-googler": true, "countdown": 0, "opt-in": true}'
]
@self.collector.collect_metrics('fun')
def fun():
self.collector.add_repeated('fun', 1)
self.collector.add_repeated('fun', 2)
self.collector.add_repeated('fun', 5)
fun()
# Assert that we collected all metrics for fun.
self.assert_collects_metrics({'fun': [1, 2, 5]})
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment