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

DockerOperateur TaskFlow - improve logs #39620

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

antoinetavant
Copy link

Closes #39319

This PR provide two minor changes :

  • Two additional arguments are given to the python command to match the updates of the script interface
    python3 /tmp/script.py /tmp/script.in /tmp/script.out none /tmp/script.out
    Indeed, the script used in the DockerOperator in the same as the one in PythonVirtualenvOperator (see airflow/utils/python_virtualenv_script.jinja2 )
  • The messages transferred from the docker container to the worker are split line by line to the logger, in order to
    • allow multiline messages such as Trace backs to maintain the indent (useful for PEP-657 )
    • Manage buffered messages that should be individually printed but could be differed
    • Sherry on the cake : filtering on the message level and the file display the totality of the multi-line message (instead of only the first line)

Illustration of the multiline splits

Before :

[2024-05-14T12:51:52.701+0000] {docker.py:436} INFO - + python3 /tmp/script.py /tmp/script.in /tmp/script.out none /tmp/script.out
[2024-05-14T12:51:52.741+0000] {docker.py:436} INFO - Traceback (most recent call last):
  File "/tmp/script.py", line 31, in <module>
    res = fails(*arg_dict["args"], **arg_dict["kwargs"])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/script.py", line 17, in fails
    a = 1 / 0
        ~~^~~
ZeroDivisionError: division by zero
[2024-05-14T12:51:52.955+0000] {taskinstance.py:454} INFO - ::group::Post task execution logs

Now

[2024-05-14T12:50:17.655+0000] {docker.py:437} INFO - + python3 /tmp/script.py /tmp/script.in /tmp/script.out none /tmp/script.out
[2024-05-14T12:50:17.693+0000] {docker.py:437} INFO - Traceback (most recent call last):
[2024-05-14T12:50:17.694+0000] {docker.py:437} INFO -   File "/tmp/script.py", line 31, in <module>
[2024-05-14T12:50:17.694+0000] {docker.py:437} INFO -     res = fails(*arg_dict["args"], **arg_dict["kwargs"])
[2024-05-14T12:50:17.694+0000] {docker.py:437} INFO -           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-05-14T12:50:17.695+0000] {docker.py:437} INFO -   File "/tmp/script.py", line 17, in fails
[2024-05-14T12:50:17.695+0000] {docker.py:437} INFO -     a = 1 / 0
[2024-05-14T12:50:17.696+0000] {docker.py:437} INFO -         ~~^~~
[2024-05-14T12:50:17.696+0000] {docker.py:437} INFO - ZeroDivisionError: division by zero
[2024-05-14T12:50:17.876+0000] {taskinstance.py:454} INFO - ::group::Post task execution logs


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

Antoine TAVANT added 2 commits May 14, 2024 13:20
Needed when log messages are buffered,
and to align the ident of TraceBacks

Also add 2 arguments to the python command in order to
follow the evolutions of apache#31747
Copy link

boring-cyborg bot commented May 14, 2024

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link
Collaborator

@dirrao dirrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulations on your first MR. Can you add the test case for your change?
Formatting the traceback with logger prefix message will beautify the logs. However, it is difficult to traceback whether the logs from the same code line or multiple code lines.

Copy link
Member

@hussein-awala hussein-awala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-0.9 Your PR makes the log more beautiful in Airflow webserver, but it also makes it harder to process and analyze via log tools (datadog, cloudwatch, ELK...)

@antoinetavant
Copy link
Author

-0.9 Your PR makes the log more beautiful in Airflow webserver, but it also makes it harder to process and analyze via log tools (datadog, cloudwatch, ELK...)

Damn ! I did not expect that. I'm not using such tools...

Do you think there is a way to allow both approaches to work ?

I thought of indenting the multi-line messages with white spaces matching the length of the logging prefix, but unfortunately the buffering of the messages make such that it is not possible to differentiate one multiline message (such as a Trace back) or multiple messages that are sent at the same time.

@jscheffl
Copy link
Contributor

-0.9 Your PR makes the log more beautiful in Airflow webserver, but it also makes it harder to process and analyze via log tools (datadog, cloudwatch, ELK...)

I would be a +0.5 for the log adjustments - nt using ELK but bothered with the output especially in conjunction as also reported in #39686 . My proposal is to make it configurable, maybe as a parameter on the operator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing termination argument in DockerOperator
4 participants