Skip to content

Commit

Permalink
[MOD-3657] fix logs user msg (#2186)
Browse files Browse the repository at this point in the history
  • Loading branch information
thundergolfer authored Sep 4, 2024
1 parent c38a882 commit 369abf0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
11 changes: 7 additions & 4 deletions modal/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,11 @@ async def put_pty_content(log: api_pb2.TaskLogs, stdout):


async def get_app_logs_loop(
client: _Client, output_mgr: OutputManager, app_id: Optional[str] = None, task_id: Optional[str] = None
client: _Client,
output_mgr: OutputManager,
app_id: Optional[str] = None,
task_id: Optional[str] = None,
app_logs_url: Optional[str] = None,
):
last_log_batch_entry_id = ""

Expand Down Expand Up @@ -616,11 +620,10 @@ async def _get_logs():
try:
await _get_logs()
except asyncio.CancelledError:
# TODO: this should come from the backend maybe
app_logs_url = f"https://modal.com/logs/{app_id}"
view_logs_url = app_logs_url if app_logs_url else "https://modal.com/logs/"
output_mgr.print(
f"[red]Timed out waiting for logs. "
f"[grey70]View logs at [underline]{app_logs_url}[/underline] for remaining output.[/grey70]"
f"[grey70]View logs at [underline]{view_logs_url}[/underline] for remaining output.[/grey70]"
)
raise
except (GRPCError, StreamTerminatedError, socket.gaierror, AttributeError) as exc:
Expand Down
2 changes: 1 addition & 1 deletion modal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def deploy(
res = deploy_app(app, name=name, environment_name=env or "", tag=tag)

if stream_logs:
stream_app_logs(res.app_id)
stream_app_logs(app_id=res.app_id, app_logs_url=res.app_logs_url)


def serve(
Expand Down
6 changes: 4 additions & 2 deletions modal/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@


@synchronizer.create_blocking
async def stream_app_logs(app_id: Optional[str] = None, task_id: Optional[str] = None):
async def stream_app_logs(
app_id: Optional[str] = None, task_id: Optional[str] = None, app_logs_url: Optional[str] = None
):
client = await _Client.from_env()
output_mgr = OutputManager(status_spinner_text=f"Tailing logs for {app_id}")
try:
with output_mgr.show_status_spinner():
await get_app_logs_loop(client, output_mgr, app_id, task_id)
await get_app_logs_loop(client, output_mgr, app_id=app_id, task_id=task_id, app_logs_url=app_logs_url)
except asyncio.CancelledError:
pass
except GRPCError as exc:
Expand Down
17 changes: 13 additions & 4 deletions modal/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ async def _init_local_app_new(
app_state=app_state,
)
app_resp = await retry_transient_errors(client.stub.AppCreate, app_req)
app_page_url = app_resp.app_page_url
logger.debug(f"Created new app with id {app_resp.app_id}")
return RunningApp(
app_resp.app_id, app_page_url=app_page_url, environment_name=environment_name, interactive=interactive
app_resp.app_id,
app_page_url=app_resp.app_page_url,
app_logs_url=app_resp.app_logs_url,
environment_name=environment_name,
interactive=interactive,
)


Expand Down Expand Up @@ -275,7 +278,9 @@ async def _run_app(
output_mgr.update_app_page_url(running_app.app_page_url)

# Start logs loop
logs_loop = tc.create_task(get_app_logs_loop(client, output_mgr, running_app.app_id))
logs_loop = tc.create_task(
get_app_logs_loop(client, output_mgr, app_id=running_app.app_id, app_logs_url=running_app.app_logs_url)
)

exc_info: Optional[BaseException] = None
try:
Expand Down Expand Up @@ -389,6 +394,8 @@ class DeployResult:
"""Dataclass representing the result of deploying an app."""

app_id: str
app_page_url: str
app_logs_url: str


async def _deploy_app(
Expand Down Expand Up @@ -478,7 +485,9 @@ async def _deploy_app(
t = time.time() - t0
output_mgr.print(step_completed(f"App deployed in {t:.3f}s! 🎉"))
output_mgr.print(f"\nView Deployment: [magenta]{app_url}[/magenta]")
return DeployResult(app_id=running_app.app_id)
return DeployResult(
app_id=running_app.app_id, app_page_url=running_app.app_page_url, app_logs_url=running_app.app_logs_url
)


async def _interactive_shell(_app: _App, cmds: List[str], environment_name: str = "", **kwargs: Any) -> None:
Expand Down
1 change: 1 addition & 0 deletions modal/running_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RunningApp:
app_id: str
environment_name: Optional[str] = None
app_page_url: Optional[str] = None
app_logs_url: Optional[str] = None
tag_to_object_id: Dict[str, str] = field(default_factory=dict)
object_handle_metadata: Dict[str, Optional[Message]] = field(default_factory=dict)
interactive: bool = False

0 comments on commit 369abf0

Please sign in to comment.