Skip to content

Commit

Permalink
fix: Missing CLIContext and log-level config in wsproxy and manager C…
Browse files Browse the repository at this point in the history
…LI (#2698)

Co-authored-by: Kyujin Cho <[email protected]>
  • Loading branch information
achimnol and kyujin-cho authored Sep 30, 2024
1 parent f35ccb9 commit d0379fe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/2698.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing implementation of wsproxy and manager CLI's log-level customization options
2 changes: 2 additions & 0 deletions src/ai/backend/manager/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def main(
Manager Administration CLI
"""
setproctitle("backend.ai: manager.cli")
if debug:
log_level = LogLevel.DEBUG
ctx.obj = ctx.with_resource(CLIContext(config_path, log_level))


Expand Down
8 changes: 7 additions & 1 deletion src/ai/backend/manager/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ def __enter__(self) -> Self:
# If we duplicate the local logging with it, the process termination may hang.
click_ctx = click.get_current_context()
if click_ctx.invoked_subcommand != "start-server":
logging_config = {}
logging_config = {
"level": self.log_level,
"pkg-ns": {
"": LogLevel.WARNING,
"ai.backend": self.log_level,
},
}
try:
# Try getting the logging config but silently fallback to the default if not
# present (e.g., when `mgr gql show` command used in CI without installation as
Expand Down
29 changes: 28 additions & 1 deletion src/ai/backend/wsproxy/cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import importlib
import json
import logging
from pathlib import Path
from typing import Any

Expand All @@ -15,9 +16,30 @@
from ..config import ServerConfig, generate_example_json
from ..openapi import generate_openapi
from ..utils import ensure_json_serializable
from .context import CLIContext

log = logging.getLogger(__spec__.name) # type: ignore[name-defined,union-attr]


@click.group(invoke_without_command=False, context_settings={"help_option_names": ["-h", "--help"]})
@click.option(
"-f",
"--config-path",
"--config",
type=click.Path(
file_okay=True,
dir_okay=False,
exists=True,
path_type=Path,
),
default=None,
help="The config file path. (default: ./manager.conf and /etc/backend.ai/manager.conf)",
)
@click.option(
"--debug",
is_flag=True,
help="Set the logging level to DEBUG",
)
@click.option(
"--log-level",
type=click.Choice([*LogLevel], case_sensitive=False),
Expand All @@ -27,12 +49,17 @@
@click.pass_context
def main(
ctx: click.Context,
log_level: str,
config_path: Path,
log_level: LogLevel,
debug: bool,
) -> None:
"""
Backend.AI WSProxy CLI
"""
setproctitle("backend.ai: wsproxy.cli")
if debug:
log_level = LogLevel.DEBUG
ctx.obj = ctx.with_resource(CLIContext(config_path, log_level))


@main.command()
Expand Down
8 changes: 7 additions & 1 deletion src/ai/backend/wsproxy/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def __enter__(self) -> Self:
# If we duplicate the local logging with it, the process termination may hang.
click_ctx = click.get_current_context()
if click_ctx.invoked_subcommand != "start-server":
self._logger = LocalLogger({})
self._logger = LocalLogger({
"level": self.log_level,
"pkg-ns": {
"": LogLevel.WARNING,
"ai.backend": self.log_level,
},
})
self._logger.__enter__()
return self

Expand Down
14 changes: 12 additions & 2 deletions src/ai/backend/wsproxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,28 @@ async def server_main_logwrapper(
default=None,
help=("The config file path. (default: ./wsproxy.toml and /etc/backend.ai/wsproxy.toml)"),
)
@click.option(
"--debug",
is_flag=True,
help="This option will soon change to --log-level TEXT option.",
)
@click.option(
"--log-level",
type=click.Choice([*LogLevel], case_sensitive=False),
default=LogLevel.NOTSET,
help="Set the logging verbosity level",
)
@click.pass_context
def main(ctx: click.Context, config_path: Path, log_level: LogLevel) -> None:
def main(
ctx: click.Context,
config_path: Path,
log_level: str,
debug: bool = False,
) -> None:
"""
Start the wsproxy service as a foreground process.
"""
cfg = load_config(config_path, log_level)
cfg = load_config(config_path, LogLevel.DEBUG if debug else LogLevel[log_level])

if ctx.invoked_subcommand is None:
cfg.wsproxy.pid_file.touch(exist_ok=True)
Expand Down

0 comments on commit d0379fe

Please sign in to comment.