Skip to content

Commit 09d27bf

Browse files
committed
less code
1 parent 69707e2 commit 09d27bf

File tree

5 files changed

+3
-45
lines changed

5 files changed

+3
-45
lines changed

src/common/gunicorn/logging.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from common.core.logging import JsonFormatter
1515
from common.gunicorn import metrics
1616
from common.gunicorn.constants import WSGI_DJANGO_ROUTE_ENVIRON_KEY
17-
from common.gunicorn.utils import get_status_from_wsgi_response_status
1817
from common.prometheus.utils import with_labels
1918

2019

@@ -57,7 +56,7 @@ def access(
5756
# The Django route is set by `PrometheusGunicornLoggerMiddleware`.
5857
"path": environ.get(WSGI_DJANGO_ROUTE_ENVIRON_KEY),
5958
"method": environ.get("REQUEST_METHOD"),
60-
"response_status": get_status_from_wsgi_response_status(resp.status),
59+
"response_status": resp.status_code,
6160
}
6261
with_labels(metrics.http_request_duration_seconds, **labels).observe(
6362
duration_seconds

src/common/gunicorn/utils.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import argparse
2-
from functools import lru_cache
32
from typing import Any
43

54
from django.core.handlers.wsgi import WSGIHandler
65
from django.core.wsgi import get_wsgi_application
7-
from django.urls import Resolver404, resolve
86
from environs import Env
97
from gunicorn.app.wsgiapp import ( # type: ignore[import-untyped]
108
WSGIApplication as GunicornWSGIApplication,
119
)
1210
from gunicorn.config import Config # type: ignore[import-untyped]
1311

14-
from common.prometheus.constants import UNKNOWN_LABEL_VALUE
15-
from common.prometheus.types import LabelValue
16-
1712
env = Env()
1813

1914
DEFAULT_ACCESS_LOG_FORMAT = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %({origin}i)s %({access-control-allow-origin}o)s'
@@ -54,19 +49,6 @@ def load_wsgiapp(self) -> WSGIHandler:
5449
return get_wsgi_application()
5550

5651

57-
@lru_cache(maxsize=64)
58-
def get_status_from_wsgi_response_status(
59-
status: str | bytes | int | None,
60-
) -> str | None:
61-
if isinstance(status, int):
62-
return str(status)
63-
if isinstance(status, bytes):
64-
status = status.decode("utf-8")
65-
if isinstance(status, str):
66-
status = status.split(None, 1)[0]
67-
return status
68-
69-
7052
def add_arguments(parser: argparse._ArgumentGroup) -> None:
7153
_config = Config()
7254
keys = sorted(_config.settings, key=_config.settings.__getitem__)

src/common/prometheus/types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import Literal, TypeAlias
1+
from typing import Literal
22

33
UnknownLabelValue = Literal["unknown"]
4-
LabelValue: TypeAlias = str | UnknownLabelValue

src/common/prometheus/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from prometheus_client.multiprocess import MultiProcessCollector
66

77
from common.prometheus.constants import UNKNOWN_LABEL_VALUE
8-
from common.prometheus.types import LabelValue
98

109
T = typing.TypeVar("T", bound=MetricWrapperBase)
1110

@@ -18,7 +17,7 @@ def get_registry() -> prometheus_client.CollectorRegistry:
1817

1918
def with_labels(
2019
metric: T,
21-
**labels: LabelValue | None,
20+
**labels: typing.Any,
2221
) -> T:
2322
"""
2423
Add labels to a given metric. If a label value is `None` or is not provided,

tests/unit/common/gunicorn/test_utils.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,10 @@
88

99
from common.gunicorn.utils import (
1010
DjangoWSGIApplication,
11-
get_status_from_wsgi_response_status,
1211
run_server,
1312
)
1413

1514

16-
@pytest.mark.parametrize(
17-
"status,expected",
18-
(
19-
[b" 200 ", "200"],
20-
[200, "200"],
21-
["200", "200"],
22-
[None, "unknown"],
23-
),
24-
)
25-
def test_get_status_from_wsgi_response_status__returns_expected(
26-
status: str | bytes | int | None,
27-
expected: str,
28-
) -> None:
29-
# When
30-
result = get_status_from_wsgi_response_status(status)
31-
32-
# Then
33-
assert result == expected
34-
35-
3615
def test_django_wsgi_application__defaults__expected_config(
3716
mocker: pytest_mock.MockerFixture,
3817
) -> None:

0 commit comments

Comments
 (0)