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

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

Issue 1720323002: Update metrics.proto, and set metric descriptions in MetricsData messages (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Undo the go link change Created 4 years, 10 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 textwrap 6 import textwrap
7 import unittest 7 import unittest
8 8
9 import mock 9 import mock
10 from infra_libs.ts_mon.protos import metrics_pb2 10 from infra_libs.ts_mon.protos import metrics_pb2
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 self.assertEquals(len(e.exception.fields), 8) 46 self.assertEquals(len(e.exception.fields), 8)
47 47
48 def test_serialize(self): 48 def test_serialize(self):
49 t = targets.DeviceTarget('reg', 'role', 'net', 'host') 49 t = targets.DeviceTarget('reg', 'role', 'net', 'host')
50 m = metrics.StringMetric('test') 50 m = metrics.StringMetric('test')
51 m.set('val') 51 m.set('val')
52 p = metrics_pb2.MetricsCollection() 52 p = metrics_pb2.MetricsCollection()
53 m.serialize_to(p, 1234, (('bar', 1), ('baz', False)), m.get(), t) 53 m.serialize_to(p, 1234, (('bar', 1), ('baz', False)), m.get(), t)
54 return str(p).splitlines() 54 return str(p).splitlines()
55 55
56 def test_serialize_with_description(self):
57 t = targets.DeviceTarget('reg', 'role', 'net', 'host')
58 m = metrics.StringMetric('test', description='a custom description')
59 m.set('val')
60 p = metrics_pb2.MetricsCollection()
61 m.serialize_to(p, 1234, (('bar', 1), ('baz', False)), m.get(), t)
62 return str(p).splitlines()
63
56 def test_serialize_too_many_fields(self): 64 def test_serialize_too_many_fields(self):
57 m = metrics.StringMetric('test', fields={'a': 1, 'b': 2, 'c': 3, 'd': 4}) 65 m = metrics.StringMetric('test', fields={'a': 1, 'b': 2, 'c': 3, 'd': 4})
58 m.set('val', fields={'e': 5, 'f': 6, 'g': 7}) 66 m.set('val', fields={'e': 5, 'f': 6, 'g': 7})
59 with self.assertRaises(errors.MonitoringTooManyFieldsError): 67 with self.assertRaises(errors.MonitoringTooManyFieldsError):
60 m.set('val', fields={'e': 5, 'f': 6, 'g': 7, 'h': 8}) 68 m.set('val', fields={'e': 5, 'f': 6, 'g': 7, 'h': 8})
61 69
62 def test_populate_field_values(self): 70 def test_populate_field_values(self):
63 pb1 = metrics_pb2.MetricsData() 71 pb1 = metrics_pb2.MetricsData()
64 m1 = metrics.Metric('foo', fields={'asdf': 1}) 72 m1 = metrics.Metric('foo', fields={'asdf': 1})
65 m1._populate_fields(pb1, m1._normalized_fields) 73 m1._populate_fields(pb1, m1._normalized_fields)
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 m.add(25) 505 m.add(25)
498 p = metrics_pb2.MetricsCollection() 506 p = metrics_pb2.MetricsCollection()
499 m.serialize_to(p, 1234, (), m.get(), t) 507 m.serialize_to(p, 1234, (), m.get(), t)
500 self.assertEquals(1234000000, p.data[0].start_timestamp_us) 508 self.assertEquals(1234000000, p.data[0].start_timestamp_us)
501 509
502 def test_is_cumulative(self): 510 def test_is_cumulative(self):
503 cd = metrics.CumulativeDistributionMetric('test') 511 cd = metrics.CumulativeDistributionMetric('test')
504 ncd = metrics.NonCumulativeDistributionMetric('test2') 512 ncd = metrics.NonCumulativeDistributionMetric('test2')
505 self.assertTrue(cd.is_cumulative()) 513 self.assertTrue(cd.is_cumulative())
506 self.assertFalse(ncd.is_cumulative()) 514 self.assertFalse(ncd.is_cumulative())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698