Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-pick][Serve] fix missing message body for json log formats (#42729) #42874

Merged
merged 1 commit into from Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/ray/serve/_private/logging_utils.py
Expand Up @@ -81,10 +81,10 @@ def format(self, record: logging.LogRecord) -> str:
SERVE_LOG_APPLICATION
]

if SERVE_LOG_MESSAGE in record.__dict__:
record_format[SERVE_LOG_MESSAGE] = (
SERVE_LOG_RECORD_FORMAT[SERVE_LOG_MESSAGE] % record.__dict__
)
message_formatter = logging.Formatter(
SERVE_LOG_RECORD_FORMAT[SERVE_LOG_MESSAGE]
)
record_format[SERVE_LOG_MESSAGE] = message_formatter.format(record)

if SERVE_LOG_EXTRA_FIELDS in record.__dict__:
if not isinstance(record.__dict__[SERVE_LOG_EXTRA_FIELDS], dict):
Expand Down
6 changes: 6 additions & 0 deletions python/ray/serve/tests/test_logging.py
Expand Up @@ -556,6 +556,12 @@ def format_and_verify_json_output(record, expected_record: dict):
expected_json["deployment"] = "component"
expected_json["replica"] = "component_id"

# Ensure message exists in the output.
# Note that there is no "message" key in the record dict until it has been
# formatted. This check should go before other fields are set and checked.
expected_json["message"] = "my_path:1 - my_message"
format_and_verify_json_output(record, expected_json)

# Set request id
record.request_id = "request_id"
expected_json["request_id"] = "request_id"
Expand Down