Skip to content

Commit 6332afc

Browse files
Move fastapi-api command to api-server (apache#47076)
1 parent 9bca963 commit 6332afc

File tree

17 files changed

+78
-81
lines changed

17 files changed

+78
-81
lines changed

airflow/api_fastapi/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ async def lifespan(app: FastAPI):
6161
def create_app(apps: str = "all") -> FastAPI:
6262
apps_list = apps.split(",") if apps else ["all"]
6363

64-
fastapi_base_url = conf.get("fastapi", "base_url")
64+
fastapi_base_url = conf.get("api", "base_url")
6565
if fastapi_base_url.endswith("/"):
66-
raise AirflowConfigException("fastapi.base_url conf cannot have a trailing slash.")
66+
raise AirflowConfigException("`[api] base_url` config option cannot have a trailing slash.")
6767

6868
root_path = urlsplit(fastapi_base_url).path
6969
if not root_path or root_path == "/":

airflow/api_fastapi/core_api/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def init_views(app: FastAPI) -> None:
7979
def webapp(request: Request, rest_of_path: str):
8080
return templates.TemplateResponse(
8181
"/index.html",
82-
{"request": request, "backend_server_base_url": conf.get("fastapi", "base_url")},
82+
{"request": request, "backend_server_base_url": conf.get("api", "base_url")},
8383
media_type="text/html",
8484
)
8585

airflow/api_fastapi/gunicorn_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def post_worker_init(_):
2727
"""
2828
Set process title.
2929
30-
This is used by airflow.cli.commands.local_commands.fastapi_api_command to track the status of the worker.
30+
This is used by airflow.cli.commands.local_commands.api_server_command to track the status of the worker.
3131
"""
3232
old_title = setproctitle.getproctitle()
3333
setproctitle.setproctitle(settings.GUNICORN_WORKER_READY_PREFIX + old_title)

airflow/cli/cli_config.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -697,48 +697,48 @@ def string_lower_type(val):
697697
help="The access log format for gunicorn logs",
698698
)
699699

