You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "syun64 (via GitHub)" <gi...@apache.org> on 2023/09/05 23:19:26 UTC
[GitHub] [airflow] syun64 opened a new pull request, #34126: New 'cleared' boolean attribute for dag_run
syun64 opened a new pull request, #34126:
URL: https://github.com/apache/airflow/pull/34126
<!--
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.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
related: https://github.com/apache/airflow/discussions/33677
Currently, Airflow supports clearing Dag runs in one of three ways:
REST API endpoint [clear](https://airflow.apache.org/docs/apache-airflow/stable/stable-rest-api-ref.html#operation/clear_dag_run)
UI button [clearExistingTasks](https://github.com/apache/airflow/blob/9fa782f622ad9f6e568f0efcadf93595f67b8a20/airflow/www/static/js/dag/details/dagRun/ClearRun.tsx#L54)
[Task Clear cli command](https://github.com/apache/airflow/blob/47682042a45501ab235d612580b8284a8957523e/airflow/cli/commands/task_command.py)
All three of these methods ultimately invoke [dag.clear method](https://github.com/apache/airflow/blob/main/airflow/models/dag.py#L2129) and put the DagRun back in a DagRunState.Queued state. Unfortunately there is currently no way for the schedulers to know if the QUEUED DagRun is its original scheduled run, or has been cleared from an already finished state.
The inability for Airflow or for users to distinguish between the original scheduled DagRun, and a cleared DagRun leads to difficulty in inferring meaningful information from reliability metrics. Some example reliability metrics that can be used as meaningful indicators of the Airflow cluster health, when monitoring periodic / scheduled Dags include:
[dagrun.schedule_delay](https://github.com/apache/airflow/blob/5dfbbbbf5adf70a9814121de8706a7c36f241836/airflow/jobs/scheduler_job_runner.py#L1341)
[dagrun.first_task_scheduling_delay](https://github.com/apache/airflow/blob/4037d79b5c3fe952b491a24ed99dea95c43e7666/airflow/models/dagrun.py#L954)
Each of these metrics help engineers understand if the Airflow is scheduling DagRuns and tasks when they are meant to be scheduled. And if these metrics are published in a reliable way, we empower engineers to be able to set up alarms when these metrics spike. Unfortunately, these metrics spike in false-alarms when the DagRuns are cleared.
This PR proposes that we persist the information that a DagRun was **cleared** as a boolean attribute in the DagRun table, when the DagRun is cleared to a 'QUEUED' state from a finished state ('SUCCESS' or 'FAILED').
Additional positive impact of introducing this boolean attribute, is that this also exposes this information to users who may be using their own custom operators to generate reliability metrics of their DagRuns/tasks. (e.g. Deferrable Operators that measure SLAs as suggested in https://cwiki.apache.org/confluence/display/AIRFLOW/AIP-57+Refactor+SLA+Feature and other discussions).
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] syun64 commented on a diff in pull request #34126: New 'clear_number' attribute for dag_run to track the number of times it has been cleared
Posted by "syun64 (via GitHub)" <gi...@apache.org>.
syun64 commented on code in PR #34126:
URL: https://github.com/apache/airflow/pull/34126#discussion_r1321506335
##########
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py:
##########
@@ -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,
+ )
Review Comment:
Not paranoid, these are great suggestions. I took all of your suggestions @uranusjr thank you for your input :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr merged pull request #34126: New 'clear_number' attribute for dag_run to track the number of times it has been cleared
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr merged PR #34126:
URL: https://github.com/apache/airflow/pull/34126
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on pull request #34126: New 'cleared' boolean attribute for dag_run
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #34126:
URL: https://github.com/apache/airflow/pull/34126#issuecomment-1710601966
`clear_number` sounds good to me too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] syun64 commented on pull request #34126: New 'cleared' boolean attribute for dag_run
Posted by "syun64 (via GitHub)" <gi...@apache.org>.
syun64 commented on PR #34126:
URL: https://github.com/apache/airflow/pull/34126#issuecomment-1709330561
> > Similarly, I think using a transient state instead of a more permanent marker will reduce the amount of information the users can build on when they try to infer if the DagRun had been cleared for their own purposes - for instance if there's an importance in differentiating between the original scheduled run, or a cleared run in their custom operator.
>
> How about "cleared_count" instead of bool? I think that would be quie a bit more informative
I agree! I will implement the change shortly 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on pull request #34126: New 'cleared' boolean attribute for dag_run
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on PR #34126:
URL: https://github.com/apache/airflow/pull/34126#issuecomment-1709575228
We already have `try_number` on TaskInstance for a similar purpose, I wonder if there’s some unifying can be done here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] syun64 commented on pull request #34126: New 'cleared' boolean attribute for dag_run
Posted by "syun64 (via GitHub)" <gi...@apache.org>.
syun64 commented on PR #34126:
URL: https://github.com/apache/airflow/pull/34126#issuecomment-1710114384
> We already have `try_number` on TaskInstance for a similar purpose (you can clear and rerun one single task), I wonder if there’s some unifying can be done here.
Yeah, that was my initial thought, and have noted that in the [original Google Doc draft of the SLA AIP-57](https://docs.google.com/document/d/1drNaYmAy6GqC4WGGn4MNt6VqbOwVNm7jPfmr5Pc52AU/edit#heading=h.z45mqf5nt94). I don't feel strongly about the naming convention, and will more than happily take either one :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on a diff in pull request #34126: New 'clear_number' attribute for dag_run to track the number of times it has been cleared
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #34126:
URL: https://github.com/apache/airflow/pull/34126#discussion_r1321291408
##########
airflow/models/dagrun.py:
##########
@@ -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)
Review Comment:
```suggestion
clear_number = Column(Integer, default=0, nullable=False)
```
to match the migration?
##########
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py:
##########
@@ -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,
+ )
Review Comment:
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.
##########
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py:
##########
@@ -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,
+ )
Review Comment:
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.
##########
airflow/models/dagrun.py:
##########
@@ -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,
Review Comment:
Is this argument used anywhere? I wonder if we should just have `self.clear_number = 0` always and rely on in-place modification instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] syun64 commented on pull request #34126: New 'cleared' boolean attribute for dag_run
Posted by "syun64 (via GitHub)" <gi...@apache.org>.
syun64 commented on PR #34126:
URL: https://github.com/apache/airflow/pull/34126#issuecomment-1708350097
> > Unfortunately there is currently no way for the schedulers to know if the QUEUED DagRun is its original scheduled run, or has been cleared from an already finished state.
>
> Instead of a separate flag, would it be viable to have a CLEARED state instead?
@uranusjr thank you for the review, and yes interesting thought... Given that a new CLEARED state will only be a transient state, I think it'll be harder for us to provide same amount of information at different points throughout the lifecycle of the DagRun. Assuming that the new state will go through the following lifecycle: CLEARED -> (QUEUED) -> RUNNING -> finished STATE, I believe that using a transient state only allows us to differentiate between the original scheduled run, and a cleared dag run until the DagRun is scheduled.
For example, with a new state, we will still be able to know that the DagRun was cleared when we call [_update_state](https://github.com/apache/airflow/pull/34126/files#diff-b0491913f69327937706aea8fc77a71efeb979897898e405ade2b162ad862476R1348), but not when we publish the first_task_scheduling_delay metric within _emit_true_scheduling_delay_stats_for_finished_state call (since the DagRun will already be in a RUNNING state at this point).
Similarly, I think using a transient state instead of a more permanent marker will reduce the amount of information the users can build on when they try to infer if the DagRun had been cleared for their own purposes - for instance if there's an importance in differentiating between the original scheduled run, or a cleared run in their custom operator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk commented on pull request #34126: New 'cleared' boolean attribute for dag_run
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #34126:
URL: https://github.com/apache/airflow/pull/34126#issuecomment-1709317743
> Similarly, I think using a transient state instead of a more permanent marker will reduce the amount of information the users can build on when they try to infer if the DagRun had been cleared for their own purposes - for instance if there's an importance in differentiating between the original scheduled run, or a cleared run in their custom operator.
How about "cleared_count" instead of bool? I think that would be quie a bit more informative
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org