Skip to content

Commit

Permalink
[CherryPick] [Core] Fix ray start command output (ray-project#34081) (r…
Browse files Browse the repository at this point in the history
…ay-project#34273)

With ray-project#32409, we stopped printing out information like dashboard url when creating a single node ray cluster on OSX and windows. This is a regression and this PR reverts back to the old behavior.

Signed-off-by: Jiajun Yao <[email protected]>
  • Loading branch information
jjyao authored Apr 11, 2023
1 parent cb6f1c2 commit 26be96d
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 126 deletions.
3 changes: 2 additions & 1 deletion python/ray/_private/ray_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,11 @@ def gcs_actor_scheduling_enabled():

# Whether to enable Ray clusters (in addition to local Ray).
# Ray clusters are not explicitly supported for Windows and OSX.
IS_WINDOWS_OR_OSX = sys.platform == "darwin" or sys.platform == "win32"
ENABLE_RAY_CLUSTERS_ENV_VAR = "RAY_ENABLE_WINDOWS_OR_OSX_CLUSTER"
ENABLE_RAY_CLUSTER = env_bool(
ENABLE_RAY_CLUSTERS_ENV_VAR,
not (sys.platform == "darwin" or sys.platform == "win32"),
not IS_WINDOWS_OR_OSX,
)

SESSION_LATEST = "session_latest"
Expand Down
3 changes: 0 additions & 3 deletions python/ray/_private/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,6 @@ def resolve_ip_for_localhost(address: str):
raise ValueError(f"Malformed address: {address}")
address_parts = address.split(":")
if address_parts[0] == "127.0.0.1" or address_parts[0] == "localhost":
# Clusters are disabled by default for OSX and Windows.
if not ray_constants.ENABLE_RAY_CLUSTER:
return address
# Make sure localhost isn't resolved to the loopback ip
ip_address = get_node_ip_address()
return ":".join([ip_address] + address_parts[1:])
Expand Down
4 changes: 0 additions & 4 deletions python/ray/_private/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,10 +1431,6 @@ def init(
gcs_address = bootstrap_address
logger.info("Connecting to existing Ray cluster at address: %s...", gcs_address)

# NOTE(swang): We must set the node IP address *after* we determine whether
# this is an existing cluster or not. For Windows and OSX, the resolved IP
# is localhost for new clusters and the usual public IP for existing
# clusters.
if _node_ip_address is not None:
node_ip_address = services.resolve_ip_for_localhost(_node_ip_address)
raylet_ip_address = node_ip_address
Expand Down
120 changes: 48 additions & 72 deletions python/ray/scripts/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ def start(
cf.bold("--port"),
)

# Whether the original arguments include node_ip_address.
include_node_ip_address = False
if node_ip_address is not None:
include_node_ip_address = True
node_ip_address = services.resolve_ip_for_localhost(node_ip_address)

resources = parse_resources_json(resources, cli_logger, cf)
Expand Down Expand Up @@ -747,104 +750,77 @@ def start(
cli_logger.newline()
with cli_logger.group("Next steps"):
dashboard_url = node.address_info["webui_url"]
if bootstrap_address.startswith("127.0.0.1:"):
if ray_constants.ENABLE_RAY_CLUSTER:
cli_logger.print(
"This Ray runtime only accepts connections from local host."
)
cli_logger.print(
"To accept connections from remote hosts, "
"specify a public ip when starting"
)
cli_logger.print(
"the head node: ray start --head --node-ip-address=<public-ip>."
)
else:
cli_logger.print(
"Multi-node Ray clusters are not supported on OSX and Windows."
)
cli_logger.print(
"If you would like to proceed anyway, restart Ray with:"
)
cli_logger.print(
cf.bold(" ray stop"),
)
cli_logger.print(
cf.bold(" {}=true ray start"),
ray_constants.ENABLE_RAY_CLUSTERS_ENV_VAR,
)
cli_logger.newline()
else:
if ray_constants.ENABLE_RAY_CLUSTER:
cli_logger.print("To add another node to this Ray cluster, run")
# NOTE(kfstorm): Java driver rely on this line to get the address
# of the cluster. Please be careful when updating this line.
cli_logger.print(
cf.bold(" ray start --address='{}'"),
cf.bold(" {} ray start --address='{}'"),
f" {ray_constants.ENABLE_RAY_CLUSTERS_ENV_VAR}=1"
if ray_constants.IS_WINDOWS_OR_OSX
else "",
bootstrap_address,
)
cli_logger.newline()
if ray_constants.ENABLE_RAY_CLUSTER:

cli_logger.newline()
cli_logger.print("To connect to this Ray cluster:")
with cli_logger.indented():
cli_logger.print("{} ray", cf.magenta("import"))
cli_logger.print(
"To connect to this Ray cluster, run `ray.init()` as usual:"
)
with cli_logger.indented():
cli_logger.print("{} ray", cf.magenta("import"))
cli_logger.print(
"ray{}init()",
cf.magenta("."),
"ray{}init({})",
cf.magenta("."),
"_node_ip_address{}{}".format(
cf.magenta("="), cf.yellow("'" + node_ip_address + "'")
)
cli_logger.newline()
cli_logger.print(
"To connect to this Ray instance from outside of "
"the cluster, for example "
)
cli_logger.print(
"when connecting to a remote cluster from your laptop, "
"make sure the"
if include_node_ip_address
else "",
)

if dashboard_url:
cli_logger.newline()
cli_logger.print("To submit a Ray job using the Ray Jobs CLI:")
cli_logger.print(
"dashboard {}is accessible and use the Ray Jobs API. For example:",
f"({dashboard_url}) " if dashboard_url else "",
cf.bold(
" RAY_ADDRESS='http://{}' ray job submit "
"--working-dir . "
"-- python my_script.py"
),
dashboard_url,
)
if dashboard_url:
cli_logger.print(
cf.bold(
" RAY_ADDRESS='http://<dashboard URL>:{}' ray job submit "
"--working-dir . "
"-- python my_script.py"
),
ray_params.dashboard_port,
)
cli_logger.newline()
cli_logger.print(
"See https://docs.ray.io/en/latest/cluster/running-applications"
"/job-submission/index.html"
"/job-submission/index.html "
)
cli_logger.print(
"for more information on connecting to the Ray cluster from "
"a remote client."
"for more information on submitting Ray jobs to the Ray cluster."
)

cli_logger.newline()
cli_logger.print("To terminate the Ray runtime, run")
cli_logger.print(cf.bold(" ray stop"))

cli_logger.newline()
cli_logger.print("To view the status of the cluster, use")
cli_logger.print(" {}".format(cf.bold("ray status")))

if dashboard_url:
cli_logger.newline()
cli_logger.print("To see the status of the cluster, use")
cli_logger.print(" {}".format(cf.bold("ray status")))
if dashboard_url:
cli_logger.print("To monitor and debug Ray, view the dashboard at ")
cli_logger.print(
" {}".format(
cf.bold(dashboard_url),
)
cli_logger.print("To monitor and debug Ray, view the dashboard at ")
cli_logger.print(
" {}".format(
cf.bold(dashboard_url),
)
)

cli_logger.newline()
cli_logger.print(
cf.underlined(
"If connection fails, check your "
"If connection to the dashboard fails, check your "
"firewall settings and "
"network configuration."
)
)
cli_logger.newline()
cli_logger.print("To terminate the Ray runtime, run")
cli_logger.print(cf.bold(" ray stop"))
ray_params.gcs_address = bootstrap_address
else:
# Start worker node.
Expand Down
8 changes: 2 additions & 6 deletions python/ray/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,6 @@ def test_disable_usage_stats(monkeypatch, tmp_path):
assert '{"usage_stats": false}' == tmp_usage_stats_config_path.read_text()


@pytest.mark.skipif(
sys.platform == "darwin" and "travis" in os.environ.get("USER", ""),
reason=("Mac builds don't provide proper locale support"),
)
def test_ray_start(configure_lang, monkeypatch, tmp_path, cleanup_ray):
monkeypatch.setenv("RAY_USAGE_STATS_CONFIG_PATH", str(tmp_path / "config.json"))
runner = CliRunner()
Expand All @@ -306,8 +302,8 @@ def test_ray_start(configure_lang, monkeypatch, tmp_path, cleanup_ray):

_die_on_error(runner.invoke(scripts.stop))

if ray.util.get_node_ip_address() == "127.0.0.1":
_check_output_via_pattern("test_ray_start_localhost.txt", result)
if ray_constants.IS_WINDOWS_OR_OSX:
_check_output_via_pattern("test_ray_start_windows_osx.txt", result)
else:
_check_output_via_pattern("test_ray_start.txt", result)

Expand Down
22 changes: 10 additions & 12 deletions python/ray/tests/test_cli_patterns/test_ray_start.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ Next steps
To add another node to this Ray cluster, run
ray start --address='.+'

To connect to this Ray cluster, run `ray.init\(\)` as usual:
To connect to this Ray cluster:
import ray
ray\.init\(\)

To connect to this Ray instance from outside of the cluster, for example
when connecting to a remote cluster from your laptop, make sure the
dashboard (.*) is accessible and use the Ray Jobs API\. For example:
RAY_ADDRESS='http://<dashboard URL>:8265' ray job submit --working-dir \. -- python my_script\.py
To submit a Ray job using the Ray Jobs CLI:
RAY_ADDRESS='http://.+:8265' ray job submit --working-dir \. -- python my_script\.py

See https://docs\.ray\.io/en/latest/cluster/running-applications/job-submission/index\.html
for more information on connecting to the Ray cluster from a remote client\.
for more information on submitting Ray jobs to the Ray cluster.

To see the status of the cluster, use
To terminate the Ray runtime, run
ray stop

To view the status of the cluster, use
ray status

To monitor and debug Ray, view the dashboard at
127.0.0.1:8265

If connection fails, check your firewall settings and network configuration.

To terminate the Ray runtime, run
ray stop

If connection to the dashboard fails, check your firewall settings and network configuration.
28 changes: 0 additions & 28 deletions python/ray/tests/test_cli_patterns/test_ray_start_localhost.txt

This file was deleted.

32 changes: 32 additions & 0 deletions python/ray/tests/test_cli_patterns/test_ray_start_windows_osx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Usage stats collection is enabled by default without user confirmation because this terminal is detected to be non-interactive\..+

Local node IP: .+

--------------------
Ray runtime started.
--------------------

Next steps
To add another node to this Ray cluster, run
RAY_ENABLE_WINDOWS_OR_OSX_CLUSTER=1 ray start --address='.+'

To connect to this Ray cluster:
import ray
ray\.init\(\)

To submit a Ray job using the Ray Jobs CLI:
RAY_ADDRESS='http://.+:8265' ray job submit --working-dir \. -- python my_script\.py

See https://docs\.ray\.io/en/latest/cluster/running-applications/job-submission/index\.html
for more information on submitting Ray jobs to the Ray cluster.

To terminate the Ray runtime, run
ray stop

To view the status of the cluster, use
ray status

To monitor and debug Ray, view the dashboard at
127.0.0.1:8265

If connection to the dashboard fails, check your firewall settings and network configuration.

0 comments on commit 26be96d

Please sign in to comment.