Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class GridRunsResponse(BaseModel):
run_after: datetime
state: DagRunState | None
run_type: DagRunType
has_missed_deadline: bool

@computed_field
def duration(self) -> float:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from __future__ import annotations

from datetime import datetime
from uuid import UUID

from airflow.api_fastapi.core_api.base import BaseModel


class DeadlineResponse(BaseModel):
"""Deadline data for the DAG run deadlines tab."""

id: UUID
deadline_time: datetime
missed: bool
created_at: datetime
alert_name: str | None = None
alert_description: str | None = None
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,51 @@ paths:
security:
- OAuth2PasswordBearer: []
- HTTPBearer: []
/ui/deadlines/{dag_id}/{run_id}:
get:
tags:
- Deadlines
summary: Get Dag Run Deadlines
description: Get all deadlines for a specific DAG run.
operationId: get_dag_run_deadlines
security:
- OAuth2PasswordBearer: []
- HTTPBearer: []
parameters:
- name: dag_id
in: path
required: true
schema:
type: string
title: Dag Id
- name: run_id
in: path
required: true
schema:
type: string
title: Run Id
responses:
'200':
description: Successful Response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/DeadlineResponse'
title: Response Get Dag Run Deadlines
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/ui/structure/structure_data:
get:
tags:
Expand Down Expand Up @@ -1917,6 +1962,41 @@ components:
- queued_dag_count
title: DashboardDagStatsResponse
description: Dashboard DAG Stats serializer for responses.
DeadlineResponse:
properties:
id:
type: string
format: uuid
title: Id
deadline_time:
type: string
format: date-time
title: Deadline Time
missed:
type: boolean
title: Missed
created_at:
type: string
format: date-time
title: Created At
alert_name:
anyOf:
- type: string
- type: 'null'
title: Alert Name
alert_description:
anyOf:
- type: string
- type: 'null'
title: Alert Description
type: object
required:
- id
- deadline_time
- missed
- created_at
title: DeadlineResponse
description: Deadline data for the DAG run deadlines tab.
EdgeResponse:
properties:
source_id:
Expand Down Expand Up @@ -2095,6 +2175,9 @@ components:
- type: 'null'
run_type:
$ref: '#/components/schemas/DagRunType'
has_missed_deadline:
type: boolean
title: Has Missed Deadline
duration:
type: number
title: Duration
Expand All @@ -2109,6 +2192,7 @@ components:
- run_after
- state
- run_type
- has_missed_deadline
- duration
title: GridRunsResponse
description: Base Node serializer for responses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from airflow.api_fastapi.core_api.routes.ui.connections import connections_router
from airflow.api_fastapi.core_api.routes.ui.dags import dags_router
from airflow.api_fastapi.core_api.routes.ui.dashboard import dashboard_router
from airflow.api_fastapi.core_api.routes.ui.deadlines import deadlines_router
from airflow.api_fastapi.core_api.routes.ui.dependencies import dependencies_router
from airflow.api_fastapi.core_api.routes.ui.gantt import gantt_router
from airflow.api_fastapi.core_api.routes.ui.grid import grid_router
Expand All @@ -40,6 +41,7 @@
ui_router.include_router(dags_router)
ui_router.include_router(dependencies_router)
ui_router.include_router(dashboard_router)
ui_router.include_router(deadlines_router)
ui_router.include_router(structure_router)
ui_router.include_router(backfills_router)
ui_router.include_router(grid_router)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from __future__ import annotations

from fastapi import Depends, HTTPException, status
from sqlalchemy import select
from sqlalchemy.orm import joinedload

from airflow.api_fastapi.auth.managers.models.resource_details import DagAccessEntity
from airflow.api_fastapi.common.db.common import SessionDep
from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.datamodels.ui.deadline import DeadlineResponse
from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
from airflow.api_fastapi.core_api.security import requires_access_dag
from airflow.models.dagrun import DagRun
from airflow.models.deadline import Deadline

deadlines_router = AirflowRouter(prefix="/deadlines", tags=["Deadlines"])


@deadlines_router.get(
"/{dag_id}/{run_id}",
responses=create_openapi_http_exception_doc(
[
status.HTTP_404_NOT_FOUND,
]
),
dependencies=[
Depends(
requires_access_dag(
method="GET",
access_entity=DagAccessEntity.RUN,
)
),
],
)
def get_dag_run_deadlines(
dag_id: str,
run_id: str,
session: SessionDep,
) -> list[DeadlineResponse]:
"""Get all deadlines for a specific DAG run."""
dag_run = session.scalar(select(DagRun).where(DagRun.dag_id == dag_id, DagRun.run_id == run_id))
if not dag_run:
raise HTTPException(
status.HTTP_404_NOT_FOUND,
f"No DAG run found for dag_id={dag_id} run_id={run_id}",
)

deadlines = (
session.scalars(
select(Deadline)
.where(Deadline.dagrun_id == dag_run.id)
.options(joinedload(Deadline.deadline_alert))
.order_by(Deadline.deadline_time.asc())
)
.unique()
.all()
)

