Skip to content

Commit

Permalink
Prettify post launch prints (#1716)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewitt1 authored Jan 28, 2025
1 parent 1fb436f commit 493c19a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
19 changes: 5 additions & 14 deletions runhouse/resources/hardware/launcher_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SSEClient,
)
from runhouse.rns.utils.api import generate_ssh_keys, load_resp_content, read_resp_data
from runhouse.utils import ClusterLogsFormatter, Spinner
from runhouse.utils import ClusterLogsFormatter, ColoredFormatter, Spinner

logger = get_logger(__name__)

Expand Down Expand Up @@ -180,20 +180,17 @@ def run_verbose(
if event.event == "info":
logger.info(event.data)

if event.event == "log":
log_processor.log_event(event)

if event.event == "step_complete":
event_data = ast.literal_eval(event.data)
step_complete = event_data.get("step")
total_steps = event_data.get("total_steps")
message = event_data.get("message")

# use a custom message step completion
BLUE = "\033[94m"
ITALIC = "\033[3m"
RESET = "\033[0m"
styled_message = f"{BLUE}{ITALIC}► Step {step_complete}/{total_steps}: {message}{RESET}"
blue = ColoredFormatter.get_color("blue")
italic = ColoredFormatter.get_color("italic")
reset = ColoredFormatter.get_color("reset")
styled_message = f"{blue}{italic}► Step {step_complete}/{total_steps}: {message}{reset}"

if spinner:
# Temporarily pause the spinner to output the step if it's currently running
Expand Down Expand Up @@ -293,9 +290,6 @@ def up(cls, cluster, verbose: bool = True, force: bool = False):
)
cluster.cluster_status = ClusterStatus.RUNNING
cls._update_from_den_response(cluster=cluster, config=data)
logger.info(
f"To view this cluster in Den, visit https://run.house/resources/{rns_client.format_rns_address(cluster.rns_address)}"
)
return
except Exception as e:
cluster.cluster_status = ClusterStatus.UNKNOWN
Expand All @@ -315,9 +309,6 @@ def up(cls, cluster, verbose: bool = True, force: bool = False):
)
data = read_resp_data(resp)
logger.info("Successfully launched cluster")
logger.info(
f"To view this cluster in Den, visit https://run.house/resources/{rns_client.format_rns_address(cluster.rns_address)}"
)
cluster.cluster_status = ClusterStatus.RUNNING
cls._update_from_den_response(cluster=cluster, config=data)

Expand Down
3 changes: 3 additions & 0 deletions runhouse/resources/hardware/on_demand_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
_cluster_set_autostop_command,
ClusterStatus,
LauncherType,
pprint_launched_cluster_summary,
RunhouseDaemonStatus,
ServerConnectionType,
up_cluster_helper,
Expand Down Expand Up @@ -647,6 +648,8 @@ def up(self, verbose: bool = True, force: bool = False, start_server: bool = Tru
logger.info("Starting Runhouse server on cluster")
self.start_server()

pprint_launched_cluster_summary(cluster=self)

return self

def keep_warm(self, mins: int = -1):
Expand Down
35 changes: 32 additions & 3 deletions runhouse/resources/hardware/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ssh_options_list,
SshMode,
)
from runhouse.utils import run_setup_command
from runhouse.utils import ColoredFormatter, run_setup_command

logger = get_logger(__name__)

Expand Down Expand Up @@ -394,8 +394,6 @@ def up_cluster_helper(cluster, capture_output: Union[bool, str] = True):
###################################
# Cluster list helping methods
###################################


def parse_time_duration(duration: str):
# A simple parser for duration like "15m", "2h", "3d"
try:
Expand Down Expand Up @@ -579,6 +577,37 @@ def get_running_and_not_running_clusters(clusters: list):
)


def pprint_launched_cluster_summary(cluster):
properties: dict = cluster.compute_properties
cluster_name = cluster.name
rns_address = cluster.rns_address
properties["autostop_mins"] = cluster.autostop_mins

blue = ColoredFormatter.get_color("blue")
white = ColoredFormatter.get_color("white")
cyan = ColoredFormatter.get_color("cyan")
green = ColoredFormatter.get_color("green")
reset = ColoredFormatter.get_color("reset")
italic = ColoredFormatter.get_color("italic")

print(
f"► To view the cluster in Den, visit https://run.house/resources/{rns_client.format_rns_address(rns_address)}"
)
print(f"{blue}Launch Summary:{reset}")
for key, value in properties.items():
if value is None:
continue
bullet = f"{white}{reset}"
key_str = f"{blue}{key.replace('_', ' ').capitalize()}{reset}"
value_str = f"{green}{value}{reset}"
print(f"{bullet} {key_str}: {value_str}")

print(
f"To teardown the cluster, run {italic}{cyan}runhouse cluster down {cluster_name}{reset}, "
f'or in python via {italic}{cyan}rh.cluster("{cluster_name}").teardown(){reset}'
)


###################################
# CLUSTER LOGS
###################################
Expand Down
2 changes: 2 additions & 0 deletions runhouse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ class ColoredFormatter:
"magenta": "\u001b[35m",
"cyan": "\u001b[36m",
"white": "\u001b[37m",
"bold": "\u001b[1m",
"italic": "\u001b[3m",
"reset": "\u001b[0m",
}

Expand Down

0 comments on commit 493c19a

Please sign in to comment.