Skip to content

Commit b40db30

Browse files
ConeyLiufishbone
authored andcommitted
[dashboard] Fixes dashboard issues when environments have set http_proxy (ray-project#12598)
* fixes ray start with http_proxy * format * fixes * fixes * increase timeout * address comments
1 parent 773d13c commit b40db30

File tree

8 files changed

+97
-32
lines changed

8 files changed

+97
-32
lines changed

dashboard/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ def __init__(self,
7575
logger.info("Dashboard agent grpc address: %s:%s", self.ip,
7676
self.grpc_port)
7777
self.aioredis_client = None
78+
options = (("grpc.enable_http_proxy", 0), )
7879
self.aiogrpc_raylet_channel = aiogrpc.insecure_channel(
79-
f"{self.ip}:{self.node_manager_port}")
80+
f"{self.ip}:{self.node_manager_port}", options=options)
8081
self.http_session = None
8182

8283
def _load_modules(self):

dashboard/head.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ async def run(self):
159159
if not gcs_address:
160160
raise Exception("GCS address not found.")
161161
logger.info("Connect to GCS at %s", gcs_address)
162-
channel = aiogrpc.insecure_channel(gcs_address)
162+
options = (("grpc.enable_http_proxy", 0), )
163+
channel = aiogrpc.insecure_channel(
164+
gcs_address, options=options)
163165
except Exception as ex:
164166
logger.error("Connect to GCS failed: %s, retry...", ex)
165167
await asyncio.sleep(

dashboard/modules/logical_view/logical_view_head.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ async def kill_actor(self, req) -> aiohttp.web.Response:
4646
except KeyError:
4747
return rest_response(success=False, message="Bad Request")
4848
try:
49-
channel = aiogrpc.insecure_channel(f"{ip_address}:{port}")
49+
options = (("grpc.enable_http_proxy", 0), )
50+
channel = aiogrpc.insecure_channel(
51+
f"{ip_address}:{port}", options=options)
5052
stub = core_worker_pb2_grpc.CoreWorkerServiceStub(channel)
5153

5254
await stub.KillActor(

dashboard/modules/reporter/reporter_head.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ async def _update_stubs(self, change):
3838
if change.new:
3939
node_id, ports = change.new
4040
ip = DataSource.node_id_to_ip[node_id]
41-
channel = aiogrpc.insecure_channel(f"{ip}:{ports[1]}")
41+
options = (("grpc.enable_http_proxy", 0), )
42+
channel = aiogrpc.insecure_channel(
43+
f"{ip}:{ports[1]}", options=options)
4244
stub = reporter_pb2_grpc.ReporterServiceStub(channel)
4345
self._stubs[ip] = stub
4446

dashboard/modules/stats_collector/stats_collector_head.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ async def _update_stubs(self, change):
7171
node_id, node_info = change.new
7272
address = "{}:{}".format(node_info["nodeManagerAddress"],
7373
int(node_info["nodeManagerPort"]))
74-
channel = aiogrpc.insecure_channel(address)
74+
options = (("grpc.enable_http_proxy", 0), )
75+
channel = aiogrpc.insecure_channel(address, options=options)
7576
stub = node_manager_pb2_grpc.NodeManagerServiceStub(channel)
7677
self._stubs[node_id] = stub
7778

dashboard/tests/conftest.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1-
import os
2-
import pytest
3-
from ray.tests.conftest import * # noqa
4-
5-
6-
@pytest.fixture
7-
def enable_test_module():
8-
os.environ["RAY_DASHBOARD_MODULE_TEST"] = "true"
9-
yield
10-
os.environ.pop("RAY_DASHBOARD_MODULE_TEST", None)
11-
12-
13-
@pytest.fixture
14-
def disable_aiohttp_cache():
15-
os.environ["RAY_DASHBOARD_NO_CACHE"] = "true"
16-
yield
17-
os.environ.pop("RAY_DASHBOARD_NO_CACHE", None)
1+
import os
2+
import pytest
3+
from ray.tests.conftest import * # noqa
4+
5+
6+
@pytest.fixture
7+
def enable_test_module():
8+
os.environ["RAY_DASHBOARD_MODULE_TEST"] = "true"
9+
yield
10+
os.environ.pop("RAY_DASHBOARD_MODULE_TEST", None)
11+
12+
13+
@pytest.fixture
14+
def disable_aiohttp_cache():
15+
os.environ["RAY_DASHBOARD_NO_CACHE"] = "true"
16+
yield
17+
os.environ.pop("RAY_DASHBOARD_NO_CACHE", None)
18+
19+
20+
@pytest.fixture
21+
def set_http_proxy():
22+
http_proxy = os.environ.get("http_proxy", None)
23+
https_proxy = os.environ.get("https_proxy", None)
24+
25+
# set http proxy
26+
os.environ["http_proxy"] = "www.example.com:990"
27+
os.environ["https_proxy"] = "www.example.com:990"
28+
29+
yield
30+
31+
# reset http proxy
32+
if http_proxy:
33+
os.environ["http_proxy"] = http_proxy
34+
else:
35+
del os.environ["http_proxy"]
36+
37+
if https_proxy:
38+
os.environ["https_proxy"] = https_proxy
39+
else:
40+
del os.environ["https_proxy"]

dashboard/tests/test_dashboard.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,5 +571,38 @@ def test_immutable_types():
571571
print(d3[1])
572572

573573

574+
def test_http_proxy(enable_test_module, set_http_proxy, shutdown_only):
575+
address_info = ray.init(num_cpus=1, include_dashboard=True)
576+
assert (wait_until_server_available(address_info["webui_url"]) is True)
577+
578+
webui_url = address_info["webui_url"]
579+
webui_url = format_web_url(webui_url)
580+
581+
timeout_seconds = 10
582+
start_time = time.time()
583+
while True:
584+
time.sleep(1)
585+
try:
586+
response = requests.get(
587+
webui_url + "/test/dump",
588+
proxies={
589+
"http": None,
590+
"https": None
591+
})
592+
response.raise_for_status()
593+
try:
594+
response.json()
595+
assert response.ok
596+
except Exception as ex:
597+
logger.info("failed response: %s", response.text)
598+
raise ex
599+
break
600+
except (AssertionError, requests.exceptions.ConnectionError) as e:
601+
logger.info("Retry because of %s", e)
602+
finally:
603+
if time.time() > start_time + timeout_seconds:
604+
raise Exception("Timed out while testing.")
605+
606+
574607
if __name__ == "__main__":
575608
sys.exit(pytest.main(["-v", __file__]))

dashboard/utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
import abc
2-
import os
3-
import socket
4-
import time
52
import asyncio
63
import collections
7-
import json
84
import datetime
95
import functools
106
import importlib
117
import inspect
8+
import json
129
import logging
10+
import os
1311
import pkgutil
12+
import socket
1413
import traceback
15-
from base64 import b64decode
1614
from abc import ABCMeta, abstractmethod
17-
from collections.abc import MutableMapping, Mapping, Sequence
15+
from base64 import b64decode
1816
from collections import namedtuple
17+
from collections.abc import MutableMapping, Mapping, Sequence
1918
from typing import Any
2019

21-
import aioredis
20+
import aiohttp.signals
2221
import aiohttp.web
23-
import ray.new_dashboard.consts as dashboard_consts
22+
import aioredis
23+
import time
2424
from aiohttp import hdrs
2525
from aiohttp.frozenlist import FrozenList
2626
from aiohttp.typedefs import PathLike
2727
from aiohttp.web import RouteDef
28-
import aiohttp.signals
2928
from google.protobuf.json_format import MessageToDict
30-
from ray.utils import binary_to_hex
29+
30+
import ray.new_dashboard.consts as dashboard_consts
3131
from ray.ray_constants import env_bool
32+
from ray.utils import binary_to_hex
3233

3334
try:
3435
create_task = asyncio.create_task

0 commit comments

Comments
 (0)