From 03c11d3b85ff54b1caf121cfbfcb1a2de49340a6 Mon Sep 17 00:00:00 2001 From: Max Fitton Date: Tue, 29 Sep 2020 17:57:49 -0700 Subject: [PATCH] [Dashboard] Add Ray Config API to Reporter Head (#11010) * Add Ray Config API to the backend for fetching config * Address PR comments. * Make reporter cache whole payload * lint Co-authored-by: Max Fitton --- dashboard/modules/reporter/reporter_head.py | 46 ++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/dashboard/modules/reporter/reporter_head.py b/dashboard/modules/reporter/reporter_head.py index 932a34854..f0ff25dd8 100644 --- a/dashboard/modules/reporter/reporter_head.py +++ b/dashboard/modules/reporter/reporter_head.py @@ -1,6 +1,7 @@ import json import logging - +import yaml +import os import aiohttp.web from aioredis.pubsub import Receiver from grpc.experimental import aio as aiogrpc @@ -52,6 +53,49 @@ class ReportHead(dashboard_utils.DashboardHeadModule): message="Profiling success.", profiling_info=profiling_info) + @routes.get("/api/ray_config") + async def get_ray_config(self, req) -> aiohttp.web.Response: + if self._ray_config is None: + try: + config_path = os.path.expanduser("~/ray_bootstrap_config.yaml") + with open(config_path) as f: + cfg = yaml.safe_load(f) + except yaml.YAMLError: + return await dashboard_utils.rest_response( + success=False, + message=f"No config found at {config_path}.", + ) + except FileNotFoundError: + return await dashboard_utils.rest_response( + success=False, + message=f"Invalid config, could not load YAML.") + + payload = { + "min_workers": cfg["min_workers"], + "max_workers": cfg["max_workers"], + "initial_workers": cfg["initial_workers"], + "autoscaling_mode": cfg["autoscaling_mode"], + "idle_timeout_minutes": cfg["idle_timeout_minutes"], + } + + try: + payload["head_type"] = cfg["head_node"]["InstanceType"] + except KeyError: + payload["head_type"] = "unknown" + + try: + payload["worker_type"] = cfg["worker_nodes"]["InstanceType"] + except KeyError: + payload["worker_type"] = "unknown" + + self._ray_config = payload + + return await dashboard_utils.rest_response( + success=True, + message="Fetched ray config.", + **self._ray_config, + ) + async def run(self, server): aioredis_client = self._dashboard_head.aioredis_client receiver = Receiver()