def test_rpc_handler_export_multiple_packets(self):
        requests = []

        event = threading.Event()

        def _helper(request_iterator, context):
            # Ensure a stream has not been started before accepting a request.
            if len(requests) != 0:
                return

            for request in request_iterator:
                requests.append(request)
                if len(requests) == 2:
                    event.set()
            yield

        self._add_and_start_service(GenericRpcHandler(_helper))

        r1 = metrics_service_pb2.ExportMetricsServiceRequest(
            node=common_pb2.Node(service_info=common_pb2.ServiceInfo(
                name='request1')))
        r2 = metrics_service_pb2.ExportMetricsServiceRequest(
            node=common_pb2.Node(service_info=common_pb2.ServiceInfo(
                name='request2')))

        handler = _create_rpc_handler(self._create_stub())
        handler.send(r1)
        handler.send(r2)

        self.assertTrue(event.wait(timeout=1))
        self.assertListEqual(requests, [r1, r2])
    def __init__(
            self,
            service_name,
            host_name=None,
            endpoint=None,
            client=None,
            transport=sync.SyncTransport):
        self.transport = transport(self)
        self.endpoint = DEFAULT_ENDPOINT if endpoint is None else endpoint

        if client is None:
            self.channel = grpc.insecure_channel(self.endpoint)
            self.client = trace_service_pb2_grpc.TraceServiceStub(
                channel=self.channel)
        else:
            self.client = client

        self.service_name = service_name
        self.node = common_pb2.Node(
            identifier=common_pb2.ProcessIdentifier(
                host_name=socket.gethostname() if host_name is None
                else host_name,
                pid=os.getpid(),
                start_timestamp=utils.proto_ts_from_datetime(
                    datetime.datetime.utcnow())
            ),
            library_info=common_pb2.LibraryInfo(
                language=common_pb2.LibraryInfo.Language.Value('PYTHON'),
                exporter_version=EXPORTER_VERSION,
                core_library_version=__version__
            ),
            service_info=common_pb2.ServiceInfo(name=self.service_name))
Exemple #3
0
def get_node(service_name, host_name):
    """Generates Node message from params and system information.
    """
    return common_pb2.Node(
        identifier=common_pb2.ProcessIdentifier(
            host_name=socket.gethostname() if host_name is None else host_name,
            pid=os.getpid(),
            start_timestamp=proto_ts_from_datetime(
                datetime.datetime.utcnow())),
        library_info=common_pb2.LibraryInfo(
            language=common_pb2.LibraryInfo.Language.Value('PYTHON'),
            exporter_version=EXPORTER_VERSION,
            core_library_version=opencensus_version),
        service_info=common_pb2.ServiceInfo(name=service_name))
    def test_rpc_handler_initialization(self):
        requests = []
        event = threading.Event()

        def _helper(request_iterator, context):
            for request in request_iterator:
                requests.append(request)
                event.set()
            yield

        self._add_and_start_service(GenericRpcHandler(_helper))

        request = metrics_service_pb2.ExportMetricsServiceRequest(
            node=common_pb2.Node(service_info=common_pb2.ServiceInfo(
                name='test-service')))
        _create_rpc_handler(self._create_stub()).send(request)

        self.assertTrue(event.wait(timeout=1))
        self.assertListEqual(requests, [request])
Exemple #5
0
def get_node(service_name, host_name):
    """Generates Node message from params and system information.

     Args:
        service_name: Name of Collector service.
        host_name: Host name.
    """
    return common_pb2.Node(
        identifier=common_pb2.ProcessIdentifier(
            host_name=socket.gethostname() if host_name is None else host_name,
            pid=os.getpid(),
            start_timestamp=proto_timestamp_from_time_ns(int(time.time() *
                                                             1e9)),
        ),
        library_info=common_pb2.LibraryInfo(
            language=common_pb2.LibraryInfo.Language.Value("PYTHON"),
            exporter_version=otcollector_exporter_version,
            core_library_version=OPENTELEMETRY_VERSION,
        ),
        service_info=common_pb2.ServiceInfo(name=service_name),
    )