-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Refactor serve_logs with FastAPI #52581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
potiuk
merged 7 commits into
apache:main
from
jason810496:refactor/logging/replace-flask-serve-log-with-fastapi
Jul 9, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bee1422
Refactor serve_logs with FastAPI
jason810496 5210522
Remove details for 403 forbidden response
jason810496 eea5f5d
Replace Gunicorn with Uvicorn
jason810496 ef2b873
Fix uvicorn multiple workers error
jason810496 63227b8
Remove flask and gunicorn from airflow-core/pyproject.toml
jason810496 8ffb9e1
Remove old serve_logs module and add gunicorn to spelling_wordlist
jason810496 491285c
Merge branch 'main' into refactor/logging/replace-flask-serve-log-wit…
jason810496 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # 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. | ||
| from __future__ import annotations | ||
|
|
||
| from airflow.utils.serve_logs.core import serve_logs | ||
| from airflow.utils.serve_logs.log_server import create_app | ||
|
|
||
| __all__ = ["serve_logs", "create_app"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # 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. | ||
| """Serve logs process.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import socket | ||
| import sys | ||
|
|
||
| import uvicorn | ||
|
|
||
| from airflow.configuration import conf | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def serve_logs(port=None): | ||
| """Serve logs generated by Worker.""" | ||
| # setproctitle causes issue on Mac OS: https://github.com/benoitc/gunicorn/issues/3021 | ||
| os_type = sys.platform | ||
| if os_type == "darwin": | ||
| logger.debug("Mac OS detected, skipping setproctitle") | ||
| else: | ||
| from setproctitle import setproctitle | ||
|
|
||
| setproctitle("airflow serve-logs") | ||
|
|
||
| port = port or conf.getint("logging", "WORKER_LOG_SERVER_PORT") | ||
|
|
||
| # If dual stack is available and IPV6_V6ONLY is not enabled on the socket | ||
| # then when IPV6 is bound to it will also bind to IPV4 automatically | ||
| if getattr(socket, "has_dualstack_ipv6", lambda: False)(): | ||
| host = "::" # ASGI uses `::` syntax for IPv6 binding instead of the `[::]` notation used in WSGI, while preserving the `[::]` format in logs | ||
| serve_log_uri = f"http://[::]:{port}" | ||
| else: | ||
| host = "0.0.0.0" | ||
| serve_log_uri = f"http://{host}:{port}" | ||
|
|
||
| logger.info("Starting log server on %s", serve_log_uri) | ||
|
|
||
| # Use uvicorn directly for ASGI applications | ||
| uvicorn.run("airflow.utils.serve_logs.log_server:app", host=host, port=port, workers=2, log_level="info") | ||
| # Note: if we want to use more than 1 workers, we **can't** use the instance of FastAPI directly | ||
| # This is way we split the instantiation of log server to a separate module | ||
| # | ||
| # https://github.com/encode/uvicorn/blob/374bb6764e8d7f34abab0746857db5e3d68ecfdd/docs/deployment/index.md?plain=1#L50-L63 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| serve_logs() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.