-
Notifications
You must be signed in to change notification settings - Fork 17.5k
feat: Add dagrun status progress to backfills #64089
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| from collections import defaultdict | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from sqlalchemy import func, select | ||
|
|
||
| from airflow.api_fastapi.core_api.datamodels.backfills import BackfillResponse | ||
| from airflow.models import DagRun | ||
| from airflow.models.backfill import BackfillDagRun | ||
|
|
||
| if TYPE_CHECKING: | ||
| from sqlalchemy.orm import Session | ||
|
|
||
|
|
||
| def enrich_backfill_responses( | ||
| backfills: list[BackfillResponse], | ||
| *, | ||
| session: Session, | ||
| ) -> list[BackfillResponse]: | ||
| """Populate num_runs and dag_run_state_counts on each backfill response.""" | ||
| ids = [b.id for b in backfills] | ||
| if not ids: | ||
| return backfills | ||
| # Single query: get state counts per backfill, derive num_runs by summing counts. | ||
| rows = session.execute( | ||
| select( | ||
| BackfillDagRun.backfill_id, | ||
| DagRun.state, | ||
| func.count().label("count"), | ||
| ) | ||
| .join(DagRun, BackfillDagRun.dag_run_id == DagRun.id) | ||
| .where( | ||
| BackfillDagRun.backfill_id.in_(ids), | ||
| DagRun.backfill_id == BackfillDagRun.backfill_id, | ||
| DagRun.state.is_not(None), | ||
| ) | ||
| .group_by(BackfillDagRun.backfill_id, DagRun.state) | ||
| ).all() | ||
| counts: dict[int, dict[str, int]] = defaultdict(dict) | ||
| num_runs: dict[int, int] = defaultdict(int) | ||
| for backfill_id, state, count in rows: | ||
| counts[backfill_id][str(state)] = count | ||
| num_runs[backfill_id] += count | ||
| for backfill in backfills: | ||
| backfill.num_runs = num_runs.get(backfill.id, 0) | ||
| backfill.dag_run_state_counts = dict(counts.get(backfill.id, {})) | ||
| return backfills |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -9321,6 +9321,16 @@ components: | |||
| dag_display_name: | ||||
| type: string | ||||
| title: Dag Display Name | ||||
| num_runs: | ||||
| type: integer | ||||
| title: Num Runs | ||||
| default: 0 | ||||
| dag_run_state_counts: | ||||
| additionalProperties: | ||||
| type: integer | ||||
| type: object | ||||
| title: Dag Run State Counts | ||||
| default: {} | ||||
|
||||
| default: {} |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -147,6 +147,10 @@ export type BackfillResponse = { | |||||
| completed_at: string | null; | ||||||
| updated_at: string; | ||||||
| dag_display_name: string; | ||||||
| num_runs?: number; | ||||||
| dag_run_state_counts?: { | ||||||
| [key: string]: (number); | ||||||
|
||||||
| [key: string]: (number); | |
| [key: string]: number; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1155,6 +1155,8 @@ class BackfillResponse(BaseModel): | |
| completed_at: Annotated[datetime | None, Field(title="Completed At")] = None | ||
| updated_at: Annotated[datetime, Field(title="Updated At")] | ||
| dag_display_name: Annotated[str, Field(title="Dag Display Name")] | ||
| num_runs: Annotated[int | None, Field(title="Num Runs")] = 0 | ||
| dag_run_state_counts: Annotated[dict[str, int] | None, Field(title="Dag Run State Counts")] = {} | ||
|
Comment on lines
+1158
to
+1159
|
||
|
|
||
|
|
||
| class BulkCreateActionConnectionBody(BaseModel): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR updates
_private_ui.yaml(an OpenAPI artifact) directly. Please ensure this file is regenerated via the repo’s OpenAPI generation process rather than hand-edited, to keep generated specs consistent and reproducible.