bbovenzi commented on code in PR #75608:
URL: https://github.com/apache/airflow/pull/75608#discussion_r4484769013
##########
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:
Let's add a test to for checking applicableAlerts to make sure it is
filtering properly
##########
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:
```suggestion
run_type_filter: list[DagRunType] | None = None
```
##########
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:
We aren't actually testing if any run types appear so this filter could be
empty. Let's test that 1-2 run types appear or that we don't show it when
`run_type_filter: null`
--
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]