return [
DeadlineResponse(
id=d.id,
deadline_time=d.deadline_time,
missed=d.missed,
created_at=d.created_at,
alert_name=d.deadline_alert.name if d.deadline_alert else None,
alert_description=d.deadline_alert.description if d.deadline_alert else None,
)
for d in deadlines
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import structlog
from fastapi import Depends, HTTPException, status
from sqlalchemy import select
from sqlalchemy import exists, select
from sqlalchemy.orm import joinedload

from airflow.api_fastapi.auth.managers.models.resource_details import DagAccessEntity
Expand Down Expand Up @@ -60,6 +60,7 @@
)
from airflow.models.dag_version import DagVersion
from airflow.models.dagrun import DagRun
from airflow.models.deadline import Deadline
from airflow.models.serialized_dag import SerializedDagModel
from airflow.models.taskinstance import TaskInstance

Expand Down Expand Up @@ -275,6 +276,12 @@ def get_grid_runs(
) -> list[GridRunsResponse]:
"""Get info about a run for the grid."""
# Retrieve, sort the previous DAG Runs
has_missed_deadline = (
exists()
.where(Deadline.dagrun_id == DagRun.id, Deadline.missed.is_(True))
.correlate(DagRun)
.label("has_missed_deadline")
)
base_query = select(
DagRun.dag_id,
DagRun.run_id,
Expand All @@ -284,6 +291,7 @@ def get_grid_runs(
DagRun.run_after,
DagRun.state,
DagRun.run_type,
has_missed_deadline,
).where(DagRun.dag_id == dag_id)

# This comparison is to fall back to DAG timetable when no order_by is provided
Expand Down
9 changes: 8 additions & 1 deletion airflow-core/src/airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// generated with @7nohe/openapi-react-query-codegen@1.6.2

import { UseQueryResult } from "@tanstack/react-query";
import { AssetService, AuthLinksService, BackfillService, CalendarService, ConfigService, ConnectionService, DagParsingService, DagRunService, DagService, DagSourceService, DagStatsService, DagVersionService, DagWarningService, DashboardService, DependenciesService, EventLogService, ExperimentalService, ExtraLinksService, GanttService, GridService, ImportErrorService, JobService, LoginService, MonitorService, PluginService, PoolService, ProviderService, StructureService, TaskInstanceService, TaskService, TeamsService, VariableService, VersionService, XcomService } from "../requests/services.gen";
import { AssetService, AuthLinksService, BackfillService, CalendarService, ConfigService, ConnectionService, DagParsingService, DagRunService, DagService, DagSourceService, DagStatsService, DagVersionService, DagWarningService, DashboardService, DeadlinesService, DependenciesService, EventLogService, ExperimentalService, ExtraLinksService, GanttService, GridService, ImportErrorService, JobService, LoginService, MonitorService, PluginService, PoolService, ProviderService, StructureService, TaskInstanceService, TaskService, TeamsService, VariableService, VersionService, XcomService } from "../requests/services.gen";
import { DagRunState, DagWarningType } from "../requests/types.gen";
export type AssetServiceGetAssetsDefaultResponse = Awaited<ReturnType<typeof AssetService.getAssets>>;
export type AssetServiceGetAssetsQueryResult<TData = AssetServiceGetAssetsDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
Expand Down Expand Up @@ -806,6 +806,13 @@ export type DashboardServiceDagStatsDefaultResponse = Awaited<ReturnType<typeof
export type DashboardServiceDagStatsQueryResult<TData = DashboardServiceDagStatsDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useDashboardServiceDagStatsKey = "DashboardServiceDagStats";
export const UseDashboardServiceDagStatsKeyFn = (queryKey?: Array<unknown>) => [useDashboardServiceDagStatsKey, ...(queryKey ?? [])];
export type DeadlinesServiceGetDagRunDeadlinesDefaultResponse = Awaited<ReturnType<typeof DeadlinesService.getDagRunDeadlines>>;
export type DeadlinesServiceGetDagRunDeadlinesQueryResult<TData = DeadlinesServiceGetDagRunDeadlinesDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useDeadlinesServiceGetDagRunDeadlinesKey = "DeadlinesServiceGetDagRunDeadlines";
export const UseDeadlinesServiceGetDagRunDeadlinesKeyFn = ({ dagId, runId }: {
dagId: string;
runId: string;
}, queryKey?: Array<unknown>) => [useDeadlinesServiceGetDagRunDeadlinesKey, ...(queryKey ?? [{ dagId, runId }])];
export type StructureServiceStructureDataDefaultResponse = Awaited<ReturnType<typeof StructureService.structureData>>;
export type StructureServiceStructureDataQueryResult<TData = StructureServiceStructureDataDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
export const useStructureServiceStructureDataKey = "StructureServiceStructureData";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// generated with @7nohe/openapi-react-query-codegen@1.6.2

import { type QueryClient } from "@tanstack/react-query";
import { AssetService, AuthLinksService, BackfillService, CalendarService, ConfigService, ConnectionService, DagRunService, DagService, DagSourceService, DagStatsService, DagVersionService, DagWarningService, DashboardService, DependenciesService, EventLogService, ExperimentalService, ExtraLinksService, GanttService, GridService, ImportErrorService, JobService, LoginService, MonitorService, PluginService, PoolService, ProviderService, StructureService, TaskInstanceService, TaskService, TeamsService, VariableService, VersionService, XcomService } from "../requests/services.gen";
import { AssetService, AuthLinksService, BackfillService, CalendarService, ConfigService, ConnectionService, DagRunService, DagService, DagSourceService, DagStatsService, DagVersionService, DagWarningService, DashboardService, DeadlinesService, DependenciesService, EventLogService, ExperimentalService, ExtraLinksService, GanttService, GridService, ImportErrorService, JobService, LoginService, MonitorService, PluginService, PoolService, ProviderService, StructureService, TaskInstanceService, TaskService, TeamsService, VariableService, VersionService, XcomService } from "../requests/services.gen";
import { DagRunState, DagWarningType } from "../requests/types.gen";
import * as Common from "./common";
/**
Expand Down Expand Up @@ -1530,6 +1530,19 @@ export const ensureUseDashboardServiceHistoricalMetricsData = (queryClient: Quer
*/
export const ensureUseDashboardServiceDagStatsData = (queryClient: QueryClient) => queryClient.ensureQueryData({ queryKey: Common.UseDashboardServiceDagStatsKeyFn(), queryFn: () => DashboardService.dagStats() });
/**
* Get Dag Run Deadlines
* Get all deadlines for a specific DAG run.
* @param data The data for the request.
* @param data.dagId
* @param data.runId
* @returns DeadlineResponse Successful Response
* @throws ApiError
*/
export const ensureUseDeadlinesServiceGetDagRunDeadlinesData = (queryClient: QueryClient, { dagId, runId }: {
dagId: string;
runId: string;
}) => queryClient.ensureQueryData({ queryKey: Common.UseDeadlinesServiceGetDagRunDeadlinesKeyFn({ dagId, runId }), queryFn: () => DeadlinesService.getDagRunDeadlines({ dagId, runId }) });
/**
* Structure Data
* Get Structure Data.
* @param data The data for the request.
Expand Down
15 changes: 14 additions & 1 deletion airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// generated with @7nohe/openapi-react-query-codegen@1.6.2

import { type QueryClient } from "@tanstack/react-query";
import { AssetService, AuthLinksService, BackfillService, CalendarService, ConfigService, ConnectionService, DagRunService, DagService, DagSourceService, DagStatsService, DagVersionService, DagWarningService, DashboardService, DependenciesService, EventLogService, ExperimentalService, ExtraLinksService, GanttService, GridService, ImportErrorService, JobService, LoginService, MonitorService, PluginService, PoolService, ProviderService, StructureService, TaskInstanceService, TaskService, TeamsService, VariableService, VersionService, XcomService } from "../requests/services.gen";
import { AssetService, AuthLinksService, BackfillService, CalendarService, ConfigService, ConnectionService, DagRunService, DagService, DagSourceService, DagStatsService, DagVersionService, DagWarningService, DashboardService, DeadlinesService, DependenciesService, EventLogService, ExperimentalService, ExtraLinksService, GanttService, GridService, ImportErrorService, JobService, LoginService, MonitorService, PluginService, PoolService, ProviderService, StructureService, TaskInstanceService, TaskService, TeamsService, VariableService, VersionService, XcomService } from "../requests/services.gen";
import { DagRunState, DagWarningType } from "../requests/types.gen";
import * as Common from "./common";
/**
Expand Down Expand Up @@ -1530,6 +1530,19 @@ export const prefetchUseDashboardServiceHistoricalMetrics = (queryClient: QueryC
*/
export const prefetchUseDashboardServiceDagStats = (queryClient: QueryClient) => queryClient.prefetchQuery({ queryKey: Common.UseDashboardServiceDagStatsKeyFn(), queryFn: () => DashboardService.dagStats() });
/**
* Get Dag Run Deadlines
* Get all deadlines for a specific DAG run.
* @param data The data for the request.
* @param data.dagId
* @param data.runId
* @returns DeadlineResponse Successful Response
* @throws ApiError
*/
export const prefetchUseDeadlinesServiceGetDagRunDeadlines = (queryClient: QueryClient, { dagId, runId }: {
dagId: string;
runId: string;
}) => queryClient.prefetchQuery({ queryKey: Common.UseDeadlinesServiceGetDagRunDeadlinesKeyFn({ dagId, runId }), queryFn: () => DeadlinesService.getDagRunDeadlines({ dagId, runId }) });
/**
* Structure Data
* Get Structure Data.
* @param data The data for the request.
Expand Down
Loading
Loading