Skip to content

Commit

Permalink
[Dashboard] Add Ray Config API to Reporter Head (#11010)
Browse files Browse the repository at this point in the history
* Add Ray Config API to the backend for fetching config

* Address PR comments.

* Make reporter cache whole payload

* lint

Co-authored-by: Max Fitton <max@semprehealth.com>
  • Loading branch information
mfitton and Max Fitton authored Sep 30, 2020
1 parent 94494c4 commit 03c11d3
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion dashboard/modules/reporter/reporter_head.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -52,6 +53,49 @@ async def launch_profiling(self, req) -> aiohttp.web.Response:
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()
Expand Down

0 comments on commit 03c11d3

Please sign in to comment.