You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2026/06/12 20:15:24 UTC
(airflow) branch revert-68078-fix/api-server-init-task-sdk-stats created (now 54df9a3aab2)
This is an automated email from the ASF dual-hosted git repository.
ashb pushed a change to branch revert-68078-fix/api-server-init-task-sdk-stats
in repository https://gitbox.apache.org/repos/asf/airflow.git
at 54df9a3aab2 Revert "Explicitly initialize Task SDK Stats in API server lifespan (hardenin…"
This branch includes the following new commits:
new 54df9a3aab2 Revert "Explicitly initialize Task SDK Stats in API server lifespan (hardenin…"
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(airflow) 01/01: Revert "Explicitly initialize Task SDK Stats in API server lifespan (hardenin…"
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ashb pushed a commit to branch revert-68078-fix/api-server-init-task-sdk-stats
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 54df9a3aab270f00ee9f8a20fd12ce2fa3180d3f
Author: Ash Berlin-Taylor <as...@firemirror.com>
AuthorDate: Fri Jun 12 21:15:12 2026 +0100
Revert "Explicitly initialize Task SDK Stats in API server lifespan (hardenin…"
This reverts commit 38c50f5b54ed77e125aa95e3005c7bc8e7ad361e.
---
airflow-core/src/airflow/api_fastapi/app.py | 24 --------------
airflow-core/tests/unit/api_fastapi/test_app.py | 43 -------------------------
2 files changed, 67 deletions(-)
diff --git a/airflow-core/src/airflow/api_fastapi/app.py b/airflow-core/src/airflow/api_fastapi/app.py
index 45b64dc36f7..8931840c880 100644
--- a/airflow-core/src/airflow/api_fastapi/app.py
+++ b/airflow-core/src/airflow/api_fastapi/app.py
@@ -71,32 +71,8 @@ class _AuthManagerState:
_lock = threading.Lock()
-def _initialize_task_sdk_stats() -> None:
- """
- Initialize the Task SDK ``Stats`` singleton in the API server process.
-
- Initialization is guarded so a metrics misconfiguration can never prevent the API server
- from starting.
- """
- try:
- from airflow._shared.observability.metrics import stats
- from airflow.observability.metrics import stats_utils
-
- stats.initialize(
- factory=stats_utils.get_stats_factory(),
- export_legacy_names=conf.getboolean("metrics", "legacy_names_on"),
- )
- except Exception:
- log.warning(
- "Failed to initialize Task SDK Stats in the API server; metrics emitted through the "
- "Task SDK Stats singleton will not be recorded.",
- exc_info=True,
- )
-
-
@asynccontextmanager
async def lifespan(app: FastAPI):
- _initialize_task_sdk_stats()
async with AsyncExitStack() as stack:
for route in app.routes:
if isinstance(route, Mount) and isinstance(route.app, FastAPI):
diff --git a/airflow-core/tests/unit/api_fastapi/test_app.py b/airflow-core/tests/unit/api_fastapi/test_app.py
index 1633e11de4e..1e8817ef243 100644
--- a/airflow-core/tests/unit/api_fastapi/test_app.py
+++ b/airflow-core/tests/unit/api_fastapi/test_app.py
@@ -168,46 +168,3 @@ def test_create_auth_manager_thread_safety():
assert call_count == 1
app_module.purge_cached_app()
-
-
-class TestInitializeTaskSdkStats:
- """
- Ensure that stats subsystem is properly initialized in API server.
- """
-
- def test_initializes_task_sdk_stats_with_factory(self):
- """It initializes the Task SDK Stats singleton using the configured factory."""
- sentinel_factory = object()
- with (
- mock.patch("airflow._shared.observability.metrics.stats") as mock_stats,
- mock.patch(
- "airflow.observability.metrics.stats_utils.get_stats_factory",
- return_value=sentinel_factory,
- ) as mock_get_factory,
- ):
- app_module._initialize_task_sdk_stats()
-
- mock_get_factory.assert_called_once_with()
- mock_stats.initialize.assert_called_once()
- _, kwargs = mock_stats.initialize.call_args
- assert kwargs["factory"] is sentinel_factory
- assert isinstance(kwargs["export_legacy_names"], bool)
-
- def test_stats_failure_does_not_block_startup(self, caplog):
- """A metrics misconfiguration must not prevent the API server from starting."""
- with (
- mock.patch("airflow._shared.observability.metrics.stats") as mock_stats,
- mock.patch("airflow.observability.metrics.stats_utils.get_stats_factory"),
- ):
- mock_stats.initialize.side_effect = RuntimeError("boom")
-
- # Must not raise.
- app_module._initialize_task_sdk_stats()
-
- assert any("Failed to initialize Task SDK Stats" in rec.message for rec in caplog.records)
-
- def test_stats_initialized_during_lifespan(self, client):
- """_initialize_task_sdk_stats must be called as part of the app lifespan, not just defined."""
- with mock.patch.object(app_module, "_initialize_task_sdk_stats") as mock_init:
- with client():
- mock_init.assert_called_once()