Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ea20feb
Refactor _interleave_logs and _read_from_local
jason810496 Dec 21, 2024
36ead5f
Refactor FileTaskHandler and TaskLogReader public method interface
jason810496 Dec 21, 2024
4af7229
Refactor test for get from local, parse log timestamp
jason810496 Dec 21, 2024
7189efb
Fix line_num in parsed_log_stream, dedupe logic
jason810496 Dec 21, 2024
77068a6
Fix interleave releated test
jason810496 Dec 21, 2024
a9c244d
Fix format for _read and read_log_stream methods
jason810496 Dec 22, 2024
e1824f7
Refactor _read_from_logs_server, read resp in chunk
jason810496 Dec 22, 2024
1fc8ef0
Add compatible utility for old and new log source
jason810496 Dec 22, 2024
e04d15f
Fix test_log_handlers
jason810496 Dec 22, 2024
b60eac3
Refactor read_log_chunks, read_log_stream methods
jason810496 Dec 23, 2024
607b4e4
Fix test_log_reader, minor fix test_log_handlers
jason810496 Dec 23, 2024
4770bbe
Fix get_log and test_get_log in api_fastapi
jason810496 Dec 23, 2024
d1e3565
Fix get_log and test_get_log in api_connexion
jason810496 Dec 23, 2024
ad13911
Fix _interleave_logs break loop condition
jason810496 Dec 23, 2024
8883de9
Move log_str_to_parsed_log_stream to test utils
jason810496 Dec 23, 2024
e6bad3d
Add _get_compatible_read_for_providers function
jason810496 Dec 25, 2024
ddb478a
Fix providers test cases that use read or _read method
jason810496 Dec 25, 2024
2123541
Fix TestGCSTaskHandler log sample
jason810496 Dec 25, 2024
5542ac5
Fix legacy view and corresponding test
jason810496 Dec 25, 2024
b96c0dc
Fix mypy typing error
jason810496 Dec 25, 2024
482b155
Fix test_file_task_handler_rotate_size_limit
jason810496 Dec 25, 2024
26c2d3e
Fix _get_compatible_parse_log_streams
jason810496 Dec 25, 2024
c441996
Fix providers compact tests
jason810496 Dec 26, 2024
8f89f5c
fixup! Add type hint
jason810496 Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions airflow/api_connexion/endpoints/log_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ def get_log(
# return_type would be either the above two or None
logs: Any
if return_type == "application/json" or return_type is None: # default
logs, metadata = task_log_reader.read_log_chunks(ti, task_try_number, metadata)
logs = logs[0] if task_try_number is not None else logs
hosts, log_streams, metadata = task_log_reader.read_log_chunks(ti, task_try_number, metadata)
host = f"{hosts[0] or ''}\n"
logs = log_streams[0] if task_try_number is not None else log_streams
# we must have token here, so we can safely ignore it
token = URLSafeSerializer(key).dumps(metadata) # type: ignore[assignment]
return logs_schema.dump(LogResponseObject(continuation_token=token, content=logs))
return logs_schema.dump(
LogResponseObject(continuation_token=token, content=host + "\n".join(log for log in logs))
)
# text/plain. Stream
logs = task_log_reader.read_log_stream(ti, task_try_number, metadata)

Expand Down
20 changes: 13 additions & 7 deletions airflow/api_fastapi/core_api/routes/public/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
from __future__ import annotations

import textwrap
from typing import Any
from collections.abc import Iterable

from fastapi import HTTPException, Request, Response, status
from fastapi import HTTPException, Request, status
from itsdangerous import BadSignature, URLSafeSerializer
from pydantic import PositiveInt
from sqlalchemy.orm import joinedload
from sqlalchemy.sql import select
from starlette.responses import StreamingResponse

from airflow.api_fastapi.common.db.common import SessionDep
from airflow.api_fastapi.common.headers import HeaderAcceptJsonOrText
Expand Down Expand Up @@ -135,12 +136,17 @@ def get_log(
except TaskNotFound:
pass

logs: Any
log_streams: list[Iterable[str]]
log_stream: Iterable[str]
if accept == Mimetype.JSON or accept == Mimetype.ANY: # default
logs, metadata = task_log_reader.read_log_chunks(ti, try_number, metadata)
hosts, log_streams, metadata = task_log_reader.read_log_chunks(ti, try_number, metadata)
# we must have token here, so we can safely ignore it
token = URLSafeSerializer(request.app.state.secret_key).dumps(metadata) # type: ignore[assignment]
return TaskInstancesLogResponse(continuation_token=token, content=str(logs[0])).model_dump()
host = f"{hosts[0] or ''}\n"
log_stream = log_streams[0]
return TaskInstancesLogResponse(
continuation_token=token, content=host + "\n".join(log for log in log_stream)
).model_dump()
# text/plain. Stream
logs = task_log_reader.read_log_stream(ti, try_number, metadata)
return Response(media_type=accept, content="".join(list(logs)))
log_stream = task_log_reader.read_log_stream(ti, try_number, metadata)
return StreamingResponse(log_stream, media_type=Mimetype.TEXT.value)
7 changes: 5 additions & 2 deletions airflow/executors/base_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from airflow.executors.executor_utils import ExecutorName
from airflow.models.taskinstance import TaskInstance
from airflow.models.taskinstancekey import TaskInstanceKey
from airflow.utils.log.file_task_handler import _CompatibleLogSourceType

# Command to execute - list of strings
# the first element is always "airflow".
Expand Down Expand Up @@ -569,13 +570,15 @@ def execute_async(
"""
raise NotImplementedError()

def get_task_log(self, ti: TaskInstance, try_number: int) -> tuple[list[str], list[str]]:
def get_task_log(self, ti: TaskInstance, try_number: int) -> _CompatibleLogSourceType:
"""
Return the task logs.

:param ti: A TaskInstance object
:param try_number: current try_number to read log from
:return: tuple of logs and messages
:return:
- old interface: Tuple of messages and list of log lines.
- new interface: Tuple of messages, parsed log streams, total size of logs.
"""
return [], []

Expand Down
Loading
Loading