youngduck98 commented on code in PR #75608:
URL: https://github.com/apache/airflow/pull/75608#discussion_r4657778315


##########
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 
[9d555518d9](https://github.com/apache/airflow/pull/75608/commits/9d555518d961de9ccb7aad09c2dd0b9e8e27c6a9).
 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/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 
[9d555518d9](https://github.com/apache/airflow/pull/75608/commits/9d555518d961de9ccb7aad09c2dd0b9e8e27c6a9).
 Header now owns the combined query and passes its response to DeadlineStatus



##########
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 
[9d555518d9](https://github.com/apache/airflow/pull/75608/commits/9d555518d961de9ccb7aad09c2dd0b9e8e27c6a9).
 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



-- 
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]

Reply via email to