Skip to content

AIP-79 Support Airflow 2.x plugins in fast api#44464

Merged
vincbeck merged 1 commit into
apache:mainfrom
aws-mwaa:vincbeck/aip-79-wsgi
Dec 6, 2024
Merged

AIP-79 Support Airflow 2.x plugins in fast api#44464
vincbeck merged 1 commit into
apache:mainfrom
aws-mwaa:vincbeck/aip-79-wsgi

Conversation

@vincbeck

@vincbeck vincbeck commented Nov 28, 2024

Copy link
Copy Markdown
Contributor

To support Airflow 2.x plugins in Airflow 3 the goal is to embed a minimal version of Airflow 2 in fast api using WSGIMiddleware. The Airflow 2.x plugins will run in this application as they are running today in Airflow 2. WSGIMiddleware allows running a WSGI in the fast api application. This Flask application will be accessible under the path /pluginsv2.

The plan is to:

  1. (This PR) Copy files from core Airflow to Fab provider to create a minimal version of Airflow 2 in Fab provider. This minimal version of Airflow 2 should only contain core elements needed by the plugins to run. The goal is not to copy the entire Flask application but only a more simplified version of it. This minimal version of Airflow 2 in Fab provider should be self contained in Fab provider, they must not depend on Flask-related objects defined in core Airflow. The goal is, when the Flask application will be deleted from core Airflow, it should be possible because the mini Airflow 2 in Fab provider does not depend on it.
  2. (This PR as well) Embed the mini Airflow 2 defined in Fab provider in the fast api application so that Airflow 2.x plugins will be available in Airflow 3
  3. When the new Airflow 3 UI becomes the default UI and no fallback to the old UI is possible, remove the Flask application and all related resources (e.g. views) from core Airflow.

The idea is, if you do not have any Airflow 2.x plugin defined in your environment, you should not have Flask as dependency. On the opposite, if you do have some Airflow 2.x plugins in your environment, fab provider will have to be installed and all the code needed to run the Flask application will be in this provider.

The experience for the user will not be ideal because these plugins use the Airflow 2 UI, therefore the UI experience will be inconsistent between the Airflow pages (Airflow 3 UI) and the plugins (Airflow 2 UI). A warning message will be added in the embedded Flask application to let the user knows about this weird experience but also to recommend them to migrate their plugins to Airflow 3 plugins.


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

@boring-cyborg boring-cyborg Bot added area:plugins area:webserver Webserver related Issues labels Nov 28, 2024
@vincbeck

Copy link
Copy Markdown
Contributor Author

@jedcunningham

@jedcunningham

Copy link
Copy Markdown
Member

Instead of waiting for #2 to happen, let's just copy/trim whatever minimal FAB stuff we need into the FAB provider now - just leave it completely separate from the old UI. Then we aren't blocked at all.

@vincbeck

vincbeck commented Dec 2, 2024

Copy link
Copy Markdown
Contributor Author

Instead of waiting for #2 to happen, let's just copy/trim whatever minimal FAB stuff we need into the FAB provider now - just leave it completely separate from the old UI. Then we aren't blocked at all.

That sounds good to me. That's a good idea indeed, we can save some time by doing this. Should we do it in a separate PR though? This one sets up the mechanism to embed Airflow 2 in Airflow 3 and the other PR(s) would be copying over the Flask app to Fab provider

@jedcunningham

Copy link
Copy Markdown
Member

I'd kinda prefer we don't mount the "whole" AF2 app as-is in AF3, even if we do view it as temporary.

@vincbeck

vincbeck commented Dec 2, 2024

Copy link
Copy Markdown
Contributor Author

I'd kinda prefer we don't mount the "whole" AF2 app as-is in AF3, even if we do view it as temporary.

Alright, I'll do it in this PR then

@vincbeck
vincbeck force-pushed the vincbeck/aip-79-wsgi branch 2 times, most recently from e403d33 to d608026 Compare December 3, 2024 20:04
Comment thread providers/src/airflow/providers/fab/www/app.py
Comment thread providers/src/airflow/providers/fab/www/templates/swagger-ui/index.j2 Outdated
Comment thread providers/src/airflow/providers/fab/www/webpack.config.js
@vincbeck

vincbeck commented Dec 3, 2024

Copy link
Copy Markdown
Contributor Author

This is a preview of the page when accessing a plugin.

URL is <fast_api_endpoint>/pluginsv2/

Screenshot 2024-12-03 at 3 31 25 PM

Comment thread providers/src/airflow/providers/fab/www/templates/airflow/main.html
@vincbeck
vincbeck marked this pull request as ready for review December 3, 2024 22:27
Comment thread providers/src/airflow/providers/fab/www/package.json
Comment thread providers/src/airflow/providers/fab/www/package.json
Comment thread providers/src/airflow/providers/fab/www/templates/airflow/main.html Outdated
Comment thread providers/src/airflow/providers/fab/www/static/js/toggle_theme.js Outdated
Comment thread providers/src/airflow/providers/fab/www/extensions/init_views.py
@vincbeck
vincbeck force-pushed the vincbeck/aip-79-wsgi branch 4 times, most recently from f3b17ee to 629f12e Compare December 4, 2024 22:54

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Amazing work.

Can we also reuse that same application to do the flask auth server ? (When people are using FABAuthManager and we need to reach for the flask webserver) ?

Comment thread airflow/api_fastapi/core_api/app.py
@vincbeck
vincbeck force-pushed the vincbeck/aip-79-wsgi branch from 629f12e to 1576e04 Compare December 5, 2024 14:25
@vincbeck

vincbeck commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

Can we also reuse that same application to do the flask auth server ? (When people are use FABAuthManager and we need to reach for the flask webserver) ?

I was wondering the same and I think we should do that

@vincbeck
vincbeck force-pushed the vincbeck/aip-79-wsgi branch from 1576e04 to 348893e Compare December 5, 2024 14:55
@vincbeck

vincbeck commented Dec 5, 2024

Copy link
Copy Markdown
Contributor Author

Tests are passing, let me know if there are more comments/feedbacks

@jedcunningham jedcunningham left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks good. Couple things (like the link to the AF3 homepage) that we can sort out later.

Comment thread airflow/api_fastapi/core_api/app.py Outdated
Comment thread providers/src/airflow/providers/fab/www/templates/swagger-ui/index.j2 Outdated
@vincbeck
vincbeck force-pushed the vincbeck/aip-79-wsgi branch 2 times, most recently from 2221193 to fe5aa66 Compare December 6, 2024 17:17
…on of the Flask application in fastapi application
@vincbeck
vincbeck force-pushed the vincbeck/aip-79-wsgi branch from fe5aa66 to 03ce01e Compare December 6, 2024 17:42
@vincbeck
vincbeck merged commit 662f6e2 into apache:main Dec 6, 2024
@vincbeck
vincbeck deleted the vincbeck/aip-79-wsgi branch December 6, 2024 18:41
@jedcunningham

Copy link
Copy Markdown
Member

Whoo! Nice!

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

Labels

area:plugins area:webserver Webserver related Issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants