seyiogunjuyigbe commented on code in PR #76367:
URL: https://github.com/apache/airflow/pull/76367#discussion_r4641360819


##########
airflow-core/docs/core-concepts/debug.rst:
##########
@@ -112,3 +112,104 @@ Run ``python -m pdb <path to Dag file>.py`` for an 
interactive debugging experie
       dag.test()
 
 2. Run / debug the Dag file.
+
+Debugging Dags in a running deployment
+--------------------------------------
+
+``dag.test()`` covers local development. Once a Dag runs in a shared 
deployment, most debugging
+starts from a failed or misbehaving task instance. The techniques below work 
from the UI and from
+the ``airflow`` CLI on any machine that can reach the metadata database.
+
+Reading task logs
+'''''''''''''''''
+
+Open the failed task instance from the Grid view and go to the **Logs** tab.
+
+* Use the log level filter (**All Log Levels** by default) to show only 
``WARNING``, ``ERROR`` or
+  ``CRITICAL`` lines. You can select more than one level. The selection is 
kept in the URL
+  (``log_level``), so a filtered link can be shared with a teammate.
+* Use **Search logs...** to jump between matches for an error message, a table 
name or a request
+  ID. Press ``l``, ``t`` or ``w`` to show or hide log levels and timestamps, 
or toggle line wrapping.
+* A task that retried has one log per try. Pick the try from **Task Tries** 
above the log. The
+  first try usually has the original error. Later tries can fail on a side 
effect of it, such as a
+  partially written table.
+
+Inspecting XComs
+''''''''''''''''
+
+Many failures come from a task receiving the wrong input rather than from its 
own code. Open the
+upstream task instance and check its **XCom** tab to see exactly what it 
pushed for that run. To
+compare values across runs and Dags, use **Browse > XComs**.
+
+For how XComs are pushed and pulled, see :ref:`concepts:xcom`.
+
+Checking Connections and Variables
+''''''''''''''''''''''''''''''''''
+
+A task that works in one environment and fails in another usually points at 
configuration. Check
+that the Connection or Variable the task uses exists and resolves to the value 
you expect:
+
+.. code-block:: bash
+
+  airflow connections get my_postgres
+  airflow variables get my_variable
+
+Both commands resolve values the same way tasks do, so they also find 
Connections and Variables
+defined in a secrets backend or in ``AIRFLOW_CONN_*`` and ``AIRFLOW_VAR_*`` 
environment variables.
+**Admin > Connections** and **Admin > Variables** in the UI only list entries 
stored in the
+metadata database.
+
+If ``[core] test_connection`` is set to ``Enabled``, ``airflow connections 
test my_postgres``, or
+**Test Connection** in **Admin > Connections**, checks that Airflow can reach 
the target system.
+
+Looking at past runs
+''''''''''''''''''''
+
+Comparing a failing run with the last good one narrows down what changed. The 
Grid view shows the
+state of every task across recent runs, and the **Runs** tab of a Dag lists 
them with their run
+type and duration. From the CLI:
+
+.. code-block:: bash
+
+  airflow dags list-runs my_dag --state failed --limit 5
+  airflow tasks states-for-dag-run my_dag <run_id>
+
+Check whether the failure started with a particular run, a new Dag version or 
a change in input
+data before changing any code.
+
+Re-running a single task
+''''''''''''''''''''''''
+
+Once you have a fix, clear only the task that failed instead of triggering a 
new Dag run. In the UI,
+select the task instance and use **Clear Task Instance**. The dialog lets you 
include
+**Downstream** tasks, which you usually want so that results depending on the 
fixed task are
+recomputed, and **Upstream**, **Past** or **Future** task instances when 
needed. It lists the
+affected tasks before you confirm.
+
+The CLI equivalent clears matching task instances over a date range:
+
+.. code-block:: bash
+
+  airflow tasks clear my_dag --task-regex '^load_orders$' --downstream \

Review Comment:
   Good catch, thanks. Switched the examples to `airflowctl dagrun list`, 
`tasks states-for-dag-run` and `tasks clear`, and ran each through the 
airflowctl parser. Found two more while I was in there: `airflowctl variables 
get` goes through the API, so it only sees the metadata DB, and that paragraph 
is about seeing what a task resolves from a secrets backend, so I kept the 
legacy command there and said why. `airflowctl connections test` takes a full 
connection definition instead of a conn id, so I dropped that one and kept the 
UI's Test Connection.



##########
airflow-core/docs/core-concepts/debug.rst:
##########
@@ -112,3 +112,104 @@ Run ``python -m pdb <path to Dag file>.py`` for an 
interactive debugging experie
       dag.test()
 
 2. Run / debug the Dag file.
+
+Debugging Dags in a running deployment
+--------------------------------------
+
+``dag.test()`` covers local development. Once a Dag runs in a shared 
deployment, most debugging
+starts from a failed or misbehaving task instance. The techniques below work 
from the UI and from
+the ``airflow`` CLI on any machine that can reach the metadata database.
+
+Reading task logs
+'''''''''''''''''
+
+Open the failed task instance from the Grid view and go to the **Logs** tab.
+
+* Use the log level filter (**All Log Levels** by default) to show only 
``WARNING``, ``ERROR`` or
+  ``CRITICAL`` lines. You can select more than one level. The selection is 
kept in the URL
+  (``log_level``), so a filtered link can be shared with a teammate.
+* Use **Search logs...** to jump between matches for an error message, a table 
name or a request
+  ID. Press ``l``, ``t`` or ``w`` to show or hide log levels and timestamps, 
or toggle line wrapping.
+* A task that retried has one log per try. Pick the try from **Task Tries** 
above the log. The
+  first try usually has the original error. Later tries can fail on a side 
effect of it, such as a
+  partially written table.
+
+Inspecting XComs
+''''''''''''''''
+
+Many failures come from a task receiving the wrong input rather than from its 
own code. Open the
+upstream task instance and check its **XCom** tab to see exactly what it 
pushed for that run. To
+compare values across runs and Dags, use **Browse > XComs**.
+
+For how XComs are pushed and pulled, see :ref:`concepts:xcom`.
+
+Checking Connections and Variables
+''''''''''''''''''''''''''''''''''
+
+A task that works in one environment and fails in another usually points at 
configuration. Check
+that the Connection or Variable the task uses exists and resolves to the value 
you expect:
+
+.. code-block:: bash
+
+  airflow connections get my_postgres
+  airflow variables get my_variable
+
+Both commands resolve values the same way tasks do, so they also find 
Connections and Variables
+defined in a secrets backend or in ``AIRFLOW_CONN_*`` and ``AIRFLOW_VAR_*`` 
environment variables.
+**Admin > Connections** and **Admin > Variables** in the UI only list entries 
stored in the
+metadata database.
+
+If ``[core] test_connection`` is set to ``Enabled``, ``airflow connections 
test my_postgres``, or
+**Test Connection** in **Admin > Connections**, checks that Airflow can reach 
the target system.
+
+Looking at past runs
+''''''''''''''''''''
+
+Comparing a failing run with the last good one narrows down what changed. The 
Grid view shows the
+state of every task across recent runs, and the **Runs** tab of a Dag lists 
them with their run
+type and duration. From the CLI:
+
+.. code-block:: bash
+
+  airflow dags list-runs my_dag --state failed --limit 5
+  airflow tasks states-for-dag-run my_dag <run_id>
+
+Check whether the failure started with a particular run, a new Dag version or 
a change in input
+data before changing any code.
+
+Re-running a single task
+''''''''''''''''''''''''
+
+Once you have a fix, clear only the task that failed instead of triggering a 
new Dag run. In the UI,
+select the task instance and use **Clear Task Instance**. The dialog lets you 
include
+**Downstream** tasks, which you usually want so that results depending on the 
fixed task are
+recomputed, and **Upstream**, **Past** or **Future** task instances when 
needed. It lists the
+affected tasks before you confirm.
+
+The CLI equivalent clears matching task instances over a date range:

Review Comment:
   Agreed, calling it the CLI equivalent was wrong. It now uses `airflowctl 
tasks clear`, says it discards task state like the UI does (with 
`--keep-task-state` to keep it), notes that the legacy command always keeps it, 
and links dag-run and resumable-tasks. Added the idempotency warning too. I 
also called out that `airflowctl tasks clear` only dry-runs without 
`--no-dry-run` and clears only failed and upstream-failed tasks by default, 
since that would catch out anyone copying the example.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to