Skip to content
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

[Serve][Core] Refactor serve tail logs to serve core #4046

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from sky import optimizer
from sky import provision as provision_lib
from sky import resources as resources_lib
from sky import serve as serve_lib
from sky import sky_logging
from sky import status_lib
from sky import task as task_lib
Expand Down Expand Up @@ -4037,43 +4036,6 @@ def _rsync_down(args) -> None:
f'{colorama.Style.RESET_ALL}')
return {str(job_id): local_log_dir}

def tail_serve_logs(self, handle: CloudVmRayResourceHandle,
service_name: str, target: serve_lib.ServiceComponent,
replica_id: Optional[int], follow: bool) -> None:
"""Tail the logs of a service.

Args:
handle: The handle to the sky serve controller.
service_name: The name of the service.
target: The component to tail the logs of. Could be controller,
load balancer, or replica.
replica_id: The replica ID to tail the logs of. Only used when
target is replica.
follow: Whether to follow the logs.
"""
if target != serve_lib.ServiceComponent.REPLICA:
code = serve_lib.ServeCodeGen.stream_serve_process_logs(
service_name,
stream_controller=(
target == serve_lib.ServiceComponent.CONTROLLER),
follow=follow)
else:
assert replica_id is not None, service_name
code = serve_lib.ServeCodeGen.stream_replica_logs(
service_name, replica_id, follow)

signal.signal(signal.SIGINT, backend_utils.interrupt_handler)
signal.signal(signal.SIGTSTP, backend_utils.stop_handler)

self.run_on_head(
handle,
code,
stream_logs=True,
process_stream=False,
ssh_mode=command_runner.SshMode.INTERACTIVE,
stdin=subprocess.DEVNULL,
)

def teardown_no_lock(self,
handle: CloudVmRayResourceHandle,
terminate: bool,
Expand Down
33 changes: 28 additions & 5 deletions sky/serve/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""SkyServe core APIs."""
import re
import signal
import subprocess
import tempfile
import threading
from typing import Any, Dict, List, Optional, Tuple, Union

import colorama
Expand All @@ -18,6 +21,7 @@
from sky.skylet import constants
from sky.usage import usage_lib
from sky.utils import admin_policy_utils
from sky.utils import command_runner
from sky.utils import common_utils
from sky.utils import controller_utils
from sky.utils import resources_utils
Expand Down Expand Up @@ -731,8 +735,27 @@ def tail_logs(

backend = backend_utils.get_backend_from_handle(handle)
assert isinstance(backend, backends.CloudVmRayBackend), backend
backend.tail_serve_logs(handle,
service_name,
target,
replica_id,
follow=follow)

if target != serve_utils.ServiceComponent.REPLICA:
code = serve_utils.ServeCodeGen.stream_serve_process_logs(
service_name,
stream_controller=(
target == serve_utils.ServiceComponent.CONTROLLER),
follow=follow)
else:
assert replica_id is not None, service_name
code = serve_utils.ServeCodeGen.stream_replica_logs(
service_name, replica_id, follow)

# With the stdin=subprocess.DEVNULL, the ctrl-c will not directly
# kill the process, so we need to handle it manually here.
if threading.current_thread() is threading.main_thread():
cblmemo marked this conversation as resolved.
Show resolved Hide resolved
signal.signal(signal.SIGINT, backend_utils.interrupt_handler)
signal.signal(signal.SIGTSTP, backend_utils.stop_handler)

backend.run_on_head(handle,
code,
stream_logs=True,
process_stream=False,
ssh_mode=command_runner.SshMode.INTERACTIVE,
stdin=subprocess.DEVNULL)
Loading