-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Add button to download task logs as a text file #49412
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
base: main
Are you sure you want to change the base?
Conversation
const element = document.createElement("a"); | ||
|
||
element.href = URL.createObjectURL(file); | ||
element.download = `taskInstanceLogs.txt`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks the filename for the downloaded log file. This should include dagId and taskInstance details in the name like Airflow 2 else this might keep overwriting the file on disk or create something like taskInstanceLogs(1).txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on ${dagId}-${taskId}-${runId}-${mapIndex}-${tryNumber}.txt
) => { | ||
const refetchInterval = useAutoRefresh({ dagId }); | ||
|
||
const { data, ...rest } = useTaskInstanceServiceGetLog( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can pass text/plain
in the accept here and get the raw value of the log file in the storage which is the value users usually want to reduce the code for formatting.
accept?: "application/json" | "text/plain" | "*/*";
airflow/airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py
Lines 136 to 153 in 96c6daa
if accept == Mimetype.JSON or accept == Mimetype.ANY: # default | |
logs, metadata = task_log_reader.read_log_chunks(ti, try_number, metadata) | |
encoded_token = None | |
if not metadata.get("end_of_log", False): | |
encoded_token = URLSafeSerializer(request.app.state.secret_key).dumps(metadata) | |
return TaskInstancesLogResponse.model_construct(continuation_token=encoded_token, content=logs) | |
# text/plain, or something else we don't understand. Return raw log content | |
# We need to exhaust the iterator before we can generate the continuation token. | |
# We could improve this by making it a streaming/async response, and by then setting the header using | |
# HTTP Trailers | |
logs = "".join(task_log_reader.read_log_stream(ti, try_number, metadata)) | |
headers = None | |
if not metadata.get("end_of_log", False): | |
headers = { | |
"Airflow-Continuation-Token": URLSafeSerializer(request.app.state.secret_key).dumps(metadata) | |
} | |
return Response(media_type="application/x-ndjson", content=logs, headers=headers) |
@aarochuk mind rebasing and addressing PR comments? |
@bbovenzi I will make sure to make another push by the end of the week sorry it has taken so long |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
@aarochuk are you still able to finish this PR? |
Added ability to download task instance logs in airflow 3 ui as described in issue #47689
closes: #47689