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 queued asset events for assets to FASTAPI #44139

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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/asset_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def delete_dag_asset_queued_events(
)


@mark_fastapi_migration_done
@security.requires_access_asset("GET")
@provide_session
def get_asset_queued_events(
Expand Down
53 changes: 53 additions & 0 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,59 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/assets/queuedEvent/{uri}:
get:
tags:
- Asset
summary: Get Asset Queued Events
description: Get queued asset events for an asset.
operationId: get_asset_queued_events
parameters:
- name: uri
in: path
required: true
schema:
type: string
title: Uri
- name: before
in: query
required: false
schema:
anyOf:
- type: string
- type: 'null'
title: Before
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/QueuedEventCollectionResponse'
'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/backfills/:
get:
tags:
Expand Down
41 changes: 41 additions & 0 deletions airflow/api_fastapi/core_api/routes/public/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,44 @@ def delete_dag_asset_queued_events(

if result.rowcount == 0:
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Queue event with dag_id: `{dag_id}` was not found")


@assets_router.get(
"/assets/queuedEvents/{uri:path}",
pierrejeambrun marked this conversation as resolved.
Show resolved Hide resolved
responses=create_openapi_http_exception_doc(
[
status.HTTP_404_NOT_FOUND,
]
),
)
def get_asset_queued_events(
uri: str,
session: Annotated[Session, Depends(get_session)],
before: OptionalDateTimeQuery = None,
) -> QueuedEventCollectionResponse:
"""Get queued asset events for an asset."""
where_clause = _generate_queued_event_where_clause(uri=uri, before=before)
query = (
select(AssetDagRunQueue, AssetModel.uri)
.join(AssetModel, AssetDagRunQueue.asset_id == AssetModel.id)
.where(*where_clause)
)

dag_asset_queued_events_select, total_entries = paginated_select(
query,
[],
)
adrqs = session.execute(dag_asset_queued_events_select).all()

if not adrqs:
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Queue event with uri: `{uri}` was not found")

queued_events = [
QueuedEventResponse(created_at=adrq.created_at, dag_id=adrq.target_dag_id, uri=uri)
for adrq, uri in adrqs
]

return QueuedEventCollectionResponse(
queued_events=queued_events,
total_entries=total_entries,
)
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 @@ -151,6 +151,28 @@ export const UseAssetServiceGetDagAssetQueuedEventsKeyFn = (
useAssetServiceGetDagAssetQueuedEventsKey,
...(queryKey ?? [{ before, dagId }]),
];
export type AssetServiceGetAssetQueuedEventsDefaultResponse = Awaited<
ReturnType<typeof AssetService.getAssetQueuedEvents>
>;
export type AssetServiceGetAssetQueuedEventsQueryResult<
TData = AssetServiceGetAssetQueuedEventsDefaultResponse,
TError = unknown,
> = UseQueryResult<TData, TError>;
export const useAssetServiceGetAssetQueuedEventsKey =
"AssetServiceGetAssetQueuedEvents";
export const UseAssetServiceGetAssetQueuedEventsKeyFn = (
{
before,
uri,
}: {
before?: string;
uri: string;
},
queryKey?: Array<unknown>,
) => [
useAssetServiceGetAssetQueuedEventsKey,
...(queryKey ?? [{ before, uri }]),
];
export type DashboardServiceHistoricalMetricsDefaultResponse = Awaited<
ReturnType<typeof DashboardService.historicalMetrics>
>;
Expand Down
23 changes: 23 additions & 0 deletions airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,29 @@ export const prefetchUseAssetServiceGetDagAssetQueuedEvents = (
}),
queryFn: () => AssetService.getDagAssetQueuedEvents({ before, dagId }),
});
/**
* Get Asset Queued Events
* Get queued asset events for an asset.
* @param data The data for the request.
* @param data.uri
* @param data.before
* @returns QueuedEventCollectionResponse Successful Response
* @throws ApiError
*/
export const prefetchUseAssetServiceGetAssetQueuedEvents = (
queryClient: QueryClient,
{
before,
uri,
}: {
before?: string;
uri: string;
},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseAssetServiceGetAssetQueuedEventsKeyFn({ before, uri }),
queryFn: () => AssetService.getAssetQueuedEvents({ before, uri }),
});
/**
* Historical Metrics
* Return cluster activity historical metrics.
Expand Down
32 changes: 32 additions & 0 deletions airflow/ui/openapi-gen/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,38 @@ export const useAssetServiceGetDagAssetQueuedEvents = <
AssetService.getDagAssetQueuedEvents({ before, dagId }) as TData,
...options,
});
/**
* Get Asset Queued Events
* Get queued asset events for an asset.
* @param data The data for the request.
* @param data.uri
* @param data.before
* @returns QueuedEventCollectionResponse Successful Response
* @throws ApiError
*/
export const useAssetServiceGetAssetQueuedEvents = <
TData = Common.AssetServiceGetAssetQueuedEventsDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[],
>(
{
before,
uri,
}: {
before?: string;
uri: string;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useQuery<TData, TError>({
queryKey: Common.UseAssetServiceGetAssetQueuedEventsKeyFn(
{ before, uri },
queryKey,
),
queryFn: () => AssetService.getAssetQueuedEvents({ before, uri }) as TData,
...options,
});
/**
* Historical Metrics
* Return cluster activity historical metrics.
Expand Down
32 changes: 32 additions & 0 deletions airflow/ui/openapi-gen/queries/suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,38 @@ export const useAssetServiceGetDagAssetQueuedEventsSuspense = <
AssetService.getDagAssetQueuedEvents({ before, dagId }) as TData,
...options,
});
/**
* Get Asset Queued Events
* Get queued asset events for an asset.
* @param data The data for the request.
* @param data.uri
* @param data.before
* @returns QueuedEventCollectionResponse Successful Response
* @throws ApiError
*/
export const useAssetServiceGetAssetQueuedEventsSuspense = <
TData = Common.AssetServiceGetAssetQueuedEventsDefaultResponse,
TError = unknown,
TQueryKey extends Array<unknown> = unknown[],
>(
{
before,
uri,
}: {
before?: string;
uri: string;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useSuspenseQuery<TData, TError>({
queryKey: Common.UseAssetServiceGetAssetQueuedEventsKeyFn(
{ before, uri },
queryKey,
),
queryFn: () => AssetService.getAssetQueuedEvents({ before, uri }) as TData,
...options,
});
/**
* Historical Metrics
* Return cluster activity historical metrics.
Expand Down
32 changes: 32 additions & 0 deletions airflow/ui/openapi-gen/requests/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type {
GetDagAssetQueuedEventsResponse,
DeleteDagAssetQueuedEventsData,
DeleteDagAssetQueuedEventsResponse,
GetAssetQueuedEventsData,
GetAssetQueuedEventsResponse,
HistoricalMetricsData,
HistoricalMetricsResponse,
RecentDagRunsData,
Expand Down Expand Up @@ -338,6 +340,36 @@ export class AssetService {
},
});
}

/**
* Get Asset Queued Events
* Get queued asset events for an asset.
* @param data The data for the request.
* @param data.uri
* @param data.before
* @returns QueuedEventCollectionResponse Successful Response
* @throws ApiError
*/
public static getAssetQueuedEvents(
data: GetAssetQueuedEventsData,
): CancelablePromise<GetAssetQueuedEventsResponse> {
return __request(OpenAPI, {
method: "GET",
url: "/public/assets/queuedEvent/{uri}",
path: {
uri: data.uri,
},
query: {
before: data.before,
},
errors: {
401: "Unauthorized",
403: "Forbidden",
404: "Not Found",
422: "Validation Error",
},
});
}
}

export class DashboardService {
Expand Down
34 changes: 34 additions & 0 deletions airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,13 @@ export type DeleteDagAssetQueuedEventsData = {

export type DeleteDagAssetQueuedEventsResponse = void;

export type GetAssetQueuedEventsData = {
before?: string | null;
uri: string;
};

export type GetAssetQueuedEventsResponse = QueuedEventCollectionResponse;

export type HistoricalMetricsData = {
endDate: string;
startDate: string;
Expand Down Expand Up @@ -1728,6 +1735,33 @@ export type $OpenApiTs = {
};
};
};
"/public/assets/queuedEvent/{uri}": {
get: {
req: GetAssetQueuedEventsData;
res: {
/**
* Successful Response
*/
200: QueuedEventCollectionResponse;
/**
* Unauthorized
*/
401: HTTPExceptionResponse;
/**
* Forbidden
*/
403: HTTPExceptionResponse;
/**
* Not Found
*/
404: HTTPExceptionResponse;
/**
* Validation Error
*/
422: HTTPValidationError;
};
};
};
"/ui/dashboard/historical_metrics_data": {
get: {
req: HistoricalMetricsData;
Expand Down
36 changes: 36 additions & 0 deletions tests/api_fastapi/core_api/routes/public/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,39 @@ def test_should_mask_sensitive_extra(self, test_client, session):
"created_dagruns": [],
"timestamp": self.default_time.replace("+00:00", "Z"),
}


class TestGetAssetQueuedEvents(TestQueuedEventEndpoint):
@pytest.mark.usefixtures("time_freezer")
def test_should_respond_200(self, test_client, session, create_dummy_dag):
dag, _ = create_dummy_dag()
dag_id = dag.dag_id
self.create_assets(session=session, num=1)
uri = "s3://bucket/key/1"
asset_id = 1
self._create_asset_dag_run_queues(dag_id, asset_id, session)

response = test_client.get(
f"/public/assets/queuedEvent/{uri}",
)
assert response.status_code == 200
assert response.json() == {
"queued_events": [
{
"created_at": self.default_time.replace("+00:00", "Z"),
"uri": "s3://bucket/key/1",
"dag_id": "dag",
}
],
"total_entries": 1,
}

def test_should_respond_404(self, test_client):
uri = "not_exists"

response = test_client.get(
f"/public/assets/queuedEvent/{uri}",
)

assert response.status_code == 404
assert response.json()["detail"] == "Queue event with uri: `not_exists` was not found"
Loading