From b0851c065225930d2eb55eba72b2d66d89b218b3 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Sun, 4 Dec 2022 01:15:28 -0500 Subject: [PATCH] remove http_debug --- relay/application.py | 3 -- relay/http_debug.py | 68 -------------------------------------------- relay/misc.py | 2 -- relay/views.py | 6 ---- 4 files changed, 79 deletions(-) delete mode 100644 relay/http_debug.py diff --git a/relay/application.py b/relay/application.py index b339672..498fdd9 100644 --- a/relay/application.py +++ b/relay/application.py @@ -102,9 +102,6 @@ class Application(web.Application): return logging.error(f'A server is already running on port {self.config.port}') for route in routes: - if route[1] == '/stats' and logging.DEBUG < logging.root.level: - continue - self.router.add_route(*route) logging.info(f'Starting webserver at {self.config.host} ({self.config.listen}:{self.config.port})') diff --git a/relay/http_debug.py b/relay/http_debug.py deleted file mode 100644 index 2a2ae67..0000000 --- a/relay/http_debug.py +++ /dev/null @@ -1,68 +0,0 @@ -import logging -import aiohttp - -from collections import defaultdict - - -STATS = { - 'requests': defaultdict(int), - 'response_codes': defaultdict(int), - 'response_codes_per_domain': defaultdict(lambda: defaultdict(int)), - 'delivery_codes': defaultdict(int), - 'delivery_codes_per_domain': defaultdict(lambda: defaultdict(int)), - 'exceptions': defaultdict(int), - 'exceptions_per_domain': defaultdict(lambda: defaultdict(int)), - 'delivery_exceptions': defaultdict(int), - 'delivery_exceptions_per_domain': defaultdict(lambda: defaultdict(int)) -} - - -async def on_request_start(session, trace_config_ctx, params): - global STATS - - logging.debug("HTTP START [%r], [%r]", session, params) - - STATS['requests'][params.url.host] += 1 - - -async def on_request_end(session, trace_config_ctx, params): - global STATS - - logging.debug("HTTP END [%r], [%r]", session, params) - - host = params.url.host - status = params.response.status - - STATS['response_codes'][status] += 1 - STATS['response_codes_per_domain'][host][status] += 1 - - if params.method == 'POST': - STATS['delivery_codes'][status] += 1 - STATS['delivery_codes_per_domain'][host][status] += 1 - - -async def on_request_exception(session, trace_config_ctx, params): - global STATS - - logging.debug("HTTP EXCEPTION [%r], [%r]", session, params) - - host = params.url.host - exception = repr(params.exception) - - STATS['exceptions'][exception] += 1 - STATS['exceptions_per_domain'][host][exception] += 1 - - if params.method == 'POST': - STATS['delivery_exceptions'][exception] += 1 - STATS['delivery_exceptions_per_domain'][host][exception] += 1 - - -def http_debug(): - if logging.DEBUG >= logging.root.level: - return - - trace_config = aiohttp.TraceConfig() - trace_config.on_request_start.append(on_request_start) - trace_config.on_request_end.append(on_request_end) - trace_config.on_request_exception.append(on_request_exception) - return [trace_config] diff --git a/relay/misc.py b/relay/misc.py index 68b6a18..a98088f 100644 --- a/relay/misc.py +++ b/relay/misc.py @@ -14,8 +14,6 @@ from json.decoder import JSONDecodeError from urllib.parse import urlparse from uuid import uuid4 -from .http_debug import http_debug - app = None diff --git a/relay/views.py b/relay/views.py index d658468..9cea1ef 100644 --- a/relay/views.py +++ b/relay/views.py @@ -7,7 +7,6 @@ import traceback from pathlib import Path from . import __version__, misc -from .http_debug import STATS from .misc import DotDict, Message, Response from .processors import run_processor @@ -190,8 +189,3 @@ async def nodeinfo(request): async def nodeinfo_wellknown(request): data = aputils.WellKnownNodeinfo.new_template(request.config.host) return Response.new(data, ctype='json') - - -@register_route('GET', '/stats') -async def stats(request): - return Response.new(STATS, ctype='json')