def test__convert_from_thrift_binary_annotations(self): decoder = _V1ThriftDecoder() local_host = thrift.create_endpoint(8888, "test_service", "10.0.0.1", None) remote_host = thrift.create_endpoint(9999, "rem_service", "10.0.0.2", None) ann_type = zipkin_core.AnnotationType thrift_binary_annotations = [ create_binary_annotation("key1", True, ann_type.BOOL, local_host), create_binary_annotation("key2", "val2", ann_type.STRING, local_host), create_binary_annotation("key3", False, ann_type.BOOL, local_host), create_binary_annotation("key4", b"04", ann_type.I16, local_host), create_binary_annotation("key5", b"0004", ann_type.I32, local_host), create_binary_annotation("sa", True, ann_type.BOOL, remote_host), ] ( tags, local_endpoint, remote_endpoint, ) = decoder._convert_from_thrift_binary_annotations(thrift_binary_annotations) assert tags == { "key1": "true", "key2": "val2", "key3": "false", } assert local_endpoint == Endpoint("test_service", "10.0.0.1", None, 8888) assert remote_endpoint == Endpoint("rem_service", "10.0.0.2", None, 9999)
def test__convert_from_thrift_binary_annotations(self): decoder = _V1ThriftDecoder() local_host = thrift.create_endpoint(8888, 'test_service', '10.0.0.1', None) remote_host = thrift.create_endpoint(9999, 'rem_service', '10.0.0.2', None) ann_type = zipkin_core.AnnotationType thrift_binary_annotations = [ create_binary_annotation('key1', True, ann_type.BOOL, local_host), create_binary_annotation('key2', 'val2', ann_type.STRING, local_host), create_binary_annotation('key3', False, ann_type.BOOL, local_host), create_binary_annotation('key4', b'04', ann_type.I16, local_host), create_binary_annotation('key5', b'0004', ann_type.I32, local_host), create_binary_annotation('sa', True, ann_type.BOOL, remote_host), ] tags, local_endpoint, remote_endpoint = \ decoder._convert_from_thrift_binary_annotations( thrift_binary_annotations, ) assert tags == { 'key1': 'true', 'key2': 'val2', 'key3': 'false', } assert local_endpoint == Endpoint('test_service', '10.0.0.1', None, 8888) assert remote_endpoint == Endpoint('rem_service', '10.0.0.2', None, 9999)
def test__convert_from_thrift_endpoint(self, thrift_endpoint): decoder = _V1ThriftDecoder() ipv4_endpoint = decoder._convert_from_thrift_endpoint(thrift_endpoint) assert ipv4_endpoint == Endpoint("test_service", "10.0.0.1", None, 8888) ipv6_thrift_endpoint = thrift.create_endpoint(8888, "test_service", None, "::1") ipv6_endpoint = decoder._convert_from_thrift_endpoint(ipv6_thrift_endpoint) assert ipv6_endpoint == Endpoint("test_service", None, "::1", 8888)
def test__convert_from_thrift_endpoint(self, thrift_endpoint): decoder = _V1ThriftDecoder() ipv4_endpoint = decoder._convert_from_thrift_endpoint(thrift_endpoint) assert ipv4_endpoint == Endpoint('test_service', '10.0.0.1', None, 8888) ipv6_thrift_endpoint = \ thrift.create_endpoint(8888, 'test_service', None, '::1') ipv6_endpoint = decoder._convert_from_thrift_endpoint( ipv6_thrift_endpoint) assert ipv6_endpoint == Endpoint('test_service', None, '::1', 8888)
def _convert_from_thrift_endpoint(self, thrift_endpoint): """Accepts a thrift decoded endpoint and converts it to an Endpoint. :param thrift_endpoint: thrift encoded endpoint :type thrift_endpoint: thrift endpoint :returns: decoded endpoint :rtype: Encoding """ ipv4 = None ipv6 = None port = struct.unpack('H', struct.pack('h', thrift_endpoint.port))[0] if thrift_endpoint.ipv4 != 0: ipv4 = socket.inet_ntop( socket.AF_INET, struct.pack('!i', thrift_endpoint.ipv4), ) if thrift_endpoint.ipv6: ipv6 = socket.inet_ntop(socket.AF_INET6, thrift_endpoint.ipv6) return Endpoint( service_name=thrift_endpoint.service_name, ipv4=ipv4, ipv6=ipv6, port=port, )
def test__convert_from_thrift_binary_annotations_unicode(self): decoder = _V1ThriftDecoder() local_host = thrift.create_endpoint(8888, 'test_service', '10.0.0.1', None) ann_type = zipkin_core.AnnotationType thrift_binary_annotations = [ create_binary_annotation('key1', u'再见', ann_type.STRING, local_host), create_binary_annotation('key2', 'val2', ann_type.STRING, local_host), create_binary_annotation('key3', '再见', ann_type.STRING, local_host), ] tags, local_endpoint, remote_endpoint = \ decoder._convert_from_thrift_binary_annotations( thrift_binary_annotations, ) assert tags == { 'key1': u'再见', 'key2': 'val2', 'key3': '再见', } assert local_endpoint == Endpoint('test_service', '10.0.0.1', None, 8888)
def fake_endpoint(): return Endpoint( service_name='test_server', ipv4='127.0.0.1', ipv6=None, port=80, )
def test__decode_thrift_annotations_server_span(self, thrift_endpoint): timestamp = 1.0 decoder = _V1ThriftDecoder() thrift_annotations = thrift.annotation_list_builder( {"sr": timestamp, "ss": timestamp + 10}, thrift_endpoint, ) annotations, end, kind, ts, dur = decoder._decode_thrift_annotations( thrift_annotations, ) assert annotations == {} assert end == Endpoint("test_service", "10.0.0.1", None, 8888) assert kind == Kind.SERVER assert ts == timestamp * USEC assert dur == 10 * USEC
def test__decode_thrift_annotations(self, thrift_endpoint): timestamp = 1.0 decoder = _V1ThriftDecoder() thrift_annotations = thrift.annotation_list_builder( {"cs": timestamp, "cr": timestamp + 10, "my_annotation": timestamp + 15}, thrift_endpoint, ) annotations, end, kind, ts, dur = decoder._decode_thrift_annotations( thrift_annotations, ) assert annotations == {"my_annotation": 16.0} assert end == Endpoint("test_service", "10.0.0.1", None, 8888) assert kind == Kind.CLIENT assert ts == timestamp * USEC assert dur == 10 * USEC
def test__decode_thrift_annotations(self, thrift_endpoint): timestamp = 1.0 decoder = _V1ThriftDecoder() thrift_annotations = thrift.annotation_list_builder( { 'cs': timestamp, 'cr': timestamp + 10, 'my_annotation': timestamp + 15, }, thrift_endpoint, ) annotations, end, kind, ts, dur = decoder._decode_thrift_annotations( thrift_annotations, ) assert annotations == {'my_annotation': 16.0} assert end == Endpoint('test_service', '10.0.0.1', None, 8888) assert kind == Kind.CLIENT assert ts == timestamp * USEC assert dur == 10 * USEC
def test__decode_thrift_annotations_local_span(self, thrift_endpoint): timestamp = 1.0 decoder = _V1ThriftDecoder() thrift_annotations = thrift.annotation_list_builder( { 'cs': timestamp, 'sr': timestamp, 'ss': timestamp + 10, 'cr': timestamp + 10, }, thrift_endpoint, ) annotations, end, kind, ts, dur = decoder._decode_thrift_annotations( thrift_annotations, ) assert annotations == {} assert end == Endpoint('test_service', '10.0.0.1', None, 8888) assert kind == Kind.LOCAL # ts and dur are not computed for a local span since those always have # timestamp and duration set as span arguments. assert ts is None assert dur is None
def test__convert_from_thrift_binary_annotations_unicode(self): decoder = _V1ThriftDecoder() local_host = thrift.create_endpoint(8888, "test_service", "10.0.0.1", None) ann_type = zipkin_core.AnnotationType thrift_binary_annotations = [ create_binary_annotation("key1", u"再见", ann_type.STRING, local_host), create_binary_annotation("key2", "val2", ann_type.STRING, local_host), create_binary_annotation("key3", "再见", ann_type.STRING, local_host), ] ( tags, local_endpoint, remote_endpoint, ) = decoder._convert_from_thrift_binary_annotations(thrift_binary_annotations) assert tags == { "key1": u"再见", "key2": "val2", "key3": "再见", } assert local_endpoint == Endpoint("test_service", "10.0.0.1", None, 8888)
def fake_endpoint(): return Endpoint(service_name="test_server", ipv4="127.0.0.1", ipv6=None, port=80)