airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Improve logging readability with DockerOperator

Open lyuyunbo opened this issue 1 year ago • 12 comments

Related: discussion

When DockerOperator logs are displayed in the Airflow UI, the logs from the container are prefixed with "[asctime UTC] {docker.py:[line]} INFO -" in some "random" lines. This prefix can disrupt the logging format inside the container and is often redundant:

  • [asctime UTC]: This timestamp may duplicate timestamps already present in the container logs
  • {docker.py:[line]}: This information is constant when the container is running and provides little value
  • INFO: The logging level is often misleading, as the actual log content may be of a different severity

This PR removes these three components from the logging prefix and only displaying the logs from the container, which aims to enhance the readability of the entire logging output.

lyuyunbo avatar Mar 09 '24 12:03 lyuyunbo

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: [email protected] Slack: https://s.apache.org/airflow-slack

boring-cyborg[bot] avatar Mar 09 '24 12:03 boring-cyborg[bot]

Hi @potiuk, I've added a PR to address your previous discussion with MattiaGallegati.

Would like to have your review on this. Thanks.

lyuyunbo avatar Mar 09 '24 12:03 lyuyunbo

I find it as a useful optional feature, but it absolutely cannot be enabled by default. It should be quite a bit more generic also in order to be useful - you should be able to not only enable it, but also provide an optional formatting + documentation and examples of usage in HowTo as well. It also needs unit tests testing it.

potiuk avatar Mar 09 '24 16:03 potiuk

I find it as a useful optional feature, but it absolutely cannot be enabled by default. It should be quite a bit more generic also in order to be useful - you should be able to not only enable it, but also provide an optional formatting + documentation and examples of usage in HowTo as well. It also needs unit tests testing it.

Good insights. I pushed a new commit based on these points. @potiuk

lyuyunbo avatar Mar 13 '24 07:03 lyuyunbo

Can you add the test cases for this change?

Change has been made in the new PR. Further review will be very welcomed and appreciated. @dirrao

lyuyunbo avatar Mar 13 '24 07:03 lyuyunbo

conflicts to resolve when rebasing.

potiuk avatar Mar 22 '24 21:03 potiuk

conflicts to resolve when rebasing.

Resolved.

lyuyunbo avatar Mar 22 '24 21:03 lyuyunbo

Still try/finally not solved

potiuk avatar Mar 22 '24 22:03 potiuk

Still try/finally not solved

Can you be more specific please @potiuk? Because we indeed added _restore_log_formatter into the except clause, which will revert the changes if formatters are not fully updated to the customized one.

If you are referring to the original suggestion:

Maybe I am nissing something I thought about try/finally where _restore_log_formatter will be called in the finally clause.

I think we've confused something here, because _restore_log_formatter will roll back all formatters no matter the try block succeeded or not, and makes this feature not working anymore.

lyuyunbo avatar Mar 22 '24 23:03 lyuyunbo

change()
try:
   do stuff
finally:
   restore()

potiuk avatar Mar 22 '24 23:03 potiuk

change()
try:
   do stuff
finally:
   restore()

Ha! I misunderstood which try-catch block you were mentioning before. Updated, this is indeed a good catch, thanks.

lyuyunbo avatar Mar 23 '24 00:03 lyuyunbo

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.

github-actions[bot] avatar May 09 '24 00:05 github-actions[bot]