Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/HH-199730' into EXP-83898
Browse files Browse the repository at this point in the history
  • Loading branch information
HH ReleaseBot committed Nov 27, 2023
2 parents 1a39600 + 5a0d4cb commit 0eb8666
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
6 changes: 1 addition & 5 deletions frontik/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
from frontik.integrations.statsd import StatsDClient, StatsDClientStub


def _fallback_status_code(status_code: int) -> int:
return status_code if status_code in ALLOWED_STATUSES else http.client.SERVICE_UNAVAILABLE


class FinishWithPostprocessors(Exception):
def __init__(self, wait_finish_group: bool = False) -> None:
self.wait_finish_group = wait_finish_group
Expand Down Expand Up @@ -292,7 +288,7 @@ def _get_request_mime_type(self, request: HTTPServerRequest) -> str:
return re.split(MEDIA_TYPE_PARAMETERS_SEPARATOR_RE, content_type)[0]

def set_status(self, status_code: int, reason: str | None = None) -> None:
status_code = _fallback_status_code(status_code)
status_code = status_code if status_code in ALLOWED_STATUSES else http.client.SERVICE_UNAVAILABLE
super().set_status(status_code, reason=reason)

def redirect(self, url, *args, allow_protocol_relative=False, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion frontik/http_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

CLIENT_CLOSED_REQUEST = 499
NON_CRITICAL_BAD_GATEWAY = 569
ALLOWED_STATUSES = [*list(http.client.responses.keys()), CLIENT_CLOSED_REQUEST, NON_CRITICAL_BAD_GATEWAY]
ALLOWED_STATUSES = {*http.client.responses.keys(), CLIENT_CLOSED_REQUEST, NON_CRITICAL_BAD_GATEWAY}
3 changes: 3 additions & 0 deletions frontik/loggers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from logging.handlers import SysLogHandler
from typing import TYPE_CHECKING

import orjson
from tornado.log import LogFormatter

from frontik import request_context
Expand Down Expand Up @@ -90,6 +91,8 @@ def format(self, record):
if stack_trace:
json_message['exception'] = stack_trace

if options.log_use_orjson:
return orjson.dumps(json_message).decode("utf-8")
return json.dumps(json_message)

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions frontik/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Options:

log_dir: str | None = None
log_level: str = 'info'
log_use_orjson: bool = True
update_log_level_interval_in_seconds: int = 300
log_json: bool = True
log_text_format: str = '[%(process)s] %(asctime)s %(levelname)s %(name)s: %(message)s'
Expand Down
63 changes: 61 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jinja2 = '3.1.2'
lxml = '4.9.2'
pydantic = '^2.3.0'
tornado = '6.3.2'
orjson = '*'
http-client = {git = 'https://github.com/hhru/balancing-http-client.git', tag = '2.1.4'}
python-consul2-hh = {git = 'https://github.com/hhru/python-consul2', tag = 'v0.2.9'}
opentelemetry-sdk = '1.17.0'
Expand Down

0 comments on commit 0eb8666

Please sign in to comment.