-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Logging handler TaskHandlerWithCustomFormatter adds prefix three times #35622
Comments
@Aakcht Sorry for the late response. Is it still a case now, maybe you found a solution? As I could see this handler initially added as part of Airflow Contrib (deprecated in Airflow 2.0) And after migration to the Airflow 2.0 it moved into the core: #9395 Unfortunetly after that I can't find any significant changes in it so this might be a signal that it is broken for a long time or even abandoned |
Hi, @Taragolis ! Just retested it on Airflow 2.8.1 version - the issue is still there. Haven't gotten around to trying to figure out what the problem is yet , so no solution for now 🙁. I guess the idea from my original comment about checking if a context is already set in |
The most I can do now is mark it as Good First Issue, and some one (maybe you?) could invest their time a investigate is possible to fix that, and if so it would be nice also create some documentation about this handler. |
Hello, can I be assigned to this? I've replicated the bug in version 2.8.2, and @Aakcht's suggestion of checking if the context was already set in the |
@TiDeane If you're working on this, perhaps you can make a related doc fix too? I noticed that the example given for https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#task-log-prefix-template does not work. Given example is:
That doesn't work (it results in no prefix being added). Corrected, it would be:
|
@brki I am, and thank you for the suggestion! I'll update the docs along with the bugfix. A little progress update for anyone interested: from the testing I've done, it seems like the bug is caused because It might just be that the simplest and most efficient solution would be to simply check if the context has already been set at the beginning of By adding a simple |
… once When using the TaskHandlerWithCustomFormatter to add a prefix to logs, it was previously adding the prefix multiple times. This happened because it was being called multiple times from logging_mixin.py, and worsened because even when the handler's formatter was a TimezoneAware formatter (to include UTC offset), it was still adding an additional prefix. Because of this, I felt that any solution outside of the TaskHandlerWithCustomFormatter itself would either require a restructuring of the handlers' structure or slow down execution for all other handlers. And so, the solution I settled on was to add to TaskHandlerWithCustomFormatter's initial 'if' statement a simple 'or self.prefix_jinja_template is not None', so that it returns if the prefix had already been set. This is similar to what is done by the ElasticSearch es_task_handler.py. Note: also fixed the documentation's example for the handler, as the previous one was incorrect and didn't work.
… once When using the TaskHandlerWithCustomFormatter to add a prefix to logs, it was previously adding the prefix multiple times. This happened because it was being called multiple times from logging_mixin.py, and worsened because even when the handler's formatter was a TimezoneAware formatter (to include UTC offset), it was still adding an additional prefix. Because of this, I felt that any solution outside of the TaskHandlerWithCustomFormatter itself would either require a restructuring of the handlers' structure or slow down execution for all other handlers. And so, the solution I settled on was to add to TaskHandlerWithCustomFormatter's initial 'if' statement a simple 'or self.prefix_jinja_template is not None', so that it returns if the prefix had already been set. This is similar to what is done by the ElasticSearch es_task_handler.py. Note: also fixed the documentation's example for the handler, as the previous one was incorrect and didn't work.
Apache Airflow version
2.7.3
What happened
I tried using
airflow.utils.log.task_handler_with_custom_formatter.TaskHandlerWithCustomFormatter
handler for task logging and noticed that the prefix specified intask_log_prefix_template
is added three times.What you think should happen instead
The prefix should be added only one time.
How to reproduce
At first I encountered this issue in Kubernetes deployment with custom logging configuration, but it is also reproduced locally with the default configuration using
airflow standalone
command:Copy logging template from https://github.com/apache/airflow/blob/main/airflow/config_templates/airflow_local_settings.py and place it to
$AIRFLOW_HOME/config/custom_logging_config.py
In the logging template change
task
handler toRun
airflow standalone
and start any DAG in the UI.Check task logs in the terminal, for example:
Operating System
Debian "11 (Bullseye)" or Ubuntu
Versions of Apache Airflow Providers
No response
Deployment
Official Apache Airflow Helm Chart
Deployment details
Can be reproduced both locally and using airflow helm chart.
Anything else
I found this issue #10202 , but it looks like it was about airflow 1.
I wouldn't mind submitting a PR for this issue, but I'm not sure how to fix it except for adding a check in https://github.com/apache/airflow/blob/main/airflow/utils/log/task_handler_with_custom_formatter.py#L37 if the context was already set. But this doesn't look like correct approach.
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: