forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from anyscale/hd-e2e-impl
[Hosted Dashboard] End to end flow
- Loading branch information
Showing
12 changed files
with
214 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import argparse | ||
|
||
from aiohttp import web | ||
|
||
|
||
async def health(request): | ||
return web.json_response({"Status": "Healty"}) | ||
|
||
|
||
async def return_ingest_server_url(request): | ||
# TODO(sang): Prepare the proper authorization process. | ||
result = {"ingestor_url": "localhost:50051", "access_token": "1234"} | ||
return web.json_response(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--host", | ||
required=False, | ||
type=str, | ||
default="127.0.0.1", | ||
help="The host to use for the GRPC server.") | ||
parser.add_argument( | ||
"--port", | ||
required=False, | ||
default=8080, | ||
type=str, | ||
help="The port to use for the GRPC server.") | ||
args = parser.parse_args() | ||
app = web.Application() | ||
app.add_routes([ | ||
web.get("/auth", return_ingest_server_url), | ||
web.get("/health", health) | ||
]) | ||
web.run_app(app, host=args.host, port=args.port, shutdown_timeout=5.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
python/ray/dashboard/closed_source/prometheus/prometheus_export_server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import json | ||
import logging | ||
import redis | ||
|
||
# TODO(sang): Add this module to requirements | ||
from prometheus_client import start_http_server, Gauge | ||
|
||
import ray | ||
|
||
from ray.dashboard.closed_source.ingest_server \ | ||
import NODE_INFO_CHANNEL, RAY_INFO_CHANNEL | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
# TODO(sang) Refactor to have more scalable structure | ||
# TODO(sang) Add args | ||
if __name__ == "__main__": | ||
redis_client = redis.StrictRedis(host="127.0.0.1", port=6379) | ||
p = redis_client.pubsub(ignore_subscribe_messages=True) | ||
p.psubscribe(RAY_INFO_CHANNEL) | ||
p.psubscribe(NODE_INFO_CHANNEL) | ||
metrics_cpu_usage = Gauge( | ||
"ray_metrics_cpu_usage", | ||
"CPU usage of pid residing in a host.", | ||
labelnames=("pid", "host", "ip")) | ||
metrics_mem_usage = Gauge( | ||
"ray_metrics_mem_usage", | ||
"Memory usage of pid residing in a host.", | ||
labelnames=("pid", "host", "ip")) | ||
|
||
# Start up the server to expose the metrics. | ||
# TODO(sang) Read from args | ||
host, port = "127.0.0.1", 8000 | ||
logger.info("Server listening on port {} at address {}".format(host, port)) | ||
start_http_server(port) | ||
|
||
# Read data from Redis. | ||
for x in p.listen(): | ||
data = x["data"] | ||
channel = ray.utils.decode(x["channel"]) | ||
data = json.loads(ray.utils.decode(data)) | ||
|
||
if channel == NODE_INFO_CHANNEL: | ||
clients = data["clients"] | ||
for client in clients: | ||
host = client["hostname"] | ||
ip = client["ip"] | ||
workers = client["workers"] | ||
|
||
for worker in workers: | ||
pid = worker["pid"] | ||
cpu_usage = worker["cpu_percent"] | ||
mem_usage = worker["memory_info"]["rss"] | ||
metrics_cpu_usage.labels( | ||
pid=pid, host=host, ip=ip).set(cpu_usage) | ||
metrics_mem_usage.labels( | ||
pid=pid, host=host, ip=ip).set(mem_usage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
import requests | ||
|
||
from ray.dashboard.hosted_dashboard.exporter import Exporter | ||
|
||
|
||
class DashboardClient: | ||
"""Managing communication to hosted dashboard. | ||
"""Managing the authentication to external services. | ||
Args: | ||
host: Host address of service that are used to authenticate. | ||
port: Port of the host that are used to authenticate. | ||
Attributes: | ||
ingestor_url(str): Address that metrics will be exported. | ||
exporter(Exporter): Exporter thread that keeps exporting | ||
metrics to the external services. | ||
""" | ||
|
||
def __init__(self, dashboard_controller): | ||
# TODO(sang): Remove hard coded ingestor url. | ||
self.ingestor_url = "127.0.0.1:50051" | ||
self.exporter = Exporter(self.ingestor_url, dashboard_controller) | ||
def __init__(self, host, port, dashboard_controller): | ||
self.auth_url = "http://{}:{}/auth".format(host, port) | ||
self.timeout = 5.0 | ||
|
||
self.auth_info = self._connect() | ||
self.exporter = Exporter( | ||
self.auth_info.get("ingestor_url"), | ||
self.auth_info.get("access_token"), dashboard_controller) | ||
|
||
def _authorize(self): | ||
resp = requests.get(self.auth_url, timeout=self.timeout) | ||
status = resp.status_code | ||
json_response = resp.json() | ||
return status, json_response["ingestor_url"], json_response[ | ||
"access_token"] | ||
|
||
def _connect(self): | ||
status, ingestor_url, access_token = self._authorize() | ||
if status != 200: | ||
raise ConnectionError( | ||
"Failed to authorize to hosted dashbaord server.") | ||
|
||
auth_info = { | ||
"ingestor_url": ingestor_url, | ||
"access_token": access_token | ||
} | ||
return auth_info | ||
|
||
def start_exporting_metrics(self): | ||
"""Run an exporter thread to export metrics""" | ||
# TODO(sang): Add a health check. | ||
self.exporter.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.