コード例 #1
0
    def test_generate_every_type_of_field(self):
        counter = metrics.CounterMetric('counter', 'desc', [
            metrics.IntegerField('a'),
            metrics.BooleanField('b'),
            metrics.StringField('c'),
        ])
        interface.register(counter)
        counter.increment({'a': 1, 'b': True, 'c': 'test'})

        proto = list(interface._generate_proto())[0]
        data_set = proto.metrics_collection[0].metrics_data_set[0]

        field_type = metrics_pb2.MetricsDataSet.MetricFieldDescriptor
        self.assertEqual('a', data_set.field_descriptor[0].name)
        self.assertEqual(field_type.INT64,
                         data_set.field_descriptor[0].field_type)

        self.assertEqual('b', data_set.field_descriptor[1].name)
        self.assertEqual(field_type.BOOL,
                         data_set.field_descriptor[1].field_type)

        self.assertEqual('c', data_set.field_descriptor[2].name)
        self.assertEqual(field_type.STRING,
                         data_set.field_descriptor[2].field_type)

        self.assertEqual(1, data_set.data[0].int64_value)

        self.assertEqual('a', data_set.data[0].field[0].name)
        self.assertEqual(1, data_set.data[0].field[0].int64_value)

        self.assertEqual('b', data_set.data[0].field[1].name)
        self.assertTrue(data_set.data[0].field[1].bool_value)

        self.assertEqual('c', data_set.data[0].field[2].name)
        self.assertEqual('test', data_set.data[0].field[2].string_value)
コード例 #2
0
ファイル: metrics_test.py プロジェクト: xinghun61/infra
 def test_boolean_field(self):
     f = metrics.BooleanField('name')
     with self.assertRaises(errors.MonitoringInvalidFieldTypeError):
         f.validate_value('', 'string')
     with self.assertRaises(errors.MonitoringInvalidFieldTypeError):
         f.validate_value('', u'string')
     with self.assertRaises(errors.MonitoringInvalidFieldTypeError):
         f.validate_value('', 123)
     with self.assertRaises(errors.MonitoringInvalidFieldTypeError):
         f.validate_value('', long(123))
     f.validate_value('', True)
     with self.assertRaises(errors.MonitoringInvalidFieldTypeError):
         f.validate_value('', None)
     with self.assertRaises(errors.MonitoringInvalidFieldTypeError):
         f.validate_value('', 12.34)
コード例 #3
0
ファイル: metrics_test.py プロジェクト: xinghun61/infra
    def test_populate_fields(self):
        data = metrics_pb2.MetricsData()
        m = metrics.Metric('test', 'test', [
            metrics.IntegerField('a'),
            metrics.BooleanField('b'),
            metrics.StringField('c'),
        ])
        m._populate_fields(data, (1, True, 'test'))

        self.assertEqual(3, len(data.field))

        self.assertEqual('a', data.field[0].name)
        self.assertEqual(1, data.field[0].int64_value)

        self.assertEqual('b', data.field[1].name)
        self.assertTrue(data.field[1].bool_value)

        self.assertEqual('c', data.field[2].name)
        self.assertEqual('test', data.field[2].string_value)
コード例 #4
0
ファイル: metrics_test.py プロジェクト: xinghun61/infra
    def test_populate_field_descriptors(self):
        data_set_pb = metrics_pb2.MetricsDataSet()
        m = metrics.Metric('test', 'test', [
            metrics.IntegerField('a'),
            metrics.BooleanField('b'),
            metrics.StringField('c'),
        ])
        m._populate_field_descriptors(data_set_pb)

        field_type = metrics_pb2.MetricsDataSet.MetricFieldDescriptor
        self.assertEqual(3, len(data_set_pb.field_descriptor))

        self.assertEqual('a', data_set_pb.field_descriptor[0].name)
        self.assertEqual(field_type.INT64,
                         data_set_pb.field_descriptor[0].field_type)

        self.assertEqual('b', data_set_pb.field_descriptor[1].name)
        self.assertEqual(field_type.BOOL,
                         data_set_pb.field_descriptor[1].field_type)

        self.assertEqual('c', data_set_pb.field_descriptor[2].name)
        self.assertEqual(field_type.STRING,
                         data_set_pb.field_descriptor[2].field_type)
コード例 #5
0
ファイル: http_metrics.py プロジェクト: xincun/yxbase
        metrics.StringField('client'),
    ])
response_status = metrics.CounterMetric(
    'http/response_status',
    'Number of responses received by HTTP status code.', [
        metrics.IntegerField('status'),
        metrics.StringField('name'),
        metrics.StringField('client'),
    ])

server_request_bytes = metrics.CumulativeDistributionMetric(
    'http/server_request_bytes',
    'Bytes received per http request (body only).', [
        metrics.IntegerField('status'),
        metrics.StringField('name'),
        metrics.BooleanField('is_robot'),
    ])
server_response_bytes = metrics.CumulativeDistributionMetric(
    'http/server_response_bytes',
    'Bytes sent per http request (content only).', [
        metrics.IntegerField('status'),
        metrics.StringField('name'),
        metrics.BooleanField('is_robot'),
    ])
server_durations = metrics.CumulativeDistributionMetric(
    'http/server_durations',
    'Time elapsed between receiving a request and sending a'
    ' response (including parsing) in milliseconds.', [
        metrics.IntegerField('status'),
        metrics.StringField('name'),
        metrics.BooleanField('is_robot'),