def test_server(port=pb2.PYTHON_HTTP_TRACECONTEXT_PROPAGATION_PORT): """Send a single multi-hop request to the server and shut it down.""" test_request = pb2.TestRequest( name="python:http:tracecontext", service_hops=[ pb2.ServiceHop( service=pb2.Service( name="python:http:tracecontext", port=port, host="0.0.0.0", spec=pb2.Spec( transport=pb2.Spec.HTTP, propagation=pb2.Spec. TRACE_CONTEXT_FORMAT_PROPAGATION))), pb2.ServiceHop( service=pb2.Service( name="python:http:tracecontext", port=port, host="0.0.0.0", spec=pb2.Spec( transport=pb2.Spec.HTTP, propagation=pb2.Spec. TRACE_CONTEXT_FORMAT_PROPAGATION))) ]) with serve_http_tracecontext(): return service.call_http_tracecontext("0.0.0.0", port, test_request)
def test_server(port=pb2.PYTHON_GRPC_BINARY_PROPAGATION_PORT): """Send a single multi-hop request to the server and shut it down.""" test_request = pb2.TestRequest( name="python:grpc:binary", service_hops=[ pb2.ServiceHop( service=pb2.Service( name="python:grpc:binary", port=port, host="0.0.0.0", spec=pb2.Spec( transport=pb2.Spec.GRPC, propagation=pb2.Spec.BINARY_FORMAT_PROPAGATION))), pb2.ServiceHop( service=pb2.Service( name="python:grpc:binary", port=port, host="0.0.0.0", spec=pb2.Spec( transport=pb2.Spec.GRPC, propagation=pb2.Spec.BINARY_FORMAT_PROPAGATION))) ]) with serve_grpc_binary(): return service.call_grpc_binary("0.0.0.0", port, test_request)
def build_service_hop(hop): return pb2.ServiceHop(service=pb2.Service(name=get_name(hop), port=hop.port, host=hop.host, spec=pb2.Spec( transport=hop.transport, propagation=hop.prop, )))
def register(host="0.0.0.0", port=pb2.PYTHON_GRPC_BINARY_PROPAGATION_PORT): """Register the server at host:port with the test registration service.""" request = pb2.RegistrationRequest( server_name='python', services=[ pb2.Service(name='python', port=port, host=host, spec=pb2.Spec( transport=pb2.Spec.GRPC, propagation=pb2.Spec.BINARY_FORMAT_PROPAGATION)) ]) client = pb2_grpc.RegistrationServiceStub(channel=grpc.insecure_channel( '{}:{}'.format(service.REGISTRATION_SERVER_HOST, service.REGISTRATION_SERVER_PORT))) return client.register(request)
def register(port=pb2.PYTHON_HTTP_TRACECONTEXT_PROPAGATION_PORT): """Register the server at host:port with the test registration service.""" request = pb2.RegistrationRequest( server_name='python', services=[ pb2.Service( name='python', port=port, host=flask.request.environ.get('SERVER_NAME'), spec=pb2.Spec( transport=pb2.Spec.HTTP, propagation=pb2.Spec.TRACE_CONTEXT_FORMAT_PROPAGATION), )]) client = pb2_grpc.RegistrationServiceStub( channel=grpc.insecure_channel( '{}:{}'.format(service.REGISTRATION_SERVER_HOST, service.REGISTRATION_SERVER_PORT)) ) try: return client.register(request) except grpc.RpcError as ex: logger.info("Registration server call failed with exception: %s", ex) return "Failed to register"