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-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to