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 <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-01 14:23:15 -07:00
parent 9aa8decf40
commit 16e6fa2cdd
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 2 additions and 2 deletions

View file

@ -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()

View file

@ -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)