700-
# fastapi-api
701-
ARG_FASTAPI_API_PORT = Arg(
700+
# api-server
701+
ARG_API_SERVER_PORT = Arg(
702702
("-p", "--port"),
703703
default=9091,
704704
type=int,
705-
help="The port on which to run the server",
705+
help="The port on which to run the API server",
706706
)
707-
ARG_FASTAPI_API_WORKERS = Arg(
707+
ARG_API_SERVER_WORKERS = Arg(
708708
("-w", "--workers"),
709709
default=4,
710710
type=int,
711-
help="Number of workers to run the FastAPI API-on",
711+
help="Number of workers to run on the API server",
712712
)
713-
ARG_FASTAPI_API_WORKER_TIMEOUT = Arg(
713+
ARG_API_SERVER_WORKER_TIMEOUT = Arg(
714714
("-t", "--worker-timeout"),
715715
default=120,
716716
type=int,
717-
help="The timeout for waiting on FastAPI API workers",
717+
help="The timeout for waiting on API server workers",
718718
)
719-
ARG_FASTAPI_API_HOSTNAME = Arg(
719+
ARG_API_SERVER_HOSTNAME = Arg(
720720
("-H", "--hostname"),
721721
default="0.0.0.0", # nosec
722-
help="Set the hostname on which to run the web server",
722+
help="Set the hostname on which to run the API server",
723723
)
724-
ARG_FASTAPI_API_ACCESS_LOGFILE = Arg(
724+
ARG_API_SERVER_ACCESS_LOGFILE = Arg(
725725
("-A", "--access-logfile"),
726726
help="The logfile to store the access log. Use '-' to print to stdout",
727727
)
728-
ARG_FASTAPI_API_ERROR_LOGFILE = Arg(
728+
ARG_API_SERVER_ERROR_LOGFILE = Arg(
729729
("-E", "--error-logfile"),
730730
help="The logfile to store the error log. Use '-' to print to stderr",
731731
)
732-
ARG_FASTAPI_API_ACCESS_LOGFORMAT = Arg(
732+
ARG_API_SERVER_ACCESS_LOGFORMAT = Arg(
733733
("-L", "--access-logformat"),
734734
help="The access log format for gunicorn logs",
735735
)
736-
ARG_FASTAPI_API_APPS = Arg(
736+
ARG_API_SERVER_APPS = Arg(
737737
("--apps",),
738738
help="Applications to run (comma-separated). Default is all. Options: core, execution, all",
739739
default="all",
740740
)
741-
ARG_FASTAPI_API_ALLOW_PROXY_FORWARDING = Arg(
741+
ARG_API_SERVER_ALLOW_PROXY_FORWARDING = Arg(
742742
flags=("--proxy-headers",),
743743
help="Enable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info.",
744744
action="store_true",
@@ -1881,27 +1881,27 @@ class GroupCommand(NamedTuple):
18811881
),
18821882
),
18831883
ActionCommand(
1884-
name="fastapi-api",
1885-
help="Start an Airflow FastAPI API instance",
1886-
func=lazy_load_command("airflow.cli.commands.local_commands.fastapi_api_command.fastapi_api"),
1884+
name="api-server",
1885+
help="Start an Airflow API server instance",
1886+
func=lazy_load_command("airflow.cli.commands.local_commands.api_server_command.api_server"),
18871887
args=(
1888-
ARG_FASTAPI_API_PORT,
1889-
ARG_FASTAPI_API_WORKERS,
1890-
ARG_FASTAPI_API_WORKER_TIMEOUT,
1891-
ARG_FASTAPI_API_HOSTNAME,
1888+
ARG_API_SERVER_PORT,
1889+
ARG_API_SERVER_WORKERS,
1890+
ARG_API_SERVER_WORKER_TIMEOUT,
1891+
ARG_API_SERVER_HOSTNAME,
18921892
ARG_PID,
18931893
ARG_DAEMON,
18941894
ARG_STDOUT,
18951895
ARG_STDERR,
1896-
ARG_FASTAPI_API_ACCESS_LOGFILE,
1897-
ARG_FASTAPI_API_ERROR_LOGFILE,
1898-
ARG_FASTAPI_API_ACCESS_LOGFORMAT,
1899-
ARG_FASTAPI_API_APPS,
1896+
ARG_API_SERVER_ACCESS_LOGFILE,
1897+
ARG_API_SERVER_ERROR_LOGFILE,
1898+
ARG_API_SERVER_ACCESS_LOGFORMAT,
1899+
ARG_API_SERVER_APPS,
19001900
ARG_LOG_FILE,
19011901
ARG_SSL_CERT,
19021902
ARG_SSL_KEY,
19031903
ARG_DEBUG,
1904-
ARG_FASTAPI_API_ALLOW_PROXY_FORWARDING,
1904+
ARG_API_SERVER_ALLOW_PROXY_FORWARDING,
19051905
),
19061906
),
19071907
ActionCommand(

airflow/cli/commands/local_commands/fastapi_api_command.py renamed to airflow/cli/commands/local_commands/api_server_command.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
@cli_utils.action_cli
4444
@providers_configuration_loaded
45-
def fastapi_api(args):
46-
"""Start Airflow FastAPI API."""
45+
def api_server(args):
46+
"""Start Airflow API server."""
4747
print(settings.HEADER)
4848

4949
apps = args.apps
@@ -54,7 +54,7 @@ def fastapi_api(args):
5454
proxy_headers = args.proxy_headers
5555

5656
if args.debug:
57-
print(f"Starting the FastAPI API server on port {args.port} and host {args.hostname} debug.")
57+
print(f"Starting the API server on port {args.port} and host {args.hostname} debug.")
5858
log.warning("Running in dev mode, ignoring uvicorn args")
5959

6060
run_args = [
@@ -83,7 +83,7 @@ def fastapi_api(args):
8383
else:
8484
if args.daemon:
8585
daemonize()
86-
log.info("Daemonized the FastAPI API server process PID: %s", os.getpid())
86+
log.info("Daemonized the API server process PID: %s", os.getpid())
8787

8888
log.info(
8989
textwrap.dedent(
@@ -99,7 +99,7 @@ def fastapi_api(args):
9999
)
100100
)
101101
ssl_cert, ssl_key = _get_ssl_cert_and_key_filepaths(args)
102-
setproctitle(f"airflow fastapi_api -- host:{args.hostname} port:{args.port}")
102+
setproctitle(f"airflow api_server -- host:{args.hostname} port:{args.port}")
103103
uvicorn.run(
104104
"airflow.api_fastapi.main:app",
105105
host=args.hostname,

airflow/cli/commands/local_commands/standalone_command.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def run(self):
8989
command=["webserver"],
9090
env=env,
9191
)
92-
self.subcommands["fastapi-api"] = SubCommand(
92+
self.subcommands["api-server"] = SubCommand(
9393
self,
94-
name="fastapi-api",
95-
command=["fastapi-api"],
94+
name="api-server",
95+
command=["api-server"],
9696
env=env,
9797
)
9898
self.subcommands["triggerer"] = SubCommand(
@@ -151,7 +151,7 @@ def print_output(self, name: str, output):
151151
You can pass multiple lines to output if you wish; it will be split for you.
152152
"""
153153
color: dict[str, Color] = {
154-
"fastapi-api": "magenta",
154+
"api-server": "magenta",
155155
"webserver": "green",
156156
"scheduler": "blue",
157157
"dag-processor": "yellow",

airflow/config_templates/config.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,15 @@ debug:
13131313
api:
13141314
description: ~
13151315
options:
1316+
base_url:
1317+
description: |
1318+
The base url of the API server. Airflow cannot guess what domain or CNAME you are using.
1319+
If the Airflow console (the front-end) and the API server are on a different domain, this config
1320+
should contain the API server endpoint.
1321+
version_added: ~
1322+
type: string
1323+
example: ~
1324+
default: "http://localhost:9091"
13161325
auth_backends:
13171326
description: |
13181327
Comma separated list of auth backends to authenticate users of the API. See
@@ -2705,15 +2714,3 @@ dag_processor:
27052714
type: integer
27062715
example: ~
27072716
default: "5"
2708-
fastapi:
2709-
description: Configuration for the Fastapi webserver.
2710-
options:
2711-
base_url:
2712-
description: |
2713-
The base url of the Fastapi endpoint. Airflow cannot guess what domain or CNAME you are using.
2714-
If the Airflow console (the front-end) and the Fastapi apis are on a different domain, this config
2715-
should contain the Fastapi apis endpoint.
2716-
version_added: ~
2717-
type: string
2718-
example: ~
2719-
default: "http://localhost:9091"

chart/values.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4853,7 +4853,7 @@
48534853
"default": [
48544854
"bash",
48554855
"-c",
4856-
"exec airflow fastapi-api"
4856+
"exec airflow api-server"
48574857
]
48584858
},
48594859
"strategy": {

chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ _apiServer:
12611261
# Command to use when running the Airflow API server (templated).
12621262
command: ~
12631263
# Args to use when running the Airflow API server (templated).
1264-
args: ["bash", "-c", "exec airflow fastapi-api"]
1264+
args: ["bash", "-c", "exec airflow api-server"]
12651265
env: []
12661266
serviceAccount:
12671267
# default value is true

docs/apache-airflow/administration-and-deployment/web-stack.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Web Stack
2121
=========
2222

2323
Sometimes you want to deploy the backend and frontend behind a
24-
variable url path prefix. To do so, you can configure the url :ref:`config:fastapi__base_url`
24+
variable url path prefix. To do so, you can configure the url :ref:`config:api__base_url`
2525
for instance, set it to ``http://localhost:29091/d12345``. All the APIs routes will
2626
now be available through that additional ``d12345`` prefix. Without rebuilding
2727
the frontend, XHR requests and static file queries should be directed to the prefixed url

0 commit comments

Comments
 (0)