Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: infra_libs/ts_mon/common/test/metrics_test.py

Issue 2111473003: Issue 623854: Support unit annotations in ts_mon metrics (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Update sysmon to pass units for metrics and renamed MetricDataUnit to MetricsDataUnits Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()
Sergey Berezin 2016/06/30 19:21:26 It seems you're missing the new expectations file
ddoman 2016/07/06 03:35:37 Done.
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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 m.add(25) 515 m.add(25)
507 p = metrics_pb2.MetricsCollection() 516 p = metrics_pb2.MetricsCollection()
508 m.serialize_to(p, 1234, (), m.get(), t) 517 m.serialize_to(p, 1234, (), m.get(), t)
509 self.assertEquals(1234000000, p.data[0].start_timestamp_us) 518 self.assertEquals(1234000000, p.data[0].start_timestamp_us)
510 519
511 def test_is_cumulative(self): 520 def test_is_cumulative(self):
512 cd = metrics.CumulativeDistributionMetric('test') 521 cd = metrics.CumulativeDistributionMetric('test')
513 ncd = metrics.NonCumulativeDistributionMetric('test2') 522 ncd = metrics.NonCumulativeDistributionMetric('test2')
514 self.assertTrue(cd.is_cumulative()) 523 self.assertTrue(cd.is_cumulative())
515 self.assertFalse(ncd.is_cumulative()) 524 self.assertFalse(ncd.is_cumulative())
OLDNEW
« infra_libs/ts_mon/common/metrics.py ('K') | « infra_libs/ts_mon/common/metrics.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698