Ejemplo n.º 1
0
    class SpanHelper(object):
        def __init__(self, span_addr, appid, appname, starttime,
                     max_pending_sz):
            self.agent_meta = [('starttime', str(starttime)),
                               ('agentid', appid),
                               ('applicationname', appname)]
            self.agent_id = appid
            self.agent_name = appname
            self.span_addr = span_addr
            self.max_pending_sz = max_pending_sz
            self.span_queue = Queue(self.max_pending_sz)
            self.span_client = GrpcSpan(self.span_addr, self.agent_meta,
                                        self.span_queue)
            self.dropped_span_count = 0

        def start(self):
            self.span_client.start()

        def sendSpan(self, spanMesg):

            try:
                self.span_queue.put(spanMesg, False)
            except Full as e:
                self.dropped_span_count += 1
                TCLogger.warning("span send queue is full")
                return False
            except Exception as e:
                TCLogger.error("send span failed: %s", e)
                return False
            return True

        def stop(self):
            self.span_client.stop()
            TCLogger.info("grpc agent dropped %d", self.dropped_span_count)
Ejemplo n.º 2
0
    def test_sendspan(self):

        queue = Queue()
        spanclient = GrpcSpan('localhost:9993', self.agent_meta, queue)
        spanclient.start()
        i = 100
        while i > 0:
            queue.put(self._generate_span())
            i -= 1
        time.sleep(1)
        spanclient.stop()
        self.assertGreaterEqual(self.spanStat.count, 100)