Skip to content

Commit 0358f54

Browse files
[Feat][Core/Dashboard] Convert ReportHead to subprocess module (#51733)
Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
1 parent 5195be5 commit 0358f54

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

python/ray/dashboard/head.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ def _load_subprocess_module_handles(
297297
cluster_id_hex=self.cluster_id_hex,
298298
gcs_address=self.gcs_address,
299299
session_name=self.session_name,
300+
temp_dir=self.temp_dir,
300301
logging_level=self.logging_level,
301302
logging_format=self.logging_format,
302303
log_dir=self.log_dir,

python/ray/dashboard/modules/reporter/reporter_head.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
from ray.core.generated import reporter_pb2, reporter_pb2_grpc
2727
from ray.dashboard.consts import GCS_RPC_TIMEOUT_SECONDS
2828
from ray.dashboard.state_aggregator import StateAPIManager
29+
from ray.dashboard.subprocesses.routes import SubprocessRouteTable as routes
30+
from ray.dashboard.subprocesses.module import SubprocessModule
2931
from ray.util.state.common import ListApiOptions
3032
from ray.util.state.state_manager import StateDataSourceClient
3133

3234
logger = logging.getLogger(__name__)
33-
routes = dashboard_optional_utils.DashboardHeadRouteTable
3435

3536
EMOJI_WARNING = "&#x26A0;&#xFE0F;"
3637
WARNING_FOR_MULTI_TASK_IN_A_WORKER = (
@@ -54,9 +55,9 @@
5455
)
5556

5657

57-
class ReportHead(dashboard_utils.DashboardHeadModule):
58-
def __init__(self, config: dashboard_utils.DashboardHeadModuleConfig):
59-
super().__init__(config)
58+
class ReportHead(SubprocessModule):
59+
def __init__(self, *args, **kwargs):
60+
super().__init__(*args, **kwargs)
6061
self._ray_config = None
6162
# TODO(fyrestone): Avoid using ray.state in dashboard, it's not
6263
# asynchronous and will lead to low performance. ray disconnect()
@@ -697,7 +698,8 @@ def _make_stub(
697698
channel = init_grpc_channel(ip_port, options=options, asynchronous=True)
698699
return reporter_pb2_grpc.ReporterServiceStub(channel)
699700

700-
async def run(self, server):
701+
async def run(self):
702+
await super().run()
701703
self._state_api_data_source_client = StateDataSourceClient(
702704
self.aiogrpc_gcs_channel, self.gcs_aio_client
703705
)
@@ -719,7 +721,3 @@ async def run(self, server):
719721
namespace=KV_NAMESPACE_CLUSTER,
720722
)
721723
self.cluster_metadata = json.loads(cluster_metadata.decode("utf-8"))
722-
723-
@staticmethod
724-
def is_minimal_module():
725-
return False

python/ray/dashboard/modules/reporter/tests/test_reporter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
import ray
1616
from ray._private import ray_constants
1717
from ray._private.metrics_agent import fix_grpc_metric
18+
import ray._private.usage.usage_lib as ray_usage_lib
1819
from ray._private.test_utils import (
1920
fetch_prometheus,
2021
format_web_url,
2122
wait_for_condition,
23+
wait_until_server_available,
2224
)
2325
from ray.core.generated.metrics_pb2 import Metric
2426
from ray.dashboard.modules.reporter.reporter_agent import ReporterAgent
@@ -948,5 +950,20 @@ def verify():
948950
wait_for_condition(verify, timeout=10)
949951

950952

953+
def test_get_cluster_metadata(ray_start_with_dashboard):
954+
assert wait_until_server_available(ray_start_with_dashboard["webui_url"])
955+
webui_url = format_web_url(ray_start_with_dashboard["webui_url"])
956+
url = f"{webui_url}/api/v0/cluster_metadata"
957+
958+
resp = requests.get(url)
959+
assert resp.status_code == 200
960+
resp_data = resp.json()["data"]
961+
meta = ray_usage_lib._generate_cluster_metadata(ray_init_cluster=True)
962+
assert len(resp_data) == len(meta)
963+
assert resp_data["pythonVersion"] == meta["python_version"]
964+
assert resp_data["rayVersion"] == meta["ray_version"]
965+
assert resp_data["rayInitCluster"] == meta["ray_init_cluster"]
966+
967+
951968
if __name__ == "__main__":
952969
sys.exit(pytest.main(["-v", __file__]))

python/ray/dashboard/subprocesses/module.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SubprocessModuleConfig:
3535
cluster_id_hex: str
3636
gcs_address: str
3737
session_name: str
38+
temp_dir: str
3839
# Logger configs. Will be set up in subprocess entrypoint `run_module`.
3940
logging_level: str
4041
logging_format: str
@@ -175,6 +176,10 @@ def session_name(self):
175176
"""
176177
return self._config.session_name
177178

179+
@property
180+
def temp_dir(self):
181+
return self._config.temp_dir
182+
178183
@property
179184
def log_dir(self):
180185
return self._config.log_dir

python/ray/dashboard/subprocesses/tests/test_e2e.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def default_module_config(tmp_path) -> SubprocessModuleConfig:
2727
cluster_id_hex="test_cluster_id",
2828
gcs_address="",
2929
session_name="test_session",
30+
temp_dir=str(tmp_path),
3031
logging_level=ray_constants.LOGGER_LEVEL,
3132
logging_format=ray_constants.LOGGER_FORMAT,
3233
log_dir=str(tmp_path),

0 commit comments

Comments
 (0)