From bf27c97d492be168f627b624043877693d9fd91d Mon Sep 17 00:00:00 2001 From: fritz-astronomer <80706212+fritz-astronomer@users.noreply.github.com> Date: Tue, 5 Aug 2025 14:31:15 -0400 Subject: [PATCH] [v3-0-test] Add FAQ entry about testing connections and "Canary" Dag (#54110) * feat: add FAQ about testing connections and canary dag * fix: static checks * fix: Static checks (cherry picked from commit 85de1fe9b80e82db3f7b668bc23f56c66b1f75fc) Co-authored-by: fritz-astronomer <80706212+fritz-astronomer@users.noreply.github.com> --- airflow-core/docs/faq.rst | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/airflow-core/docs/faq.rst b/airflow-core/docs/faq.rst index a37dcba6eb53e..f74c4194928bb 100644 --- a/airflow-core/docs/faq.rst +++ b/airflow-core/docs/faq.rst @@ -540,3 +540,38 @@ This means ``explicit_defaults_for_timestamp`` is disabled in your mysql server #. Set ``explicit_defaults_for_timestamp = 1`` under the ``mysqld`` section in your ``my.cnf`` file. #. Restart the Mysql server. + +Connections +^^^^^^^^^^^ + +How can I test a connection or use a Canary Dag? +------------------------------------------------ + +For security reasons, the test connection functionality is disabled by default across the Airflow UI, +API and CLI. This can be modified by setting ref:`config:core__test_connection`. + +You can utilize a Dag to regularly test connections. This is referred to as a "Canary Dag" and can detect and +alert on failures in external systems that your Dags depend on. You can create a simple Dag that tests connections +such as the following Airflow 3 example: + +.. code-block:: python + + from airflow import DAG + from airflow.sdk import task + + with DAG(dag_id="canary", schedule="@daily", doc_md="Canary DAG to regularly test connections to systems."): + + @task(doc_md="Test a connection by its Connection ID.") + def test_connection(conn_id): + from airflow.hooks.base import BaseHook + + ok, status = BaseHook.get_hook(conn_id=conn_id).test_connection() + if ok: + return status + raise RuntimeError(status) + + for conn_id in [ + # Add more connections here to create tasks to test them. + "aws_default", + ]: + test_connection.override(task_id="test_" + conn_id)(conn_id)