Prevent malformed Elasticsearch log entries from crashing task log fetch#69306
Open
hkc-8010 wants to merge 2 commits into
Open
Prevent malformed Elasticsearch log entries from crashing task log fetch#69306hkc-8010 wants to merge 2 commits into
hkc-8010 wants to merge 2 commits into
Conversation
A single stored log entry with a non-string `event` field (for example, a task that logs a list or dict as the sole message argument) currently crashes the entire task-log-fetch request with an unhandled pydantic.ValidationError, instead of degrading gracefully. _read() built StructuredLogMessage objects from stored Elasticsearch hits without catching validation failures. This catches ValidationError per hit and falls back to a stringified event, matching the existing fallback pattern in file_task_handler.py's _log_stream_to_parsed_log_stream. closes: apache#69304
4 tasks
The new StructuredLogMessage fallback tests exercise an Airflow 3-only type, but the provider compatibility matrix still runs this provider against Airflow 2.11.1. Guarding those tests the same way as the runtime path keeps the compatibility job focused on behavior that actually exists in that release line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
eventfield (for example, a task thatlogs a list or dict as the sole message argument) currently crashes the entire
task-log-fetch request with an unhandled pydantic.ValidationError, instead of
degrading gracefully.
_read()builtStructuredLogMessageobjects from stored Elasticsearch hits withoutcatching validation failures. This change catches
ValidationErrorper hit and fallsback to a stringified event, matching the existing fallback pattern in
file_task_handler.py's_log_stream_to_parsed_log_stream.Changes
providers/elasticsearch/src/airflow/providers/elasticsearch/log/es_task_handler.py:wrap
StructuredLogMessageconstruction in a try/exceptValidationErrorwith astringified-event fallback and a warning log.
providers/elasticsearch/tests/unit/elasticsearch/log/test_es_task_handler.py: addcoverage for malformed
eventhandling and forread()surviving one bad hit amongotherwise-valid hits.
PR Checklist
mainbranchprekhooks all passcloses: #69304