From f0ec10e2f5283207c220ff2e21065e0c01454f6b Mon Sep 17 00:00:00 2001 From: LIU ZHE YOU <68415893+jason810496@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:06:47 +0800 Subject: [PATCH] AIP-84 Add filter by dag_id in recent_dag_runs (#44737) --- .../api_fastapi/core_api/openapi/v1-generated.yaml | 10 ++++++++++ airflow/api_fastapi/core_api/routes/ui/dags.py | 11 +++++++++++ airflow/ui/openapi-gen/queries/common.ts | 3 +++ airflow/ui/openapi-gen/queries/prefetch.ts | 5 +++++ airflow/ui/openapi-gen/queries/queries.ts | 5 +++++ airflow/ui/openapi-gen/queries/suspense.ts | 5 +++++ airflow/ui/openapi-gen/requests/services.gen.ts | 2 ++ airflow/ui/openapi-gen/requests/types.gen.ts | 1 + tests/api_fastapi/core_api/routes/ui/test_dags.py | 2 ++ 9 files changed, 44 insertions(+) diff --git a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml index 31268a190a75c..0cce64152674a 100644 --- a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml +++ b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml @@ -101,6 +101,16 @@ paths: items: type: string title: Owners + - name: dag_ids + in: query + required: false + schema: + anyOf: + - type: array + items: + type: string + - type: 'null' + title: Dag Ids - name: dag_id_pattern in: query required: false diff --git a/airflow/api_fastapi/core_api/routes/ui/dags.py b/airflow/api_fastapi/core_api/routes/ui/dags.py index 8fa6b126e26a4..474cc817aa2ee 100644 --- a/airflow/api_fastapi/core_api/routes/ui/dags.py +++ b/airflow/api_fastapi/core_api/routes/ui/dags.py @@ -17,6 +17,9 @@ from __future__ import annotations +from typing import Annotated + +from fastapi import Depends from sqlalchemy import and_, func, select from airflow.api_fastapi.common.db.common import ( @@ -24,6 +27,8 @@ paginated_select, ) from airflow.api_fastapi.common.parameters import ( + FilterOptionEnum, + FilterParam, QueryDagDisplayNamePatternSearch, QueryDagIdPatternSearch, QueryLastDagRunStateFilter, @@ -33,6 +38,7 @@ QueryOwnersFilter, QueryPausedFilter, QueryTagsFilter, + filter_param_factory, ) from airflow.api_fastapi.common.router import AirflowRouter from airflow.api_fastapi.core_api.datamodels.dag_run import DAGRunResponse @@ -52,6 +58,10 @@ def recent_dag_runs( offset: QueryOffset, tags: QueryTagsFilter, owners: QueryOwnersFilter, + dag_ids: Annotated[ + FilterParam[list[str] | None], + Depends(filter_param_factory(DagRun.dag_id, list[str] | None, FilterOptionEnum.IN, "dag_ids")), + ], dag_id_pattern: QueryDagIdPatternSearch, dag_display_name_pattern: QueryDagDisplayNamePatternSearch, only_active: QueryOnlyActiveFilter, @@ -104,6 +114,7 @@ def recent_dag_runs( only_active, paused, dag_id_pattern, + dag_ids, dag_display_name_pattern, tags, owners, diff --git a/airflow/ui/openapi-gen/queries/common.ts b/airflow/ui/openapi-gen/queries/common.ts index 24a17786ef6d0..f6c42d0fc14a4 100644 --- a/airflow/ui/openapi-gen/queries/common.ts +++ b/airflow/ui/openapi-gen/queries/common.ts @@ -312,6 +312,7 @@ export const UseDagsServiceRecentDagRunsKeyFn = ( { dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, @@ -323,6 +324,7 @@ export const UseDagsServiceRecentDagRunsKeyFn = ( }: { dagDisplayNamePattern?: string; dagIdPattern?: string; + dagIds?: string[]; dagRunsLimit?: number; lastDagRunState?: DagRunState; limit?: number; @@ -339,6 +341,7 @@ export const UseDagsServiceRecentDagRunsKeyFn = ( { dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, diff --git a/airflow/ui/openapi-gen/queries/prefetch.ts b/airflow/ui/openapi-gen/queries/prefetch.ts index 5b22da26ecb39..44632737a95ce 100644 --- a/airflow/ui/openapi-gen/queries/prefetch.ts +++ b/airflow/ui/openapi-gen/queries/prefetch.ts @@ -389,6 +389,7 @@ export const prefetchUseConfigServiceGetConfigValue = ( * @param data.offset * @param data.tags * @param data.owners + * @param data.dagIds * @param data.dagIdPattern * @param data.dagDisplayNamePattern * @param data.onlyActive @@ -402,6 +403,7 @@ export const prefetchUseDagsServiceRecentDagRuns = ( { dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, @@ -413,6 +415,7 @@ export const prefetchUseDagsServiceRecentDagRuns = ( }: { dagDisplayNamePattern?: string; dagIdPattern?: string; + dagIds?: string[]; dagRunsLimit?: number; lastDagRunState?: DagRunState; limit?: number; @@ -427,6 +430,7 @@ export const prefetchUseDagsServiceRecentDagRuns = ( queryKey: Common.UseDagsServiceRecentDagRunsKeyFn({ dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, @@ -440,6 +444,7 @@ export const prefetchUseDagsServiceRecentDagRuns = ( DagsService.recentDagRuns({ dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, diff --git a/airflow/ui/openapi-gen/queries/queries.ts b/airflow/ui/openapi-gen/queries/queries.ts index bc9e3412bf313..df298a9d13580 100644 --- a/airflow/ui/openapi-gen/queries/queries.ts +++ b/airflow/ui/openapi-gen/queries/queries.ts @@ -497,6 +497,7 @@ export const useConfigServiceGetConfigValue = < * @param data.offset * @param data.tags * @param data.owners + * @param data.dagIds * @param data.dagIdPattern * @param data.dagDisplayNamePattern * @param data.onlyActive @@ -513,6 +514,7 @@ export const useDagsServiceRecentDagRuns = < { dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, @@ -524,6 +526,7 @@ export const useDagsServiceRecentDagRuns = < }: { dagDisplayNamePattern?: string; dagIdPattern?: string; + dagIds?: string[]; dagRunsLimit?: number; lastDagRunState?: DagRunState; limit?: number; @@ -541,6 +544,7 @@ export const useDagsServiceRecentDagRuns = < { dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, @@ -556,6 +560,7 @@ export const useDagsServiceRecentDagRuns = < DagsService.recentDagRuns({ dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, diff --git a/airflow/ui/openapi-gen/queries/suspense.ts b/airflow/ui/openapi-gen/queries/suspense.ts index dd53b07cf87e7..9168880d8b5c5 100644 --- a/airflow/ui/openapi-gen/queries/suspense.ts +++ b/airflow/ui/openapi-gen/queries/suspense.ts @@ -472,6 +472,7 @@ export const useConfigServiceGetConfigValueSuspense = < * @param data.offset * @param data.tags * @param data.owners + * @param data.dagIds * @param data.dagIdPattern * @param data.dagDisplayNamePattern * @param data.onlyActive @@ -488,6 +489,7 @@ export const useDagsServiceRecentDagRunsSuspense = < { dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, @@ -499,6 +501,7 @@ export const useDagsServiceRecentDagRunsSuspense = < }: { dagDisplayNamePattern?: string; dagIdPattern?: string; + dagIds?: string[]; dagRunsLimit?: number; lastDagRunState?: DagRunState; limit?: number; @@ -516,6 +519,7 @@ export const useDagsServiceRecentDagRunsSuspense = < { dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, @@ -531,6 +535,7 @@ export const useDagsServiceRecentDagRunsSuspense = < DagsService.recentDagRuns({ dagDisplayNamePattern, dagIdPattern, + dagIds, dagRunsLimit, lastDagRunState, limit, diff --git a/airflow/ui/openapi-gen/requests/services.gen.ts b/airflow/ui/openapi-gen/requests/services.gen.ts index 1ae1e1e96c332..d93e584493d80 100644 --- a/airflow/ui/openapi-gen/requests/services.gen.ts +++ b/airflow/ui/openapi-gen/requests/services.gen.ts @@ -668,6 +668,7 @@ export class DagsService { * @param data.offset * @param data.tags * @param data.owners + * @param data.dagIds * @param data.dagIdPattern * @param data.dagDisplayNamePattern * @param data.onlyActive @@ -688,6 +689,7 @@ export class DagsService { offset: data.offset, tags: data.tags, owners: data.owners, + dag_ids: data.dagIds, dag_id_pattern: data.dagIdPattern, dag_display_name_pattern: data.dagDisplayNamePattern, only_active: data.onlyActive, diff --git a/airflow/ui/openapi-gen/requests/types.gen.ts b/airflow/ui/openapi-gen/requests/types.gen.ts index 9476bce9bf4f6..1451174a6eb04 100644 --- a/airflow/ui/openapi-gen/requests/types.gen.ts +++ b/airflow/ui/openapi-gen/requests/types.gen.ts @@ -1421,6 +1421,7 @@ export type GetConfigValueResponse = Config; export type RecentDagRunsData = { dagDisplayNamePattern?: string | null; dagIdPattern?: string | null; + dagIds?: Array | null; dagRunsLimit?: number; lastDagRunState?: DagRunState | null; limit?: number; diff --git a/tests/api_fastapi/core_api/routes/ui/test_dags.py b/tests/api_fastapi/core_api/routes/ui/test_dags.py index 96b09ab5f23ee..5e7cee8096cf0 100644 --- a/tests/api_fastapi/core_api/routes/ui/test_dags.py +++ b/tests/api_fastapi/core_api/routes/ui/test_dags.py @@ -73,6 +73,8 @@ def setup_dag_runs(self, session=None) -> None: ({"paused": False}, [DAG1_ID, DAG2_ID], 11), ({"owners": ["airflow"]}, [DAG1_ID, DAG2_ID], 11), ({"owners": ["test_owner"], "only_active": False}, [DAG3_ID], 4), + ({"dag_ids": [DAG1_ID]}, [DAG1_ID], 6), + ({"dag_ids": [DAG1_ID, DAG2_ID]}, [DAG1_ID, DAG2_ID], 11), ({"last_dag_run_state": "success", "only_active": False}, [DAG1_ID, DAG2_ID, DAG3_ID], 6), ({"last_dag_run_state": "failed", "only_active": False}, [DAG1_ID, DAG2_ID, DAG3_ID], 9), # Search