Exemplo n.º 1
0
class HttpProtocol(Protocol):
    def __init__(self):
        self.properties_sent = False
        self.service_management = HttpServiceManagementClient()
        self.traces_reporter = HttpTraceSegmentReportService()

    def heartbeat(self):
        if not self.properties_sent:
            self.service_management.send_instance_props()
            self.properties_sent = True
        self.service_management.send_heart_beat()

    def connected(self):
        return True

    def report(self, queue: Queue):
        def generator():
            while True:
                segment = queue.get()  # type: Segment

                logger.debug('reporting segment %s', segment)

                yield segment

                queue.task_done()

        self.traces_reporter.report(generator=generator())
Exemplo n.º 2
0
class HttpProtocol(Protocol):
    def __init__(self):
        self.properties_sent = False
        self.service_management = HttpServiceManagementClient()
        self.traces_reporter = HttpTraceSegmentReportService()

    def fork_after_in_child(self):
        self.service_management.fork_after_in_child()
        self.traces_reporter.fork_after_in_child()

    def connected(self):
        return True

    def heartbeat(self):
        if not self.properties_sent:
            self.service_management.send_instance_props()
            self.properties_sent = True
        self.service_management.send_heart_beat()

    def report(self, queue: Queue, block: bool = True):
        start = time()

        def generator():
            while True:
                try:
                    timeout = max(0, config.QUEUE_TIMEOUT -
                                  int(time() - start))  # type: int
                    segment = queue.get(block=block,
                                        timeout=timeout)  # type: Segment
                except Empty:
                    return

                logger.debug('reporting segment %s', segment)

                yield segment

                queue.task_done()

        try:
            self.traces_reporter.report(generator=generator())
        except Exception:
            pass
Exemplo n.º 3
0
 def __init__(self):
     self.properties_sent = False
     self.service_management = HttpServiceManagementClient()
     self.traces_reporter = HttpTraceSegmentReportService()