Esempio n. 1
0
async def index(request: Request) -> JSONResponse:
    with incoming_trace("next-count", request, tracer) as span:
        return JSONResponse({
            'svc': 'service2',
            'version': '3',
            'last': next(counter)
        })
Esempio n. 2
0
async def index(request: Request) -> JSONResponse:
    with incoming_trace("fetch-counter", request, tracer) as span:
        count = next(counter)
        app.counter_gauge.set({"path": request.url.path}, count)

        return JSONResponse({
            'svc': 'service1',
            'version': '1',
            'timestamp': time.time(),
            'count': count
        })
Esempio n. 3
0
async def index(request: Request) -> JSONResponse:
    with incoming_trace("fetch-counter", request, tracer) as span:
        with outgoing_trace("next-count", request, tracer, span) as out:
            outgoing_span, ougoing_headers = out

            counter_breaker = CircuitBreaker(
                fail_max=3, timeout_duration=timedelta(seconds=30))
            counter = await counter_breaker.call_async(requests.get,
                                                       'http://service2:8000/',
                                                       timeout=1,
                                                       headers=ougoing_headers)
            data = counter.json()

            count = data['last']
            app.counter_gauge.set({"path": request.url.path}, count)

            return JSONResponse({
                'svc': 'service1',
                'version': '3',
                'timestamp': time.time(),
                'count': count
            })