Skip to content

Commit 00aec39

Browse files
potiukkaxil
andauthored
Bring back serve_logs to be in the core (#49031)
The `serve_logs` has been moved in #48457 to fab provider by mistake. It should remain in the airflow-core. We still depend on flask in the core (but as a next step we can replace it by starlette and unicorn). Fixes: #49028 Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
1 parent 485ef13 commit 00aec39

File tree

10 files changed

+18
-46
lines changed

10 files changed

+18
-46
lines changed

airflow-core/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ dependencies = [
8484
# 0.115.10 fastapi was a bad release that broke our API's and static checks.
8585
# Related fastapi issue here: https://github.com/fastapi/fastapi/discussions/13431
8686
"fastapi[standard]>=0.115.0,!=0.115.10",
87+
# We could get rid of flask and gunicorn if we replace serve_logs with a starlette + unicorn
88+
"flask>=2.1.1",
8789
"gitpython>=3.1.40",
90+
# We could get rid of flask and gunicorn if we replace serve_logs with a starlette + unicorn
8891
"gunicorn>=20.1.0",
8992
"httpx>=0.25.0",
9093
'importlib_metadata>=6.5;python_version<"3.12"',

airflow-core/src/airflow/cli/commands/scheduler_command.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from airflow.executors.executor_loader import ExecutorLoader
3030
from airflow.jobs.job import Job, run_job
3131
from airflow.jobs.scheduler_job_runner import SchedulerJobRunner
32-
from airflow.providers.celery.version_compat import AIRFLOW_V_3_0_PLUS
3332
from airflow.utils import cli as cli_utils
3433
from airflow.utils.providers_configuration_loader import providers_configuration_loaded
3534
from airflow.utils.scheduler_health import serve_health_check
@@ -60,18 +59,7 @@ def scheduler(args: Namespace):
6059

6160
@contextmanager
6261
def _serve_logs(skip_serve_logs: bool = False):
63-
"""Start serve_logs sub-process."""
64-
if AIRFLOW_V_3_0_PLUS:
65-
try:
66-
from airflow.providers.fab.www.serve_logs import serve_logs
67-
except ImportError:
68-
raise ImportError(
69-
"Celery requires FAB provider to be installed in order to run this command. "
70-
"Please install the FAB provider by running: "
71-
"pip install apache-airflow-providers-celery[fab]"
72-
)
73-
else:
74-
from airflow.utils.serve_logs import serve_logs # type: ignore[no-redef]
62+
from airflow.utils.serve_logs import serve_logs
7563

7664
sub_proc = None
7765
executor_class, _ = ExecutorLoader.import_default_executor_cls()

airflow-core/src/airflow/cli/commands/triggerer_command.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,14 @@
2828
from airflow.configuration import conf
2929
from airflow.jobs.job import Job, run_job
3030
from airflow.jobs.triggerer_job_runner import TriggererJobRunner
31-
from airflow.providers.celery.version_compat import AIRFLOW_V_3_0_PLUS
3231
from airflow.utils import cli as cli_utils
3332
from airflow.utils.providers_configuration_loader import providers_configuration_loaded
3433

3534

3635
@contextmanager
3736
def _serve_logs(skip_serve_logs: bool = False) -> Generator[None, None, None]:
3837
"""Start serve_logs sub-process."""
39-
if AIRFLOW_V_3_0_PLUS:
40-
try:
41-
from airflow.providers.fab.www.serve_logs import serve_logs
42-
except ImportError:
43-
raise ImportError(
44-
"Celery requires FAB provider to be installed in order to run this command. "
45-
"Please install the FAB provider by running: "
46-
"pip install apache-airflow-providers-celery[fab]"
47-
)
48-
else:
49-
from airflow.utils.serve_logs import serve_logs # type: ignore[no-redef]
38+
from airflow.utils.serve_logs import serve_logs
5039

5140
sub_proc = None
5241
if skip_serve_logs is False:

providers/fab/src/airflow/providers/fab/www/serve_logs.py renamed to airflow-core/src/airflow/utils/serve_logs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import logging
2222
import os
2323
import socket
24+
import sys
2425
from collections import namedtuple
2526

2627
import gunicorn.app.base
@@ -32,7 +33,6 @@
3233
InvalidIssuedAtError,
3334
InvalidSignatureError,
3435
)
35-
from setproctitle import setproctitle
3636
from werkzeug.exceptions import HTTPException
3737

3838
from airflow.api_fastapi.auth.tokens import JWTValidator, get_signing_key
@@ -169,6 +169,13 @@ def load(self):
169169

170170
def serve_logs(port=None):
171171
"""Serve logs generated by Worker."""
172+
# setproctitle causes issue on Mac OS: https://github.com/benoitc/gunicorn/issues/3021
173+
os_type = sys.platform
174+
if os_type == "darwin":
175+
logger.debug("Mac OS detected, skipping setproctitle")
176+
else:
177+
from setproctitle import setproctitle
178+
172179
setproctitle("airflow serve-logs")
173180
wsgi_app = create_app()
174181

airflow-core/tests/unit/cli/commands/test_scheduler_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
from airflow.cli import cli_parser
2626
from airflow.cli.commands import scheduler_command
2727
from airflow.executors import executor_loader
28-
from airflow.providers.fab.www.serve_logs import serve_logs
2928
from airflow.utils.scheduler_health import serve_health_check
29+
from airflow.utils.serve_logs import serve_logs
3030

3131
from tests_common.test_utils.config import conf_vars
3232

providers/fab/tests/unit/fab/www/test_serve_logs.py renamed to airflow-core/tests/unit/utils/test_serve_logs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
from airflow.api_fastapi.auth.tokens import JWTGenerator
2828
from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG
29-
from airflow.providers.fab.www.serve_logs import create_app
3029
from airflow.utils import timezone
30+
from airflow.utils.serve_logs import create_app
3131

3232
from tests_common.test_utils.config import conf_vars
3333

@@ -81,7 +81,7 @@ def sample_log(request, tmp_path):
8181
base_log_dir = Path(DEFAULT_LOGGING_CONFIG["handlers"]["task"]["base_log_folder"])
8282
else:
8383
raise ValueError(f"Unknown client fixture: {client}")
84-
84+
base_log_dir.mkdir(exist_ok=True, parents=True)
8585
f = base_log_dir.joinpath("sample.log")
8686
f.write_text(LOG_DATA)
8787
return f

dev/breeze/tests/test_selective_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ def test_upgrade_to_newer_dependencies(
21572157
),
21582158
pytest.param(
21592159
("providers/celery/src/airflow/providers/celery/file.py",),
2160-
{"docs-list-as-string": "celery cncf.kubernetes fab"},
2160+
{"docs-list-as-string": "celery cncf.kubernetes"},
21612161
id="Celery python files changed",
21622162
),
21632163
pytest.param(

providers/celery/README.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ You can install such cross-provider dependencies when installing from PyPI. For
7575
Dependent package Extra
7676
====================================================================================================================== ===================
7777
`apache-airflow-providers-cncf-kubernetes <https://airflow.apache.org/docs/apache-airflow-providers-cncf-kubernetes>`_ ``cncf.kubernetes``
78-
`apache-airflow-providers-fab <https://airflow.apache.org/docs/apache-airflow-providers-fab>`_ ``fab``
7978
====================================================================================================================== ===================
8079

8180
The changelog for the provider package can be found in the

providers/celery/pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,13 @@ dependencies = [
7272
"cncf.kubernetes" = [
7373
"apache-airflow-providers-cncf-kubernetes>=7.4.0",
7474
]
75-
"fab" = [
76-
"apache-airflow-providers-fab>=2.0.0",
77-
]
7875

7976
[dependency-groups]
8077
dev = [
8178
"apache-airflow",
8279
"apache-airflow-task-sdk",
8380
"apache-airflow-devel-common",
8481
"apache-airflow-providers-cncf-kubernetes",
85-
"apache-airflow-providers-fab",
8682
# Additional devel dependencies (do not remove this line and add extra development dependencies)
8783
]
8884

providers/celery/src/airflow/providers/celery/cli/celery_command.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,7 @@ def flower(args):
107107
@contextmanager
108108
def _serve_logs(skip_serve_logs: bool = False):
109109
"""Start serve_logs sub-process."""
110-
if AIRFLOW_V_3_0_PLUS:
111-
try:
112-
from airflow.providers.fab.www.serve_logs import serve_logs
113-
except ImportError:
114-
raise ImportError(
115-
"Celery requires FAB provider to be installed in order to run this command. "
116-
"Please install the FAB provider by running: "
117-
"pip install apache-airflow-providers-celery[fab]"
118-
)
119-
else:
120-
from airflow.utils.serve_logs import serve_logs # type: ignore[no-redef]
110+
from airflow.utils.serve_logs import serve_logs
121111

122112
sub_proc = None
123113
if skip_serve_logs is False:

0 commit comments

Comments
 (0)