Repository navigation
Add a Dag bundle detail page listing the files in the bundle - #73009
Conversation
4b6811a to
c0b2f0d
Compare
amoghrajesh
left a comment
There was a problem hiding this comment.
I wonder if we could use better UX for the import error button, on a file inside bundle. The 1 inside the box isnt too intuitive to be a clickable to me.
Needs a rebase otherwise mostly fine
c0b2f0d to
8ac2036
Compare
Rebased, and updated the UX. Now, its an outlined button with a warning icon and a label now, "View error" (or "View N errors"), which lines up with how the dashboard shows import errors. Refreshed the screenshots in the description. wdyt? |
8ac2036 to
58ae683
Compare
Add GET /api/v2/dagBundles/{bundle_name} and
GET /api/v2/dagBundles/{bundle_name}/files, and a page behind each row of the Dag
Bundles list showing the bundle's files with the Dags each one defines, when it
was last parsed, how long that took, and its import-error count.
The list view answers "has my commit landed" but not "what in it is broken". The
gap it cannot close is a file that fails before defining a Dag: there is no
DagModel row for it, so no per-Dag view in the UI mentions it, and the bundle's
import-error count says only that something is wrong. That file is exactly what
someone opens this page to find.
Files therefore come from two sources. Files holding a Dag the caller may read
are aggregated from dag, which is also the only record of parse time and
duration Airflow keeps -- a file whose Dags were all removed keeps none of its
own. Files that recorded an import error without registering a Dag are added on
the same admin-by-default terms as GET /importErrors, since they have no Dag to
authorize on. The two halves are merged in the api-server rather than unioned in
the database: they differ in shape and in authorization, and the set being merged
is one bundle's files.
Dag rows are never deleted, which decides what the counts can mean. A file that
fails to import has every Dag in it marked stale by
update_dag_parsing_results_in_db, and a file dropped from the bundle has the same
done by deactivate_deleted_dags. So dag_count counts live Dags only, agreeing
with GET /dags, which excludes stale Dags by default -- counting them would
over-report in the one case the page exists to diagnose. A file then stays listed
on the strength of a live Dag or an import error, rather than of a Dag row: a
file that has just broken keeps its row instead of vanishing, and a file deleted
long ago drops out instead of lingering with a count of Dags that no longer
exist.
A file's import-error count opens the stack trace behind it, read through
GET /importErrors rather than returned with the file list: a stack trace is
unbounded and the file list is polled, and that endpoint already decides who may
read an import error. It renders in DagImportErrorModal, which moves from
pages/Dag to components now that a second page uses it -- components already
reached across into pages for it, which was backwards.
Staleness decides the parse columns too. last_parsed_time is the file's last
known parse, so a broken file still says when it last worked, while
last_parse_duration is taken from live rows only: a Dag removed from a file keeps
its row frozen at an older, slower parse, and an unrestricted MAX would pair that
duration with the newer timestamp and report a parse that never happened.
Both routes resolve the bundle through the same filter the collection route uses,
so a bundle holding no registered Dag is reachable on exactly the terms the
collection grants it, and a bundle the caller may not see is a 404 rather than a
403 -- a response cannot be used to confirm which bundle names a deployment has.
Neither the bundle classpath nor its configured kwargs are exposed. The classpath
would mean reading dag_bundle_config_list in the api-server, which is the reason
refresh_interval stayed out, and bundle kwargs are free-form and a plausible home
for credentials.
58ae683 to
3311783
Compare
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 3a94412 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. |


