Repository navigation
Show Dag bundle versions and refresh times in the UI - #72909
Conversation
26e9012 to
16884e0
Compare
|
It would be great to have a button in this UI to run the |
16884e0 to
d4cc8c0
Compare
d4cc8c0 to
754f6d6
Compare
fca2d1f to
5c3248b
Compare
ephraimbuddy
left a comment
There was a problem hiding this comment.
The added browser tests remain smoke checks: removing polling would leave them green. Tests also still miss denial of Dag VERSION access, and two import-error tests duplicate the same scenario.
Add a read-only GET /api/v2/dagBundles endpoint and a Dag Bundles page under Browse, listing each bundle with the version Airflow currently holds, when a Dag processor last refreshed it, its import-error count, and whether it is still configured. Dag authors deploying code had no way to tell whether Airflow had picked up their commit short of reloading the Dags page until import errors or file details changed -- and where Dag code viewing is disabled, not even that. Per-Dag views cover less than they appear to: when every Dag in a commit fails to import no serialization runs at all, so DagVersion.bundle_version stays pinned to the last good commit while the bundle has plainly moved on. last_refreshed exists nowhere else per bundle, and neither view answers "has anything landed" without already knowing which Dag to look at. A bundle is visible to a caller who can read at least one Dag recorded against it, so no new authorization resource is introduced. import_error_count is counted on the same terms as GET /importErrors -- errors in files the caller can read no Dag in are excluded, and errors in files that never registered a Dag need the admin-by-default view -- and bundle_url is withheld from callers who may not read Dag versions. The page polls at the configured auto-refresh interval, floored at ten seconds since a bundle row changes at most once per its refresh interval, and stops entirely when a deployment sets that interval to zero. Also fixes a latent crash in DagBundleModel.render_url, which guarded str.format against KeyError and ValueError only. A view_url_template is deployment-supplied and unvalidated, so a positional placeholder raises IndexError, an attribute placeholder AttributeError, and a null version makes subscript and format-spec placeholders raise TypeError -- reachable today through DagVersion.bundle_url on the dagVersions endpoint.
Addresses review feedback on the Dag Bundles page.
Deriving bundle visibility from readable Dags hid a bundle with no registered
Dag from everyone, admins included. That is the first-deploy-is-broken case:
configure a bundle, push a file that fails to import, and the bundle never
appears, so the import-error count added to diagnose exactly that is
unreachable. Such a bundle has no Dag to authorize against, so it is now gated
on the admin-by-default AccessView.IMPORT_ERRORS_ALL, the same view that governs
import errors for a file that never registered a Dag. The disjunct is additive
and stays in SQL, so Dag scoping still applies to every bundle that does have
Dags, and pagination and total_entries remain correct.
render_url guarded the no-version case with a "{version" substring test, which
also matches an escaped "{{version}}" and an unrelated "{version_label}" param.
Both render fine without a version, so the link was dropped when it should not
have been. Field names now come from string.Formatter().parse.
The docs claimed the version and import-error count together tell you whether a
commit parsed. They do not: errors are not recorded against a version, a file
whose parse exceeds dag_file_processor_timeout is killed without writing an
import-error row, and the count only covers errors the reader may see. Reworded,
and added a note that the Browse entry needs a FAB provider release carrying the
menu-item mapping, since without it the entry is hidden for every role.
Adds Playwright coverage for the page, which every sibling Browse page already
had. The page object addresses cells by column id rather than position, so
multi_team and the column-visibility menu cannot silently shift them.
Addresses the second round of review. Deciding Dag-less bundle visibility with one unscoped IMPORT_ERRORS_ALL check was wrong in both directions under a team-aware policy: a caller granted the unscoped view saw every team's Dag-less bundles, and a caller granted only their own team's saw none. The names are now resolved before pagination and authorized one at a time against each bundle's own team, then passed into the query as an allow-list, which is what get_import_errors already does for a file with no registered Dag. The team lookup is the existing batched get_team_names. Keycloak's TEAM_MENU_ITEMS omitted the new menu item, so team Viewer, User, Op and Admin roles could reach the bundles through the API but never find the page under Browse. It sits with DAGS in the base team set rather than the admin one, since bundle visibility rides on Dag read, and is guarded for Airflow versions predating the item. The browser tests only checked the initial render, so deleting the refetch logic left them green. Vitest fake-timer coverage now pins the ten-second floor, a longer configured interval, zero disabling refresh, and a changed row appearing after a tick; removing the interval fails three of the four. The Browse navigation check stays in Playwright. Also adds the missing case where a caller may read a Dag but not its versions, asserting the bundle stays listed with a null url, and folds two import-error tests that asserted the same thing into one that says which restriction each exclusion depends on.
5c3248b to
8e53572
Compare
… item The provider compatibility jobs run the Keycloak tests against Airflow 3.0.6 through 3.3.1, where MenuItem has no DAG_BUNDLES member. The source already handled that: the hasattr guard leaves the item out of TEAM_MENU_ITEMS. The test did not, hard-coding "Dag Bundles" into the expected grants, so all four compat jobs failed on a list the source was right to omit. The expected resource names now follow the same guard the source does, so they describe the grant on whichever Airflow is under test while still pinning the rest of the list and its ordering.
Backport failed to create: airflow-ctl/v0-1-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker d57b249 airflow-ctl/v0-1-testThis should apply the commit to the airflow-ctl/v0-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
Problem
A Dag author pushes a commit and then has no way to tell whether Airflow has picked it up. The workflow today is: commit, push, then reload the Dags page until the import errors or the file details change. In deployments where Dag code viewing is disabled there is not even that -- the author is left guessing, including guessing what the bundle refresh interval is set to.
Nothing in the UI or the REST API exposes Dag bundle state, even though the
dag_bundletable has recorded the version and the last refresh time since Airflow 3.0.A per-Dag check covers less than it appears to.
GET /dags/{dag_id}/dagVersionsdoes report the new SHA for an ordinary commit, including one that leaves serialization untouched --SerializedDagModel.write_dagrefreshes the existingDagVersion'sbundle_versionin place on that path. What it cannot report is the case that matters most here: when every Dag in the commit fails to import, nowrite_dagruns at all, soDagVersion.bundle_versionstays pinned to the last good commit while the bundle has plainly moved on. Alongside that,last_refreshedexists nowhere else per bundle, and neither view answers "has anything landed" without already knowing which Dag to look at.Solution
GET /api/v2/dagBundleslists each bundle with the version Airflow currently holds, when a Dag processor last refreshed it, how many Dag import errors it has, its owning team, and whether it is still configured. A Dag Bundles page under Browse renders that and refreshes itself while open.versionnullfor bundles that do not support versioning.last_refreshedimport_error_countnullwhen the caller may not read import errors -- deliberately not0.bundle_urlversion, when one is configured.Read-only on purpose. This adds no way to create, delete, enable or disable a bundle, so it introduces no new role and no new writable configuration surface -- it reads rows the Dag processor already writes. That keeps it clear of the objection raised on #61645, which is about runtime mutation of bundle configuration.
The endpoint also makes "wait until my commit is live" scriptable from a deployment pipeline, which is the other half of the same problem:
What it looks like
Pushing a commit and watching the row pick it up, with no reload and no navigation -- everything that changes on screen comes from the page's own polling:
A commit whose Dag fails to import. The version advances, because the fetch itself succeeded; the import-error count beside it is what says the new code is not actually running:
The version links to the commit it names, and a bundle dropped from the configuration keeps its last version and timestamp, flagged rather than removed:
Authorization -- the decision I would most like a second opinion on
A bundle is visible to a caller who can read at least one Dag recorded against it. The route carries
requires_access_dag(method="GET"), and rows are filtered byPermittedDagBundleFilter, which is the existingPermittedDagFilterpattern applied todag_bundlevia the Dags inside it.I deliberately did not add an
AccessView.DAG_BUNDLES. It is the house style for admin-ish read views (Jobs, Plugins, Providers), and the enum's own comments explain why bundle-shaped things get one: there is no per-Dag key to authorize on. But it needs a FABRESOURCE_DAG_BUNDLEseeded into roles, and seeding that admin- or op-only locks out the Dag authors this exists for.I also rejected authorizing on
is_authorized_dag(method="GET", details=DagDetails(id=None, team_name=...)), which was my first design. FAB treatsmethod="GET"with nodetails.idas "may this user list Dags", which_is_authorized_list_dagsanswersTruefor anyone holding read on a single Dag, and FAB ignoresteam_nameoutright. Under that design one Dag's worth of access would have exposed every bundle in the deployment,bundle_urlincluded -- the Git host, org and path of every other team's private repository. Today a rendered bundle URL is only reachable per-Dag through/dags/{dag_id}/dagVersions, so that would have been a genuine widening. Deriving the filter from readable Dags instead behaves identically across FAB, SimpleAuthManager and Keycloak rather than one of them silently opting out.POST /api/v2/dagBundles/{bundle_name}/refreshin #72715 faces the same question and asked it of maintainers without an answer, so I am raising it rather than treating either choice as settled. If the answer is a dedicated resource, the change is contained to one dependency.Two consequences of the Dag-derived filter, both documented:
DagModelrow still names it. That is intentional: it is exactly when someone wants to see the bundle still being refreshed.What this does not do
bundle.refresh()raising is caught and logged, leavinglast_refreshedat its last success with no error marker anywhere ondag_bundle, so "failing for an hour" looks identical to "not due yet". The docs say so plainly and give the two checks that do not need the refresh interval: compare a bundle against the other rows, since one processor refreshes all the bundles it owns in the same loop; and/api/v2/jobs?job_type=DagProcessorJobfor whether a responsible processor is alive. Alast_refresh_errorcolumn would fix it properly and is follow-up work -- it is a migration ondag_bundle, and Allow API clients to refresh Dag bundles #72715 is contesting that same table.refresh_intervalis not exposed. Reading it in the api-server meansimport_stringon provider bundle classes in a process that has no other reason to load bundle config. The livelast_refreshedand a per-bundle refresh trigger answer the underlying question better than an interval does.activefilter, no name search, no single-bundle route. Nothing on the page needs them.bundle_namefilter in the API but not in the UI, so wiring both is a follow-up.Related: #61645, #72715, #60616.