# sky/cli.py# Tail the controller logs of a service
skyservelogs--controller[SERVICE_NAME]# Print the load balancer logs so far and exit
skyservelogs--load-balancer--no-follow[SERVICE_NAME]# Tail the logs of replica 1
skyservelogs[SERVICE_NAME]1
# sky/backends/cloud_vm_ray_backend.pydeftail_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. """
We trace the code_generation functions, namely serve_lib.ServeCodeGen.stream_serve_process_logs() and serve_lib.ServeCodeGen.stream_replica_logs() (Details omitted for brevity).
And we realize they just return the cmd in CLI in string form.
Then it shows that tail_serve_logs() will use this run_on_head() to run the cmd above.
# sky/utils/command_runner.pyclassCommandRunner:......@timeline.eventdefrun(self,cmd:Union[str,List[str]],*,require_outputs:bool=False,# Advanced options.log_path:str=os.devnull,# If False, do not redirect stdout/stderr to optimize performance.process_stream:bool=True,stream_logs:bool=True,ssh_mode:SshMode=SshMode.NON_INTERACTIVE,separate_stderr:bool=False,connect_timeout:Optional[int]=None,source_bashrc:bool=False,skip_lines:int=0,**kwargs)->Union[int,Tuple[int,str,str]]:"""Runs the command on the cluster. Args: cmd: The command to run. require_outputs: Whether to return the stdout/stderr of the command. log_path: Redirect stdout/stderr to the log_path. stream_logs: Stream logs to the stdout/stderr. ssh_mode: The mode to use for ssh. See SSHMode for more details. separate_stderr: Whether to separate stderr from stdout. connect_timeout: timeout in seconds for the ssh connection. source_bashrc: Whether to source the ~/.bashrc before running the command. skip_lines: The number of lines to skip at the beginning of the output. This is used when the output is not processed by SkyPilot but we still want to get rid of some warning messages, such as SSH warnings. Returns: returncode or A tuple of (returncode, stdout, stderr). """raiseNotImplementedError......
Following the cmd related to sky serve logs on website:
Bash
123
skyservelogsvicuna1# tail logs of replica 1, including provisioning and running logs
skyservelogsvicuna--controller# tail controller logs
skyservelogsvicuna--load-balancer--no-follow# print the load balancer logs so far, and exit
Bash
12345678
# sky/cli.py# Tail the controller logs of a service
skyservelogs--controller[SERVICE_NAME]# Print the load balancer logs so far and exit
skyservelogs--load-balancer--no-follow[SERVICE_NAME]# Tail the logs of replica 1
skyservelogs[SERVICE_NAME]1
I find they should be implemented in sky/utils/command_runner.py (Details omitted for brevity):
Python
1 2 3 4 5 6 7 8 91011121314151617
defrun(self,cmd:Union[str,List[str]],*,require_outputs:bool=False,# Advanced options.log_path:str=os.devnull,# If False, do not redirect stdout/stderr to optimize performance.process_stream:bool=True,stream_logs:bool=True,ssh_mode:SshMode=SshMode.NON_INTERACTIVE,separate_stderr:bool=False,connect_timeout:Optional[int]=None,source_bashrc:bool=False,skip_lines:int=0,**kwargs)->Union[int,Tuple[int,str,str]]:'''......'''raiseNotImplementedError
But now this run() function is not implemented? I don't understand how do we run the corresponding cmds in CLI?