Builds on #72909, which adds the Dag Bundles list. This adds the page behind each row.
Summary
GET /api/v2/dagBundles/{bundle_name}andGET /api/v2/dagBundles/{bundle_name}/files, plus a detail page showing a bundle's files with the Dags each one defines, when it was last parsed, how long that took, and its import-error count.Clicking a file's error count opens the stack trace behind it:
The bundle name on the list is now a link into it:
Why the list alone is not enough
The list answers "has my commit landed". It does not answer "what in it is broken", and there is one case where nothing else in the UI answers it either: a file that fails before defining a Dag. There is no
DagModelrow for it, so no per-Dag view mentions it, and the bundle's import-error count says only that something somewhere is wrong. That file is exactly what someone opens this page to find, and it is the first row in the screenshot above.Design rationale
The file list has two sources. Files holding a Dag the caller may read are aggregated from
dag. Files that recorded an import error without registering a Dag are added separately, because they have no Dag to authorize on, on the same admin-by-default terms asGET /importErrors.Parse times come from the Dags in the file, not the file. That is the only record Airflow keeps: a file whose Dags were all removed keeps no parse time of its own.
The stack trace is read through
GET /importErrors, not returned with the file list. A stack trace is unbounded and the file list is polled, so shipping one per row would bloat a request made every ten seconds. That endpoint already hasbundle_nameandfilenamefilters and already decides who may read an import error, so this adds no endpoint and no authorization surface. It renders inDagImportErrorModal, which moves frompages/Dagtocomponentsnow that a second page uses it --components/DagDeactivatedBannerwas already reaching across intopagesfor it, which was backwards. A dialog rather than a page of its own, because a single stack trace is not worth an addressable route.dag_countcounts live Dags, and a file is listed on the strength of a live Dag or an error. Dag rows are never deleted. A file that fails to import has every Dag in it marked stale byupdate_dag_parsing_results_in_db, and a file dropped from the bundle gets the same fromdeactivate_deleted_dags. Counting stale rows would over-report in the one case this page exists to diagnose, and would disagree withGET /dags, which excludes stale Dags by default. Keying the listing on staleness alone would be worse in the other direction: a file that had just broken would vanish from the page opened to find out why. Hence the two conditions, which is also whyfirst.pyin the screenshot shows 0 Dags, a stale parse time from when it last worked, and an error.Both routes 404 rather than 403 for a bundle that exists but holds no readable Dag, so a response cannot be used to confirm which bundle names a deployment has.
Alternatives considered
A SQL
UNION ALLfor the two halves of the file list. Rejected: the halves differ in both shape and authorization, the union needs typedNULLcasts to line the columns up across dialects, and the set being merged is one bundle's files. Merging in the api-server is the smaller thing to read. The cost is that the whole file list is read to answer one page, which the endpoint's docstring says.A separate "Import errors" section instead of folding error-only files into the table. Two tables with clean semantics each, but it splits "what is in this bundle and is it healthy" across two places, and the interesting row is precisely the one that would move to the second table.
Exposing the bundle classpath and its configured kwargs. Both are in the prototype this is modelled on, and both are left out. The classpath means reading
dag_bundle_config_listin the api-server, which is the reasonrefresh_intervalstayed out of #72909. Bundle kwargs are free-form and a plausible home for credentials, so rendering them into a response is a leak waiting to happen.A third-level page per file. The file row already carries everything the page has to say about that file, and its error opens in place, so a separate route would add a URL for a page with nothing extra on it.
Goal alignment
Airflow already records every field here. Nothing new is written, there is no migration, no new role, and no new writable surface: this reads
dag,dag_bundleandimport_errorrows the Dag processor already maintains. It is the same read-only shape as #72909, which keeps it clear of the objection on #61645 about runtime mutation of bundle configuration.Anticipated objections
"Why no
order_by?" The rows are assembled outside the database, so aSortParambound to a model cannot order them and the endpoint takes no sort parameter rather than pretending to. Files are returned ordered by path and the table declares no sortable columns. Server-side sorting is worth adding when someone has a bundle where it matters."Is
dag_counton the detail response not just the file list's total?" No.dag_countcounts Dags; the file total counts files, and includes error-only files the Dag count cannot see.Gotchas
import_error_countper file is at most 1, sinceimport_errorholds one row per file.Follow-ups
DagVersion.bundle_version. Worth doing with a clear label, because it has the blind spot Show Dag bundle versions and refresh times in the UI #72909 describes: a commit whose every Dag failed to import never produces aDagVersionrow.bundle_namefilter; the UI does not yet.