-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
New 'clear_number' attribute for dag_run to track the number of times it has been cleared #34126
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# | ||
# 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 new field 'clear_number' to dagrun | ||
|
||
Revision ID: 375a816bbbf4 | ||
Revises: 405de8318b3a | ||
Create Date: 2023-09-05 19:27:30.531558 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "375a816bbbf4" | ||
down_revision = "405de8318b3a" | ||
branch_labels = None | ||
depends_on = None | ||
airflow_version = "2.8.0" | ||
|
||
|
||
def upgrade(): | ||
"""Apply add cleared column to dagrun""" | ||
with op.batch_alter_table("dag_run") as batch_op: | ||
batch_op.add_column( | ||
sa.Column( | ||
"clear_number", | ||
sa.Integer, | ||
default=0, | ||
nullable=False, | ||
) | ||
) | ||
|
||
|
||
def downgrade(): | ||
"""Unapply add cleared column to pool""" | ||
with op.batch_alter_table("dag_run") as batch_op: | ||
batch_op.drop_column("clear_number") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,7 @@ class DagRun(Base, LoggingMixin): | |
default=select(func.max(LogTemplate.__table__.c.id)), | ||
) | ||
updated_at = Column(UtcDateTime, default=timezone.utcnow, onupdate=timezone.utcnow) | ||
clear_number = Column(Integer, default=0) | ||
syun64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Remove this `if` after upgrading Sphinx-AutoAPI | ||
if not TYPE_CHECKING and "BUILDING_AIRFLOW_DOCS" in os.environ: | ||
|
@@ -210,6 +211,7 @@ def __init__( | |
dag_hash: str | None = None, | ||
creating_job_id: int | None = None, | ||
data_interval: tuple[datetime, datetime] | None = None, | ||
clear_number: int = 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this argument used anywhere? I wonder if we should just have |
||
): | ||
if data_interval is None: | ||
# Legacy: Only happen for runs created prior to Airflow 2.2. | ||
|
@@ -232,6 +234,7 @@ def __init__( | |
self.run_type = run_type | ||
self.dag_hash = dag_hash | ||
self.creating_job_id = creating_job_id | ||
self.clear_number = clear_number | ||
super().__init__() | ||
|
||
def __repr__(self): | ||
|
@@ -917,12 +920,15 @@ def _emit_true_scheduling_delay_stats_for_finished_state(self, finished_tis: lis | |
rid of the outliers on the stats side through dashboards tooling. | ||
|
||
Note that the stat will only be emitted for scheduler-triggered DAG runs | ||
(i.e. when ``external_trigger`` is *False*). | ||
(i.e. when ``external_trigger`` is *False* and ``clear_number`` is | ||
greater than 0). | ||
""" | ||
if self.state == TaskInstanceState.RUNNING: | ||
return | ||
if self.external_trigger: | ||
return | ||
if self.clear_number > 0: | ||
return | ||
if not finished_tis: | ||
return | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
52cd8c81c9f586992515a903d882e72e8df0a55da5021d2614ba1807b8b63f7e | ||
67b3dfeba9f0f4721ec4eaf3045ede333fdf16b40e6eaaa58f680f1dc95fcc6f |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if we want to add a constraint on this to ensure the value is not negative. Or if not, maybe we should change the
== 0
check to< 1
instead. A bit paranoid probably, but it’s mostly free safety so why not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not paranoid, these are great suggestions. I took all of your suggestions @uranusjr thank you for your input :)