Commit 1b7dccd7 authored by John Gerlock's avatar John Gerlock

Adjust timout logging

parent 0e85fbe1
......@@ -9,7 +9,6 @@ import structlog
from funcy.decorators import decorator
from sanic import response
from sanic.exceptions import RequestTimeout
from sanic.exceptions import ServiceUnavailable
from sanic.exceptions import SanicException
from .typedefs import HTTPRequest
......@@ -17,7 +16,6 @@ from .typedefs import HTTPResponse
from .typedefs import JrpcRequest
from .typedefs import JrpcResponse
from .typedefs import WebApp
from .async_stats import fmt_timings
logger = structlog.get_logger(__name__)
......@@ -35,8 +33,8 @@ def setup_error_handlers(app: WebApp) -> WebApp:
# pylint: disable=unused-variable
def handle_request_timeout_errors(request: HTTPRequest,
exception: SanicException) -> Optional[
def handle_timeout_errors(request: HTTPRequest,
exception: SanicException) -> Optional[
"""handles noisy request timeout errors"""
# pylint: disable=unused-argument
......@@ -44,16 +42,6 @@ def setup_error_handlers(app: WebApp) -> WebApp:
return None
return RequestTimeoutError(http_request=request).to_sanic_response()
def handle_response_timeout_errors(request: HTTPRequest,
exception: SanicException) -> Optional[
"""handles noisy request timeout errors"""
# pylint: disable=unused-argument
if not request:
return None
return ResponseTimeoutError(http_request=request).to_sanic_response()
def handle_asyncio_timeout_errors(request: HTTPRequest,
exception: SanicException) -> Optional[
......@@ -210,30 +198,6 @@ class JussiInteralError(Exception):
return base_error
def timings(self) -> Optional[dict]:
if self.http_request.is_single_jrpc:
request_timings = fmt_timings(self.http_request.timings)
jsonrpc_timings = fmt_timings(self.http_request.jsonrpc.timings)
return {
'request_timings': request_timings,
'jsonrpc_timings': jsonrpc_timings
elif self.http_request.is_batch_jrpc:
request_timings = fmt_timings(self.http_request.timings)
jsonrpc_timings = []
for r in self.http_request.jsonrpc:
return {
'request_timings': request_timings,
'jsonrpc_timings': jsonrpc_timings
return None
except Exception as e:
return None
def log(self) -> None:
if self.log_traceback and self.exception:
self.logger.error(self.format_message(), **self.to_dict(),
......@@ -295,21 +259,6 @@ class RequestTimeoutError(JsonRpcError):
code = 1000
message = 'Request Timeout'
def to_dict(self):
data = super().to_dict()
timings = self.timings()
if timings:
except Exception as e:'error adding timing data to RequestTimeoutError', e=e)
return data
class ResponseTimeoutError(JsonRpcError):
code = 1050
message = 'Response Timeout'
class UpstreamResponseError(JsonRpcError):
code = 1100
# -*- coding: utf-8 -*-
import asyncio
from time import perf_counter
import structlog
# pylint: disable=no-name-in-module
from websockets import WebSocketClientProtocol as WSConn
......@@ -266,26 +264,17 @@ class Pool:
async def _get_new_connection(self) -> WSConn:
# First connection attempt on this pool.
logger.debug('spawning new ws conn')
start = perf_counter()
conn = await websockets_connect(self._connect_url, loop=self._loop,
return await websockets_connect(self._connect_url, loop=self._loop,
elapsed = perf_counter() - start'new ws conn', elapsed=elapsed)
return conn
async def acquire(self, timeout: int=None) -> PoolConnectionProxy:
async def _acquire_impl(timeout=None) -> PoolConnectionProxy:
start = perf_counter()
ch = await self._queue.get() # type: PoolConnectionHolder
proxy = await ch.acquire() # type: # type: PoolConnectionProxy
elapsed = perf_counter() - start
if elapsed > 1:'acquire ws conn', elapsed=elapsed)
except Exception:
# Record the timeout, as we will apply it by default
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment