From afd25c248fcee508da6724398f6c37c47bf4be5e Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Mon, 14 Mar 2022 06:24:15 -0700 Subject: [PATCH] fix: remove HEAD and OPTIONS handling from metrics Signed-off-by: Kevin Morris --- aurweb/prometheus.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aurweb/prometheus.py b/aurweb/prometheus.py index 73be3ef6..272ee023 100644 --- a/aurweb/prometheus.py +++ b/aurweb/prometheus.py @@ -60,6 +60,9 @@ def http_requests_total() -> Callable[[Info], None]: labelnames=("method", "path", "status")) def instrumentation(info: Info) -> None: + if info.request.method.lower() in ("head", "options"): # pragma: no cover + return + scope = info.request.scope # Taken from https://github.com/stephenhillier/starlette_exporter @@ -70,8 +73,8 @@ def http_requests_total() -> Callable[[Info], None]: if not (scope.get("endpoint", None) and scope.get("router", None)): return None - root_path = scope.get("root_path", "") - app = scope.get("app", {}) + root_path = scope.get("root_path", str()) + app = scope.get("app", dict()) if hasattr(app, "root_path"): app_root_path = getattr(app, "root_path") @@ -102,6 +105,9 @@ def http_api_requests_total() -> Callable[[Info], None]: labelnames=("type", "status")) def instrumentation(info: Info) -> None: + if info.request.method.lower() in ("head", "options"): # pragma: no cover + return + if info.request.url.path.rstrip("/") == "/rpc": type = info.request.query_params.get("type", "None") if info.response: