Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Stop rebuilding the FAB app on every users and roles API call - #73104

Open
namanjain24-sudo wants to merge 1 commit into
apache:mainfrom
namanjain24-sudo:fix-fab-api-appbuilder-per-request
Open

Stop rebuilding the FAB app on every users and roles API call#73104
namanjain24-sudo wants to merge 1 commit into
apache:mainfrom
namanjain24-sudo:fix-fab-api-appbuilder-per-request

Conversation

@namanjain24-sudo

Copy link
Copy Markdown
Contributor

The users, roles and permissions endpoints under /auth/fab/v1 wrapped every request in get_application_builder(), the helper written for the FAB CLI commands. It creates a new Flask app per call, so the @cache on _return_appbuilder never hits and keeps every app alive. Each request also re-runs init_appbuilder, which swaps the auth manager's appbuilder for the throwaway one and, with the default update_fab_perms, runs a full sync_roles().

These routes now use the auth manager's own Flask app through _get_flask_app(), the same way the login routes already do. The CLI helper is unchanged.

I ran a local airflow api-server (sqlite, one worker) and sent 400 authenticated GETs to users and roles, 8 at a time:

before after
p50 / p95 latency 506 / 878 ms 75 / 131 ms
API server RSS growth +271 MiB +6.6 MiB

Postgres 16 showed the same pattern. The fab unit tests pass on sqlite and Postgres 16, and the API server also behaves correctly on MySQL 8.

One behaviour change: sync_roles() no longer runs on every request, so a role created through the API without actions doesn't get can_read on Website until the next startup sync or airflow sync-perm. Roles created in the UI already work this way.

closes: #72937


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: a Gen-AI coding assistant, following the guidelines. I reviewed the change and ran the tests and the checks above locally.

The users, roles and permissions routes wrapped each request in the CLI
helper get_application_builder(), which builds a new Flask app and
AppBuilder every time and keeps each one alive through its cache. Use the
auth manager's own Flask app instead, the same way the login routes do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FAB Providers API get_application_builder cache miss trigger init_appbuilder

1 participant