def test_convert(self): data_set = metrics_pb2.MetricsDataSet() data_set.metric_name = 'foo' data = data_set.data.add() data.bool_value = True data = data_set.data.add() data.bool_value = False data = data_set.data.add() data.int64_value = 200 data = data_set.data.add() data.double_value = 123.456 popo = pb_to_popo.convert(data_set) expected = { 'metric_name': 'foo', 'data': [ { 'bool_value': True }, { 'bool_value': False }, { 'int64_value': 200L }, { 'double_value': 123.456 }, ], } self.assertDictEqual(expected, popo)
def test_convert(self): task = acquisition_task_pb2.Task(service_name='service') network_device = acquisition_network_device_pb2.NetworkDevice( hostname='host', alertable=True) metric1 = metrics_pb2.MetricsData( name='m1', counter=200, task=task, units=metrics_pb2.MetricsData.Units.Value('SECONDS')) metric2 = metrics_pb2.MetricsData(name='m2', network_device=network_device, cumulative_double_value=123.456) collection = metrics_pb2.MetricsCollection(data=[metric1, metric2], start_timestamp_us=12345) popo = pb_to_popo.convert(collection) expected = { 'data': [{ 'name': 'm1', 'counter': 200L, 'task': { 'service_name': 'service' }, 'units': 1 }, { 'name': 'm2', 'cumulative_double_value': 123.456, 'network_device': { 'hostname': 'host', 'alertable': True } }], 'start_timestamp_us': 12345L } self.assertDictEqual(expected, popo)
def encodeToJson(self, metric_pb): if interface.state.use_new_proto: return json.dumps({'payload': pb_to_popo.convert(metric_pb)}) else: return json.dumps({'resource': pb_to_popo.convert(metric_pb)})
def encode_to_json(self, metric_pb): return json.dumps({'payload': pb_to_popo.convert(metric_pb)})
def encodeToJson(self, metric_pb): return json.dumps({'resource': pb_to_popo.convert(metric_pb)})
def message(self, pb): return json.dumps({'payload': pb_to_popo.convert(pb)})
def message(self, pb): pb = monitors.Monitor._wrap_proto(pb) return json.dumps({'resource': pb_to_popo.convert(pb)})