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

Add try_number to log table #40739

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 9 additions & 0 deletions airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,8 @@ paths:
- $ref: "#/components/parameters/FilterDAGID"
- $ref: "#/components/parameters/FilterTaskID"
- $ref: "#/components/parameters/FilterRunID"
- $ref: "#/components/parameters/FilterMapIndex"
- $ref: "#/components/parameters/FilterTryNumber"
- $ref: "#/components/parameters/Event"
- $ref: "#/components/parameters/Owner"
- $ref: "#/components/parameters/Before"
Expand Down Expand Up @@ -5587,6 +5589,13 @@ components:
type: integer
description: Filter on map index for mapped task.

FilterTryNumber:
in: query
name: try_number
schema:
type: integer
description: Filter on try_number for task instance.

OrderBy:
in: query
name: order_by
Expand Down
2 changes: 2 additions & 0 deletions airflow/api_connexion/schemas/event_log_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Meta:
dag_id = auto_field(dump_only=True)
task_id = auto_field(dump_only=True)
run_id = auto_field(dump_only=True)
map_index = auto_field(dump_only=True)
try_number = auto_field(dump_only=True)
event = auto_field(dump_only=True)
execution_date = auto_field(dump_only=True)
owner = auto_field(dump_only=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# 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.

"""
Add try_number to audit log.

Revision ID: 41b3bc7c0272
Revises: ec3471c1e067
Create Date: 2024-07-11 14:48:58.998259

"""

from __future__ import annotations

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "41b3bc7c0272"
down_revision = "ec3471c1e067"
branch_labels = None
depends_on = None
airflow_version = "2.10.0"


def upgrade():
"""Apply add try_number to audit log."""
with op.batch_alter_table("log") as batch_op:
batch_op.add_column(sa.Column("try_number", sa.Integer(), nullable=True))
batch_op.create_index(
"idx_log_task_instance", ["dag_id", "task_id", "run_id", "map_index", "try_number"], unique=False
)


def downgrade():
"""Unapply add try_number to audit log."""
with op.batch_alter_table("log") as batch_op:
batch_op.drop_index("idx_log_task_instance")
batch_op.drop_column("try_number")
5 changes: 5 additions & 0 deletions airflow/models/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ class Log(Base):
owner = Column(String(500))
owner_display_name = Column(String(500))
extra = Column(Text)
try_number = Column(Integer)
dstandish marked this conversation as resolved.
Show resolved Hide resolved

__table_args__ = (
Index("idx_log_dag", dag_id),
Index("idx_log_dttm", dttm),
Index("idx_log_event", event),
Index("idx_log_task_instance", dag_id, task_id, run_id, map_index, try_number),
dstandish marked this conversation as resolved.
Show resolved Hide resolved
)

def __init__(self, event, task_instance=None, owner=None, owner_display_name=None, extra=None, **kwargs):
Expand All @@ -59,6 +61,7 @@ def __init__(self, event, task_instance=None, owner=None, owner_display_name=Non
self.task_id = task_instance.task_id
self.execution_date = task_instance.execution_date
self.run_id = task_instance.run_id
self.try_number = task_instance.try_number
self.map_index = task_instance.map_index
if getattr(task_instance, "task", None):
task_owner = task_instance.task.owner
Expand All @@ -73,6 +76,8 @@ def __init__(self, event, task_instance=None, owner=None, owner_display_name=Non
self.run_id = kwargs["run_id"]
if "map_index" in kwargs:
self.map_index = kwargs["map_index"]
if "try_number" in kwargs:
self.try_number = kwargs["try_number"]

self.owner = owner or task_owner
self.owner_display_name = owner_display_name or None
Expand Down
2 changes: 1 addition & 1 deletion airflow/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class MappedClassProtocol(Protocol):
"2.8.1": "88344c1d9134",
"2.9.0": "1949afb29106",
"2.9.2": "686269002441",
"2.10.0": "ec3471c1e067",
"2.10.0": "41b3bc7c0272",
}


Expand Down
6 changes: 6 additions & 0 deletions airflow/www/static/js/types/api-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,8 @@ export interface components {
FilterSourceMapIndex: number;
/** @description Filter on map index for mapped task. */
FilterMapIndex: number;
/** @description Filter on try_number for task instance. */
FilterTryNumber: number;
/**
* @description The name of the field to order the results by.
* Prefix a field name with `-` to reverse the sort order.
Expand Down Expand Up @@ -3676,6 +3678,10 @@ export interface operations {
task_id?: components["parameters"]["FilterTaskID"];
/** Returns objects matched by the Run ID. */
run_id?: components["parameters"]["FilterRunID"];
/** Filter on map index for mapped task. */
map_index?: components["parameters"]["FilterMapIndex"];
/** Filter on try_number for task instance. */
try_number?: components["parameters"]["FilterTryNumber"];
/** The name of event log. */
event?: components["parameters"]["Event"];
/** The owner's name of event log. */
Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow/img/airflow_erd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
88c9ce0742c54f376a3c600600d06ac9a6f80a3a2cb85dfcf2472d1c77ed75db
3afa3d98632dcfe0f585f8777d1bfcb06a4d4f1df20838ee019dc94fa05ef73d
Loading
Loading