Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIP-84: Migrating GET Dataset events for DAG runs api to fastAPI #43874

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cf5218c
AIP-84: Migrating GET Assets to fastAPI
amoghrajesh Nov 6, 2024
5a49280
matching response to legacy
amoghrajesh Nov 6, 2024
962572b
Adding unit tests - part 1
amoghrajesh Nov 8, 2024
428cb6c
Update airflow/api_fastapi/common/parameters.py
amoghrajesh Nov 8, 2024
a78d3cb
fixing the dag_ids filter
amoghrajesh Nov 8, 2024
882d20c
fixing the dag_ids filter
amoghrajesh Nov 8, 2024
25bb08e
Adding unit tests - part 2
amoghrajesh Nov 8, 2024
658479d
Merge branch 'main' into AIP84-get-asset-to-fastapi
amoghrajesh Nov 8, 2024
fa0cd23
fixing unit tests & updating parameter type
amoghrajesh Nov 8, 2024
dd791c2
review comments pierre
amoghrajesh Nov 8, 2024
06fa0a7
fixing last commit
amoghrajesh Nov 8, 2024
3bd803b
Merge branch 'main' into AIP84-get-asset-to-fastapi
amoghrajesh Nov 8, 2024
fc29d7d
Merge branch 'main' into AIP84-get-asset-to-fastapi
amoghrajesh Nov 8, 2024
7a97220
fixing unit tests
amoghrajesh Nov 9, 2024
df1ff8e
AIP-84: Migrating GET Dataset events for DAG runs to fastAPI
amoghrajesh Nov 11, 2024
6c80ced
adding test cases
amoghrajesh Nov 11, 2024
e344263
adding test cases
amoghrajesh Nov 11, 2024
0df9ebd
Merge branch 'main' into AIP84-get-asset-to-fastapi
amoghrajesh Nov 12, 2024
5fb8bc1
Merge branch 'main' into AIP84-get-asset-to-fastapi
amoghrajesh Nov 12, 2024
6426b0b
Merge branch 'AIP84-get-asset-to-fastapi' into AIP84-get-dataset-even…
amoghrajesh Nov 12, 2024
80c4da0
Merge branch 'main' into AIP84-get-dataset-events-dagrun
amoghrajesh Nov 13, 2024
e7b96aa
review comments pierre
amoghrajesh Nov 13, 2024
c4d7dfc
fixing unit tests
amoghrajesh Nov 13, 2024
e269dd3
Merge branch 'main' into AIP84-get-dataset-events-dagrun
amoghrajesh Nov 14, 2024
0da44d0
review comments pierre
amoghrajesh Nov 14, 2024
75a387e
Merge branch 'main' into AIP84-get-dataset-events-dagrun
amoghrajesh Nov 14, 2024
f93032c
review comments and fixing a test
amoghrajesh Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airflow/api_connexion/endpoints/dag_run_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def get_dag_run(
raise BadRequest("DAGRunSchema error", detail=str(e))


@mark_fastapi_migration_done
@security.requires_access_dag("GET", DagAccessEntity.RUN)
@security.requires_access_asset("GET")
@provide_session
Expand Down
2 changes: 1 addition & 1 deletion airflow/api_fastapi/core_api/datamodels/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DagRunAssetReference(BaseModel):
dag_id: str
execution_date: datetime = Field(alias="logical_date")
start_date: datetime
end_date: datetime
end_date: datetime | None
state: str
data_interval_start: datetime
data_interval_end: datetime
Expand Down
58 changes: 56 additions & 2 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,58 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/dags/{dag_id}/dagRuns/{dag_run_id}/upstreamAssetEvents:
get:
tags:
- DagRun
summary: Get Upstream Asset Events
description: If dag run is asset-triggered, return the asset events that triggered
it.
operationId: get_upstream_asset_events
parameters:
- name: dag_id
in: path
required: true
schema:
type: string
title: Dag Id
- name: dag_run_id
in: path
required: true
schema:
type: string
title: Dag Run Id
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/AssetEventCollectionResponse'
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/dagSources/{file_token}:
get:
tags:
Expand Down Expand Up @@ -4817,8 +4869,10 @@ components:
format: date-time
title: Start Date
end_date:
type: string
format: date-time
anyOf:
- type: string
format: date-time
- type: 'null'
title: End Date
state:
type: string
Expand Down
33 changes: 33 additions & 0 deletions airflow/api_fastapi/core_api/routes/public/dag_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
)
from airflow.api_fastapi.common.db.common import get_session
from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.datamodels.assets import AssetEventCollectionResponse, AssetEventResponse
from airflow.api_fastapi.core_api.datamodels.dag_run import (
DAGRunPatchBody,
DAGRunPatchStates,
Expand Down Expand Up @@ -142,3 +143,35 @@ def patch_dag_run(
dag_run = session.get(DagRun, dag_run.id)

return DAGRunResponse.model_validate(dag_run, from_attributes=True)


@dag_run_router.get(
"/{dag_run_id}/upstreamAssetEvents",
responses=create_openapi_http_exception_doc(
[
status.HTTP_404_NOT_FOUND,
]
),
)
def get_upstream_asset_events(
dag_id: str, dag_run_id: str, session: Annotated[Session, Depends(get_session)]
) -> AssetEventCollectionResponse:
"""If dag run is asset-triggered, return the asset events that triggered it."""
dag_run: DagRun | None = session.scalar(
select(DagRun).where(
DagRun.dag_id == dag_id,
DagRun.run_id == dag_run_id,
)
)
if dag_run is None:
raise HTTPException(
status.HTTP_404_NOT_FOUND,
f"The DagRun with dag_id: `{dag_id}` and run_id: `{dag_run_id}` was not found",
)
events = dag_run.consumed_asset_events
return AssetEventCollectionResponse(
asset_events=[
AssetEventResponse.model_validate(asset_event, from_attributes=True) for asset_event in events
],
total_entries=len(events),
)
22 changes: 22 additions & 0 deletions airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,28 @@ export const UseDagRunServiceGetDagRunKeyFn = (
},
queryKey?: Array<unknown>,
) => [useDagRunServiceGetDagRunKey, ...(queryKey ?? [{ dagId, dagRunId }])];
export type DagRunServiceGetUpstreamAssetEventsDefaultResponse = Awaited<
ReturnType<typeof DagRunService.getUpstreamAssetEvents>
>;
export type DagRunServiceGetUpstreamAssetEventsQueryResult<
TData = DagRunServiceGetUpstreamAssetEventsDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const useDagRunServiceGetUpstreamAssetEventsKey =
"DagRunServiceGetUpstreamAssetEvents";
export const UseDagRunServiceGetUpstreamAssetEventsKeyFn = (
{
dagId,
dagRunId,
}: {
dagId: string;
dagRunId: string;
},
queryKey?: Array<unknown>,
) => [
useDagRunServiceGetUpstreamAssetEventsKey,
...(queryKey ?? [{ dagId, dagRunId }]),
];
export type DagSourceServiceGetDagSourceDefaultResponse = Awaited<
ReturnType<typeof DagSourceService.getDagSource>
>;
Expand Down
26 changes: 26 additions & 0 deletions airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,32 @@ export const prefetchUseDagRunServiceGetDagRun = (
queryKey: Common.UseDagRunServiceGetDagRunKeyFn({ dagId, dagRunId }),
queryFn: () => DagRunService.getDagRun({ dagId, dagRunId }),
});
/**
* Get Upstream Asset Events
* If dag run is asset-triggered, return the asset events that triggered it.
* @param data The data for the request.
* @param data.dagId
* @param data.dagRunId
* @returns AssetEventCollectionResponse Successful Response
* @throws ApiError
*/
export const prefetchUseDagRunServiceGetUpstreamAssetEvents = (
queryClient: QueryClient,
{
dagId,
dagRunId,
}: {
dagId: string;
dagRunId: string;
},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseDagRunServiceGetUpstreamAssetEventsKeyFn({
dagId,
dagRunId,
}),
queryFn: () => DagRunService.getUpstreamAssetEvents({ dagId, dagRunId }),
});
/**
* Get Dag Source
* Get source code using file token.
Expand Down
33 changes: 33 additions & 0 deletions airflow/ui/openapi-gen/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,39 @@ export const useDagRunServiceGetDagRun = <
queryFn: () => DagRunService.getDagRun({ dagId, dagRunId }) as TData,
...options,
});
/**
* Get Upstream Asset Events
* If dag run is asset-triggered, return the asset events that triggered it.
* @param data The data for the request.
* @param data.dagId
* @param data.dagRunId
* @returns AssetEventCollectionResponse Successful Response
* @throws ApiError
*/
export const useDagRunServiceGetUpstreamAssetEvents = <
TData = Common.DagRunServiceGetUpstreamAssetEventsDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[],
>(
{
dagId,
dagRunId,
}: {
dagId: string;
dagRunId: string;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useQuery<TData, TError>({
queryKey: Common.UseDagRunServiceGetUpstreamAssetEventsKeyFn(
{ dagId, dagRunId },
queryKey,
),
queryFn: () =>
DagRunService.getUpstreamAssetEvents({ dagId, dagRunId }) as TData,
...options,
});
/**
* Get Dag Source
* Get source code using file token.
Expand Down
33 changes: 33 additions & 0 deletions airflow/ui/openapi-gen/queries/suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,39 @@ export const useDagRunServiceGetDagRunSuspense = <
queryFn: () => DagRunService.getDagRun({ dagId, dagRunId }) as TData,
...options,
});
/**
* Get Upstream Asset Events
* If dag run is asset-triggered, return the asset events that triggered it.
* @param data The data for the request.
* @param data.dagId
* @param data.dagRunId
* @returns AssetEventCollectionResponse Successful Response
* @throws ApiError
*/
export const useDagRunServiceGetUpstreamAssetEventsSuspense = <
TData = Common.DagRunServiceGetUpstreamAssetEventsDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[],
>(
{
dagId,
dagRunId,
}: {
dagId: string;
dagRunId: string;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useSuspenseQuery<TData, TError>({
queryKey: Common.UseDagRunServiceGetUpstreamAssetEventsKeyFn(
{ dagId, dagRunId },
queryKey,
),
queryFn: () =>
DagRunService.getUpstreamAssetEvents({ dagId, dagRunId }) as TData,
...options,
});
/**
* Get Dag Source
* Get source code using file token.
Expand Down
11 changes: 9 additions & 2 deletions airflow/ui/openapi-gen/requests/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1924,8 +1924,15 @@ export const $DagRunAssetReference = {
title: "Start Date",
},
end_date: {
type: "string",
format: "date-time",
anyOf: [
{
type: "string",
format: "date-time",
},
{
type: "null",
},
],
title: "End Date",
},
state: {
Expand Down
30 changes: 30 additions & 0 deletions airflow/ui/openapi-gen/requests/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import type {
DeleteDagRunResponse,
PatchDagRunData,
PatchDagRunResponse,
GetUpstreamAssetEventsData,
GetUpstreamAssetEventsResponse,
GetDagSourceData,
GetDagSourceResponse,
GetDagStatsData,
Expand Down Expand Up @@ -735,6 +737,34 @@ export class DagRunService {
},
});
}

/**
* Get Upstream Asset Events
* If dag run is asset-triggered, return the asset events that triggered it.
* @param data The data for the request.
* @param data.dagId
* @param data.dagRunId
* @returns AssetEventCollectionResponse Successful Response
* @throws ApiError
*/
public static getUpstreamAssetEvents(
data: GetUpstreamAssetEventsData,
): CancelablePromise<GetUpstreamAssetEventsResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/public/dags/{dag_id}/dagRuns/{dag_run_id}/upstreamAssetEvents",
path: {
dag_id: data.dagId,
dag_run_id: data.dagRunId,
},
errors: {
401: "Unauthorized",
403: "Forbidden",
404: "Not Found",
422: "Validation Error",
},
});
}
}

