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

Improve Airflow logging for operator Jinja template processing #25452

Conversation

barrywhart
Copy link
Contributor

@barrywhart barrywhart commented Aug 1, 2022

closes: #25344

Adds logging to provide debugging help for failures in render_template_fields()


^ 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.

@barrywhart barrywhart marked this pull request as draft August 1, 2022 20:30
@@ -77,6 +78,9 @@
)


logger = logging.getLogger("airflow.models.abstractoperator.AbstractOperator")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added logger instance, following the same pattern as baseoperator.py.

return render_template_as_native(template, context)
return render_template_to_string(template, context)
return render_template_as_native(template, context) # type: ignore[arg-type]
return render_template_to_string(template, context) # type: ignore[arg-type]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Work around mypy failures. These issues seemed to be unrelated to my changes.

Copy link
Member

Choose a reason for hiding this comment

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

What are the errors? We do not want to introduce necessary ignores into the code base; if the errors are indeed unrelated, they need to be fixed first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the errors. When you say:

they need to be fixed first.

Are you requesting that I fix them, or someone else will fix them?

airflow/models/abstractoperator.py:402: error: Argument 2 to "render_template_as_native" has incompatible type "Context"; expected "MutableMapping[str, Any]"  [arg-type]
                    return render_template_as_native(template, context)
                                                               ^
airflow/models/abstractoperator.py:403: error: Argument 2 to "render_template_to_string" has incompatible type "Context"; expected "MutableMapping[str, Any]"  [arg-type]
                return render_template_to_string(template, context)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the # type: ignore comments. We'll see if the CI requires them. Local mypy didn't like those lines.

For what it's worth, these are the versions of mypy and related packages in my Breeze Docker environment (newly set up yesterday):

mypy==0.950
mypy-boto3-appflow==1.24.36.post1
mypy-boto3-rds==1.24.38
mypy-boto3-redshift-data==1.24.36.post1
mypy-extensions==0.4.3

@barrywhart barrywhart marked this pull request as ready for review August 1, 2022 20:40
Comment on lines 360 to 364
logger.exception(
f"Exception rendering Jinja template for in "
f"task '{self.task_id}', field "
f"'{attr_name}'. Template: {value!r}"
)
Copy link
Member

Choose a reason for hiding this comment

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

I think self.log.exception is better here; baseoperator needed an additional logger for free functions outside a class, but this inherits LoggingMixin and does not need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@eladkal eladkal changed the title Issue 25344: Improve Airflow logging for operator Jinja template processing Improve Airflow logging for operator Jinja template processing Aug 2, 2022
@barrywhart
Copy link
Contributor Author

Updated and ready for another review!

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

COOL!

@potiuk potiuk merged commit 4da2b0c into apache:main Aug 2, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 2, 2022

Awesome work, congrats on your first merged pull request!

@ephraimbuddy ephraimbuddy added the type:improvement Changelog: Improvements label Aug 15, 2022
@ephraimbuddy ephraimbuddy added this to the Airflow 2.4.0 milestone Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Airflow logging for operator Jinja template processing
4 participants