OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import sys | 5 import sys |
6 import unittest | 6 import unittest |
7 | 7 |
8 import mock | 8 import mock |
9 from infra_libs.ts_mon.protos import metrics_pb2 | 9 from infra_libs.ts_mon.protos import metrics_pb2 |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return str(p).splitlines() | 55 return str(p).splitlines() |
56 | 56 |
57 def test_serialize_with_description(self): | 57 def test_serialize_with_description(self): |
58 t = targets.DeviceTarget('reg', 'role', 'net', 'host') | 58 t = targets.DeviceTarget('reg', 'role', 'net', 'host') |
59 m = metrics.StringMetric('test', description='a custom description') | 59 m = metrics.StringMetric('test', description='a custom description') |
60 m.set('val') | 60 m.set('val') |
61 p = metrics_pb2.MetricsCollection() | 61 p = metrics_pb2.MetricsCollection() |
62 m.serialize_to(p, 1234, (('bar', 1), ('baz', False)), m.get(), t) | 62 m.serialize_to(p, 1234, (('bar', 1), ('baz', False)), m.get(), t) |
63 return str(p).splitlines() | 63 return str(p).splitlines() |
64 | 64 |
| 65 def test_serialize_with_units(self): |
| 66 t = targets.DeviceTarget('reg', 'role', 'net', 'host') |
| 67 m = metrics.GaugeMetric('test', units=metrics.MetricsDataUnits.SECONDS) |
| 68 m.set(1) |
| 69 p = metrics_pb2.MetricsCollection() |
| 70 m.serialize_to(p, 1234, (('bar', 1), ('baz', False)), m.get(), t) |
| 71 self.assertEquals(p.data[0].units, metrics.MetricsDataUnits.SECONDS) |
| 72 return str(p).splitlines() |
| 73 |
65 def test_serialize_too_many_fields(self): | 74 def test_serialize_too_many_fields(self): |
66 m = metrics.StringMetric('test', fields={'a': 1, 'b': 2, 'c': 3, 'd': 4}) | 75 m = metrics.StringMetric('test', fields={'a': 1, 'b': 2, 'c': 3, 'd': 4}) |
67 m.set('val', fields={'e': 5, 'f': 6, 'g': 7}) | 76 m.set('val', fields={'e': 5, 'f': 6, 'g': 7}) |
68 with self.assertRaises(errors.MonitoringTooManyFieldsError): | 77 with self.assertRaises(errors.MonitoringTooManyFieldsError): |
69 m.set('val', fields={'e': 5, 'f': 6, 'g': 7, 'h': 8}) | 78 m.set('val', fields={'e': 5, 'f': 6, 'g': 7, 'h': 8}) |
70 | 79 |
71 def test_populate_field_values(self): | 80 def test_populate_field_values(self): |
72 pb1 = metrics_pb2.MetricsData() | 81 pb1 = metrics_pb2.MetricsData() |
73 m1 = metrics.Metric('foo', fields={'asdf': 1}) | 82 m1 = metrics.Metric('foo', fields={'asdf': 1}) |
74 m1._populate_fields(pb1, m1._normalized_fields) | 83 m1._populate_fields(pb1, m1._normalized_fields) |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 m.add(25) | 526 m.add(25) |
518 p = metrics_pb2.MetricsCollection() | 527 p = metrics_pb2.MetricsCollection() |
519 m.serialize_to(p, 1234, (), m.get(), t) | 528 m.serialize_to(p, 1234, (), m.get(), t) |
520 self.assertEquals(1234000000, p.data[0].start_timestamp_us) | 529 self.assertEquals(1234000000, p.data[0].start_timestamp_us) |
521 | 530 |
522 def test_is_cumulative(self): | 531 def test_is_cumulative(self): |
523 cd = metrics.CumulativeDistributionMetric('test') | 532 cd = metrics.CumulativeDistributionMetric('test') |
524 ncd = metrics.NonCumulativeDistributionMetric('test2') | 533 ncd = metrics.NonCumulativeDistributionMetric('test2') |
525 self.assertTrue(cd.is_cumulative()) | 534 self.assertTrue(cd.is_cumulative()) |
526 self.assertFalse(ncd.is_cumulative()) | 535 self.assertFalse(ncd.is_cumulative()) |
OLD | NEW |