From 16e6fa2cdd002fecf6ad5e4251727315d7a3dfc8 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Mon, 1 Nov 2021 14:23:15 -0700 Subject: [PATCH] fix(fastapi): fix prometheus parsing of HTTPStatus This wasn't actually casting to int. We shouldn't be providing HTTPStatus.CONSTANTS directly anyway, but, in case we do, we now just convert the status to an int before converting it to a string. Signed-off-by: Kevin Morris --- aurweb/prometheus.py | 2 +- aurweb/routers/packages.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aurweb/prometheus.py b/aurweb/prometheus.py index 0a3dd173..a64f6b27 100644 --- a/aurweb/prometheus.py +++ b/aurweb/prometheus.py @@ -79,7 +79,7 @@ def http_requests_total() -> Callable[[Info], None]: method = scope.get("method") path = get_matching_route_path(base_scope, scope.get("router").routes) - status = str(info.response.status_code)[:1] + "xx" + status = str(int(info.response.status_code))[:1] + "xx" metric.labels(method=method, path=path, status=status).inc() diff --git a/aurweb/routers/packages.py b/aurweb/routers/packages.py index c574ec18..bcc0be56 100644 --- a/aurweb/routers/packages.py +++ b/aurweb/routers/packages.py @@ -269,7 +269,7 @@ async def package_base(request: Request, name: str) -> Response: # If this is not a split package, redirect to /packages/{name}. if pkgbase.packages.count() == 1: return RedirectResponse(f"/packages/{name}", - status_code=HTTPStatus.SEE_OTHER) + status_code=int(HTTPStatus.SEE_OTHER)) # Add our base information. context = await make_single_context(request, pkgbase)