export class DagSourceService {
Expand Down
36 changes: 35 additions & 1 deletion airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export type DagRunAssetReference = {
dag_id: string;
logical_date: string;
start_date: string;
end_date: string;
end_date: string | null;
state: string;
data_interval_start: string;
data_interval_end: string;
Expand Down Expand Up @@ -1114,6 +1114,13 @@ export type PatchDagRunData = {

export type PatchDagRunResponse = DAGRunResponse;

export type GetUpstreamAssetEventsData = {
dagId: string;
dagRunId: string;
};

export type GetUpstreamAssetEventsResponse = AssetEventCollectionResponse;

export type GetDagSourceData = {
accept?: string;
fileToken: string;
Expand Down Expand Up @@ -1978,6 +1985,33 @@ export type $OpenApiTs = {
};
};
};
"/public/dags/{dag_id}/dagRuns/{dag_run_id}/upstreamAssetEvents": {
get: {
req: GetUpstreamAssetEventsData;
res: {
/**
* Successful Response
*/
200: AssetEventCollectionResponse;
/**
* Unauthorized
*/
401: HTTPExceptionResponse;
/**
* Forbidden
*/
403: HTTPExceptionResponse;
/**
* Not Found
*/
404: HTTPExceptionResponse;
/**
* Validation Error
*/
422: HTTPValidationError;
};
};
};
"/public/dagSources/{file_token}": {
get: {
req: GetDagSourceData;
Expand Down
Loading