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

Fix static file caching is disabled in Airflow Webserver. #39345

Conversation

VertexToEdge
Copy link
Contributor

@VertexToEdge VertexToEdge commented May 1, 2024

close #39344

Above Airflow 2.3.0, webserver's static file caching is disabled because of major updated Flask's breaking change. In Flask 2.0.x, default value of SEND_FILE_MAX_AGE_DEFAULT is changed from 12 hours to None on that version.
SEND_FILE_MAX_AGE_DEFAULT affects Expires Field in HTTP response header.
if it is None, Expires Field in HTTP response header is removed.

this pr add SEND_FILE_MAX_AGE_DEFAULT config for Flask explicitly in /airflow/www/app.py.
It enables static file caching in Airflow webserver.

I checked Airflow configuration references and searched SEND_FILE_MAX_AGE_DEFAULT in Airflow codebase, but there's no way to enable static file caching for airflow webserver's Flask.

Airflow 2.9.0: As-Is

image

Airflow 2.9.0: To-Be (Caching Worked)

290_with_caching

Local test in /tests/www

image


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

In Airflow 2.3.0, it's Flask version is bumped up to 2.0.x
Flask 2.0.x has some breaking changes. one of them is about `SEND_FILE_MAX_AGE_DEFAULT`.
It affect static file's Expires value on HTTP response header.
and the default value is changed from 12 hours to None on that version.

in order to enable static file caching in airflow webserver.
it needs explicitly configration of `SEND_FILE_MAX_AGE_DEFAULT` in Flask.
@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label May 1, 2024
Copy link

boring-cyborg bot commented May 1, 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

@bbovenzi bbovenzi added this to the Airflow 2.9.2 milestone May 1, 2024
@bbovenzi
Copy link
Contributor

bbovenzi commented May 1, 2024

Nice catch! We could probably cache it for a few weeks. Assets will only change between airflow version updates.

airflow/www/app.py Outdated Show resolved Hide resolved
@jscheffl
Copy link
Contributor

jscheffl commented May 4, 2024

Really cool catch. I can immediately see it locally and the UI feels immediately faster with this PR! THANKS!

(I think we could debate about the time, 12h sounds reasonable for me, still it will allow also proxy chains to cache files (if not HTTPS) - if somebody wants to have this nicer, still could be configurable. But 12h is a big improvement anyway!

@jscheffl jscheffl merged commit d396533 into apache:main May 4, 2024
39 checks passed
Copy link

boring-cyborg bot commented May 4, 2024

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

RodrigoGanancia pushed a commit to RodrigoGanancia/airflow that referenced this pull request May 10, 2024
* Fix static file caching is disabled in Airflow Webserver.

In Airflow 2.3.0, it's Flask version is bumped up to 2.0.x
Flask 2.0.x has some breaking changes. one of them is about `SEND_FILE_MAX_AGE_DEFAULT`.
It affect static file's Expires value on HTTP response header.
and the default value is changed from 12 hours to None on that version.

in order to enable static file caching in airflow webserver.
it needs explicitly configration of `SEND_FILE_MAX_AGE_DEFAULT` in Flask.

* Fix typo

* Fix code's formatting with ruff
@utkarsharma2 utkarsharma2 added the type:bug-fix Changelog: Bug Fixes label Jun 4, 2024
ephraimbuddy pushed a commit that referenced this pull request Jun 4, 2024
* Fix static file caching is disabled in Airflow Webserver.

In Airflow 2.3.0, it's Flask version is bumped up to 2.0.x
Flask 2.0.x has some breaking changes. one of them is about `SEND_FILE_MAX_AGE_DEFAULT`.
It affect static file's Expires value on HTTP response header.
and the default value is changed from 12 hours to None on that version.

in order to enable static file caching in airflow webserver.
it needs explicitly configration of `SEND_FILE_MAX_AGE_DEFAULT` in Flask.

* Fix typo

* Fix code's formatting with ruff

(cherry picked from commit d396533)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webserver static file caching is disabled above 2.3.0 version.
5 participants