youngduck98 commented on code in PR #75608:
URL: https://github.com/apache/airflow/pull/75608#discussion_r4470142122
##########
airflow-core/src/airflow/ui/src/pages/Run/Header.tsx:
##########
@@ -63,8 +64,16 @@ export const Header = ({ dagRun }: { readonly dagRun:
DAGRunResponse }) => {
const dagId = dagRun.dag_id;
const dagRunId = dagRun.dag_run_id;
- const { data: alertData } = useDeadlinesServiceGetDagDeadlineAlerts({ dagId
});
- const hasDeadlineAlerts = (alertData?.total_entries ?? 0) > 0;
+ const { data: alertData } = useDeadlinesServiceGetDagDeadlineAlerts({ dagId,
dagRunId, limit: 100 });
+ const { data: deadlineData } = useDeadlinesServiceGetDeadlines({
+ dagId,
+ dagRunId,
+ limit: 10,
+ orderBy: ["deadline_time"],
+ });
Review Comment:
The existing API returns deadline records and alert definitions separately,
so i think reducing this to a single request required an API change.
In
[1b3104d6ac](https://github.com/apache/airflow/commit/1b3104d6ac27287419b136e59db3685d052c797c),
I extended the existing run deadlines endpoint with an optional include_alerts
parameter to return both together, using the alert definitions from the Dag
version that created the run.
I also updated DeadlineStatus to use the same API and query parameters as
Header so both components can share one request. Please let me know if you
would prefer a different approach.
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/deadline.py:
##########
@@ -48,18 +48,12 @@ class DeadlineResponse(BaseModel):
callback_path: str | None = Field(validation_alias=AliasPath("callback",
"data", "path"), default=None)
-class DeadlineCollectionResponse(BaseModel):
- """Deadline Collection serializer for responses."""
-
- deadlines: Iterable[DeadlineResponse]
- total_entries: int
-
-
class DeadlineAlertResponse(BaseModel):
"""DeadlineAlert serializer for responses."""
id: UUID
name: str | None = None
+ run_type_filter: list[str] | None = None
Review Comment:
Changed this to `list[DagRunType] | None` and regenerated the OpenAPI schema
and TypeScript client in
[930a300248](https://github.com/apache/airflow/pull/75608/commits/930a300248b6ca37fd21ad44a4e076d3b5991293).
##########
airflow-core/src/airflow/ui/src/pages/Dag/DeadlineAlertsBadge.test.tsx:
##########
@@ -88,4 +88,14 @@ describe("DeadlineAlertsBadge", () => {
expect(screen.queryByText(absent)).not.toBeInTheDocument();
},
);
+ it("shows the configured run type scope", async () => {
+ vi.mocked(useDeadlinesServiceGetDagDeadlineAlerts).mockReturnValue({
+ data: { deadline_alerts: [{ ...baseAlert, run_type_filter: ["scheduled"]
}], total_entries: 1 },
+ } as ReturnType<typeof useDeadlinesServiceGetDagDeadlineAlerts>);
+
+ render(<DeadlineAlertsBadge dagId="test_dag" />, { wrapper: Wrapper });
+ fireEvent.click(screen.getByRole("button"));
+
+ expect(await
screen.findByText("deadlineAlerts.appliesTo")).toBeInTheDocument();
Review Comment:
Updated the tests in
[930a300248](https://github.com/apache/airflow/pull/75608/commits/930a300248b6ca37fd21ad44a4e076d3b5991293)
to assert which run types are displayed for single-value and multiple-value
filters, and that the “Applies to” text is omitted when the filter is `null`,
since the alert applies to all run types. The existing translation mock now
preserves the interpolated `runTypes` value.
##########
airflow-core/src/airflow/ui/src/pages/Run/DeadlineStatus.tsx:
##########
@@ -23,67 +23,62 @@ import dayjs from "dayjs";
import { useTranslation } from "react-i18next";
import { FiAlertTriangle, FiCheck, FiClock } from "react-icons/fi";
-import { useDeadlinesServiceGetDagDeadlineAlerts,
useDeadlinesServiceGetDeadlines } from "openapi/queries";
-import type { DeadlineAlertResponse } from "openapi/requests/types.gen";
+import { useDeadlinesServiceGetDeadlines } from "openapi/queries";
+import type { DAGRunResponse, DeadlineAlertResponse } from
"openapi/requests/types.gen";
import { Tooltip } from "src/system-components";
import Time from "src/components/Time";
import { useDurationFormat } from "src/utils";
-import { translateCompletionRule } from "src/utils/deadlines";
+import { isDeadlineAlertApplicable, translateCompletionRule } from
"src/utils/deadlines";
import { DeadlineStatusModal } from "./DeadlineStatusModal";
type DeadlineStatusProps = {
readonly dagId: string;
readonly dagRunId: string;
readonly endDate: string | null;
+ readonly runType: DAGRunResponse["run_type"];
};
-export const DeadlineStatus = ({ dagId, dagRunId, endDate }:
DeadlineStatusProps) => {
+export const DeadlineStatus = ({ dagId, dagRunId, endDate, runType }:
DeadlineStatusProps) => {
const { t: translate } = useTranslation("dag");
const { locale, renderDuration } = useDurationFormat();
const [isModalOpen, setIsModalOpen] = useState(false);
const { data: deadlineData, isLoading: isLoadingDeadlines } =
useDeadlinesServiceGetDeadlines({
dagId,
dagRunId,
+ includeAlerts: true,
limit: 10,
orderBy: ["deadline_time"],
});
-
- // Used to detect whether the DAG has any deadline alerts at all, so we can
show "Met" when there are alerts configured but no active deadline instances.
- const { data: alertData, isLoading: isLoadingAlerts } =
useDeadlinesServiceGetDagDeadlineAlerts({
- dagId,
- limit: 100,
- });
+ const applicableAlerts = (deadlineData?.deadline_alerts ??
[]).filter((deadlineAlert) =>
+ isDeadlineAlertApplicable(deadlineAlert, runType),
+ );
Review Comment:
Added a `DeadlineStatus` test in
[930a300248](https://github.com/apache/airflow/pull/75608/commits/930a300248b6ca37fd21ad44a4e076d3b5991293).
For a manual run with no deadline records, it checks that the tooltip includes
the matching and unrestricted alert rules and excludes the scheduled-only rule.
In
[fc8a30ea61](https://github.com/apache/airflow/pull/75608/commits/fc8a30ea617f2e740d696d7789e7b017d31dcd73),
I also added a case where `manual` is the second value in the filter, plus a
backend test that checks the exact alert IDs used to create deadlines when a
Dag has a mix of filters.
##########
airflow-core/src/airflow/ui/src/pages/Run/DeadlineStatus.tsx:
##########
@@ -23,67 +23,62 @@ import dayjs from "dayjs";
import { useTranslation } from "react-i18next";
import { FiAlertTriangle, FiCheck, FiClock } from "react-icons/fi";
-import { useDeadlinesServiceGetDagDeadlineAlerts,
useDeadlinesServiceGetDeadlines } from "openapi/queries";
-import type { DeadlineAlertResponse } from "openapi/requests/types.gen";
+import { useDeadlinesServiceGetDeadlines } from "openapi/queries";
+import type { DAGRunResponse, DeadlineAlertResponse } from
"openapi/requests/types.gen";
import { Tooltip } from "src/system-components";
import Time from "src/components/Time";
import { useDurationFormat } from "src/utils";
-import { translateCompletionRule } from "src/utils/deadlines";
+import { isDeadlineAlertApplicable, translateCompletionRule } from
"src/utils/deadlines";
import { DeadlineStatusModal } from "./DeadlineStatusModal";
type DeadlineStatusProps = {
readonly dagId: string;
readonly dagRunId: string;
readonly endDate: string | null;
+ readonly runType: DAGRunResponse["run_type"];
};
-export const DeadlineStatus = ({ dagId, dagRunId, endDate }:
DeadlineStatusProps) => {
+export const DeadlineStatus = ({ dagId, dagRunId, endDate, runType }:
DeadlineStatusProps) => {
const { t: translate } = useTranslation("dag");
const { locale, renderDuration } = useDurationFormat();
const [isModalOpen, setIsModalOpen] = useState(false);
const { data: deadlineData, isLoading: isLoadingDeadlines } =
useDeadlinesServiceGetDeadlines({
dagId,
dagRunId,
+ includeAlerts: true,
limit: 10,
orderBy: ["deadline_time"],
});
-
- // Used to detect whether the DAG has any deadline alerts at all, so we can
show "Met" when there are alerts configured but no active deadline instances.
- const { data: alertData, isLoading: isLoadingAlerts } =
useDeadlinesServiceGetDagDeadlineAlerts({
- dagId,
- limit: 100,
- });
+ const applicableAlerts = (deadlineData?.deadline_alerts ??
[]).filter((deadlineAlert) =>
+ isDeadlineAlertApplicable(deadlineAlert, runType),
+ );
Review Comment:
Updated in
[c472db4905](https://github.com/apache/airflow/pull/75608/commits/c472db4905a46cc4334d1d6214572d872253fca4).
The DeadlineStatus test now checks that the tooltip includes only rules marked
`is_applicable=true` by the API. Run-type matching is covered by the Deadline
API tests, while the scheduler test still checks the exact alert IDs used to
create deadlines with mixed filters.
##########
airflow-core/src/airflow/ui/src/utils/deadlines.ts:
##########
@@ -18,10 +18,18 @@
*/
import type { TFunction } from "i18next";
-import type { DeadlineAlertResponse } from "openapi/requests/types.gen";
+import type { DAGRunResponse, DeadlineAlertResponse } from
"openapi/requests/types.gen";
import { humanizeSeconds } from "src/utils/datetimeUtils";
+export const isDeadlineAlertApplicable = (
+ alert: DeadlineAlertResponse,
+ runType: DAGRunResponse["run_type"],
+): boolean =>
+ alert.run_type_filter === null ||
+ alert.run_type_filter === undefined ||
+ alert.run_type_filter.includes(runType);
+
Review Comment:
Addressed in
[c472db4905](https://github.com/apache/airflow/pull/75608/commits/c472db4905a46cc4334d1d6214572d872253fca4).
The run deadlines API now returns `is_applicable` for each creation-version
alert definition. Both the API and deadline creation use
`DeadlineAlert.is_applicable_to_run_type()`, and I removed the run-type
matching logic from the UI.
All definitions remain in the response so stored deadline records keep their
alert metadata, even when an alert does not apply to the run's current type(i
think this can happen when rerun dagrun using backfill, which have deadline
record). The UI uses the server flag(`is_applicable`) to decide whether to show
Met and which alert rules to include in the tooltip.
Header fetches the response and passes it to DeadlineStatus. The current run
type is part of the query key, so when the UI observes a type change, it uses
the cached response for that type if available or fetches it from the API.
<details>
<summary> shape of api </summary>
```json
{
"deadlines": [
{
"alert_id": "alert-1",
"alert_name": "manual_only",
"deadline_time": "2026-11-19T15:28:10Z",
"missed": false
},
{
"alert_id": "alert-3",
"alert_name": "all_types",
"deadline_time": "2026-11-19T15:28:10Z",
"missed": false
}
],
"total_entries": 2,
"deadline_alerts": [
{
"id": "alert-1",
"name": "manual_only",
"run_type_filter": ["manual"],
"is_applicable": true
},
{
"id": "alert-2",
"name": "scheduled_only",
"run_type_filter": ["scheduled"],
"is_applicable": false
},
{
"id": "alert-3",
"name": "all_types",
"run_type_filter": null,
"is_applicable": true
}
]
}
```
if deadlines exist, show all(limit 10)
else if is_applicable exist, `Met`
else hidden
##########
airflow-core/src/airflow/ui/src/pages/Run/Header.tsx:
##########
@@ -63,8 +64,16 @@ export const Header = ({ dagRun }: { readonly dagRun:
DAGRunResponse }) => {
const dagId = dagRun.dag_id;
const dagRunId = dagRun.dag_run_id;
- const { data: alertData } = useDeadlinesServiceGetDagDeadlineAlerts({ dagId
});
- const hasDeadlineAlerts = (alertData?.total_entries ?? 0) > 0;
+ const { data: deadlineData } = useDeadlinesServiceGetDeadlines({
+ dagId,
+ dagRunId,
+ includeAlerts: true,
Review Comment:
Updated in
[c472db4905](https://github.com/apache/airflow/pull/75608/commits/c472db4905a46cc4334d1d6214572d872253fca4).
Header now owns the combined query and passes its response to DeadlineStatus
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]