From 49b8162f837309df9bd10bf2a6387f2f04cb4654 Mon Sep 17 00:00:00 2001 From: Burak Karakan Date: Thu, 20 Jul 2023 00:40:21 +0100 Subject: [PATCH 1/3] add dag_run_ids and task_ids as filter types for the batch task instance endpoint --- .../endpoints/task_instance_endpoint.py | 2 ++ airflow/api_connexion/openapi/v1.yaml | 16 ++++++++++ .../schemas/task_instance_schema.py | 2 ++ airflow/www/static/js/types/api-generated.ts | 10 +++++++ .../endpoints/test_task_instance_endpoint.py | 30 +++++++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/airflow/api_connexion/endpoints/task_instance_endpoint.py b/airflow/api_connexion/endpoints/task_instance_endpoint.py index ab4b24f8f27cc..a18514696ba39 100644 --- a/airflow/api_connexion/endpoints/task_instance_endpoint.py +++ b/airflow/api_connexion/endpoints/task_instance_endpoint.py @@ -400,6 +400,8 @@ def get_task_instances_batch(session: Session = NEW_SESSION) -> APIResponse: base_query = select(TI).join(TI.dag_run) base_query = _apply_array_filter(base_query, key=TI.dag_id, values=data["dag_ids"]) + base_query = _apply_array_filter(base_query, key=TI.run_id, values=data["dag_run_ids"]) + base_query = _apply_array_filter(base_query, key=TI.task_id, values=data["task_ids"]) base_query = _apply_range_filter( base_query, key=DR.execution_date, diff --git a/airflow/api_connexion/openapi/v1.yaml b/airflow/api_connexion/openapi/v1.yaml index b3b4a0f5f0ea4..c968e8d11ea5d 100644 --- a/airflow/api_connexion/openapi/v1.yaml +++ b/airflow/api_connexion/openapi/v1.yaml @@ -4409,6 +4409,22 @@ components: description: Return objects with specific DAG IDs. + The value can be repeated to retrieve multiple matching values (OR condition). + dag_run_ids: + type: array + items: + type: string + description: + Return objects with specific DAG Run IDs. + + The value can be repeated to retrieve multiple matching values (OR condition). + task_ids: + type: array + items: + type: string + description: + Return objects with specific task IDs. + The value can be repeated to retrieve multiple matching values (OR condition). execution_date_gte: type: string diff --git a/airflow/api_connexion/schemas/task_instance_schema.py b/airflow/api_connexion/schemas/task_instance_schema.py index c929da30990ce..a3ce7c6a62e4a 100644 --- a/airflow/api_connexion/schemas/task_instance_schema.py +++ b/airflow/api_connexion/schemas/task_instance_schema.py @@ -100,6 +100,8 @@ class TaskInstanceBatchFormSchema(Schema): page_offset = fields.Int(load_default=0, validate=validate.Range(min=0)) page_limit = fields.Int(load_default=100, validate=validate.Range(min=1)) dag_ids = fields.List(fields.Str(), load_default=None) + dag_run_ids = fields.List(fields.Str(), load_default=None) + task_ids = fields.List(fields.Str(), load_default=None) execution_date_gte = fields.DateTime(load_default=None, validate=validate_istimezone) execution_date_lte = fields.DateTime(load_default=None, validate=validate_istimezone) start_date_gte = fields.DateTime(load_default=None, validate=validate_istimezone) diff --git a/airflow/www/static/js/types/api-generated.ts b/airflow/www/static/js/types/api-generated.ts index f791db4385a63..18b2481f2a11e 100644 --- a/airflow/www/static/js/types/api-generated.ts +++ b/airflow/www/static/js/types/api-generated.ts @@ -1983,6 +1983,16 @@ export interface components { * The value can be repeated to retrieve multiple matching values (OR condition). */ dag_ids?: string[]; + /** + * @description Return objects with specific DAG Run IDs. + * The value can be repeated to retrieve multiple matching values (OR condition). + */ + dag_run_ids?: string[]; + /** + * @description Return objects with specific task IDs. + * The value can be repeated to retrieve multiple matching values (OR condition). + */ + task_ids?: string[]; /** * Format: date-time * @description Returns objects greater or equal to the specified date. diff --git a/tests/api_connexion/endpoints/test_task_instance_endpoint.py b/tests/api_connexion/endpoints/test_task_instance_endpoint.py index a8c4c8b10a232..f39fad6d6e974 100644 --- a/tests/api_connexion/endpoints/test_task_instance_endpoint.py +++ b/tests/api_connexion/endpoints/test_task_instance_endpoint.py @@ -778,6 +778,36 @@ class TestGetTaskInstancesBatch(TestTaskInstanceEndpoint): "test", id="with execution date filter", ), + pytest.param( + [ + {"execution_date": DEFAULT_DATETIME_1}, + {"execution_date": DEFAULT_DATETIME_1 + dt.timedelta(days=1)}, + {"execution_date": DEFAULT_DATETIME_1 + dt.timedelta(days=2)}, + {"execution_date": DEFAULT_DATETIME_1 + dt.timedelta(days=3)}, + ], + False, + { + "dag_run_ids": ["TEST_DAG_RUN_ID_0", "TEST_DAG_RUN_ID_1"], + }, + 2, + "test", + id="test dag run id filter", + ), + pytest.param( + [ + {"execution_date": DEFAULT_DATETIME_1}, + {"execution_date": DEFAULT_DATETIME_1 + dt.timedelta(days=1)}, + {"execution_date": DEFAULT_DATETIME_1 + dt.timedelta(days=2)}, + {"execution_date": DEFAULT_DATETIME_1 + dt.timedelta(days=3)}, + ], + False, + { + "task_ids": ["print_the_context", "log_sql_query"], + }, + 2, + "test", + id="test task id filter", + ), ], ) def test_should_respond_200( From c62506ec8508b4d7af5593ffb8df52732d690964 Mon Sep 17 00:00:00 2001 From: Burak Karakan Date: Mon, 24 Jul 2023 15:14:12 +0100 Subject: [PATCH 2/3] add version notice to the new filters --- airflow/api_connexion/openapi/v1.yaml | 4 ++++ airflow/www/static/js/types/api-generated.ts | 2 ++ 2 files changed, 6 insertions(+) diff --git a/airflow/api_connexion/openapi/v1.yaml b/airflow/api_connexion/openapi/v1.yaml index c968e8d11ea5d..372769bbd7733 100644 --- a/airflow/api_connexion/openapi/v1.yaml +++ b/airflow/api_connexion/openapi/v1.yaml @@ -4418,6 +4418,8 @@ components: Return objects with specific DAG Run IDs. The value can be repeated to retrieve multiple matching values (OR condition). + + *New in version 2.6.4* task_ids: type: array items: @@ -4426,6 +4428,8 @@ components: Return objects with specific task IDs. The value can be repeated to retrieve multiple matching values (OR condition). + + *New in version 2.6.4* execution_date_gte: type: string format: date-time diff --git a/airflow/www/static/js/types/api-generated.ts b/airflow/www/static/js/types/api-generated.ts index 18b2481f2a11e..f84d1bccc495f 100644 --- a/airflow/www/static/js/types/api-generated.ts +++ b/airflow/www/static/js/types/api-generated.ts @@ -1986,11 +1986,13 @@ export interface components { /** * @description Return objects with specific DAG Run IDs. * The value can be repeated to retrieve multiple matching values (OR condition). + * *New in version 2.6.4* */ dag_run_ids?: string[]; /** * @description Return objects with specific task IDs. * The value can be repeated to retrieve multiple matching values (OR condition). + * *New in version 2.6.4* */ task_ids?: string[]; /** From 78c5de0ce9eb4ea46f31cdcdb170ab47ef01ce45 Mon Sep 17 00:00:00 2001 From: pierrejeambrun Date: Sat, 5 Aug 2023 15:52:51 +0200 Subject: [PATCH 3/3] Update the released version in OpenAPI spec --- airflow/api_connexion/openapi/v1.yaml | 4 ++-- airflow/www/static/js/types/api-generated.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/airflow/api_connexion/openapi/v1.yaml b/airflow/api_connexion/openapi/v1.yaml index 372769bbd7733..da7dca04f64c5 100644 --- a/airflow/api_connexion/openapi/v1.yaml +++ b/airflow/api_connexion/openapi/v1.yaml @@ -4419,7 +4419,7 @@ components: The value can be repeated to retrieve multiple matching values (OR condition). - *New in version 2.6.4* + *New in version 2.7.1* task_ids: type: array items: @@ -4429,7 +4429,7 @@ components: The value can be repeated to retrieve multiple matching values (OR condition). - *New in version 2.6.4* + *New in version 2.7.1* execution_date_gte: type: string format: date-time diff --git a/airflow/www/static/js/types/api-generated.ts b/airflow/www/static/js/types/api-generated.ts index f84d1bccc495f..e2d38d072597e 100644 --- a/airflow/www/static/js/types/api-generated.ts +++ b/airflow/www/static/js/types/api-generated.ts @@ -1986,13 +1986,13 @@ export interface components { /** * @description Return objects with specific DAG Run IDs. * The value can be repeated to retrieve multiple matching values (OR condition). - * *New in version 2.6.4* + * *New in version 2.7.1* */ dag_run_ids?: string[]; /** * @description Return objects with specific task IDs. * The value can be repeated to retrieve multiple matching values (OR condition). - * *New in version 2.6.4* + * *New in version 2.7.1* */ task_ids?: string[]; /**