Skip to content

Commit ad6f7d9

Browse files
authored
Add redirect from prefix root to status (#9015)
1 parent fe5e431 commit ad6f7d9

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

distributed/dashboard/scheduler.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,23 @@ def connect(application, http_server, scheduler, prefix=""):
172172
application.add_application(bokeh_app)
173173
bokeh_app.initialize(IOLoop.current())
174174

175-
bokeh_app.add_handlers(
176-
r".*",
177-
[
175+
routes = [
176+
(
177+
r"/",
178+
web.RedirectHandler,
179+
{"url": urljoin((prefix or "").strip("/") + "/", "status")},
180+
)
181+
]
182+
183+
if prefix:
184+
prefix_clean = prefix.strip("/")
185+
routes.append(
178186
(
179-
r"/",
187+
rf"/{prefix_clean}/?",
180188
web.RedirectHandler,
181-
{"url": urljoin((prefix or "").strip("/") + "/", r"status")},
189+
{"url": urljoin(prefix_clean + "/", "status")},
182190
)
183-
],
184-
)
191+
)
185192

193+
bokeh_app.add_handlers(r".*", routes)
186194
bokeh_app.start()

distributed/dashboard/tests/test_scheduler_bokeh.py

+17
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,23 @@ async def test_prefix_bokeh(s, a, b):
13291329
assert bokeh_app.prefix == f"/{prefix}"
13301330

13311331

1332+
@gen_cluster(
1333+
client=True, scheduler_kwargs={"http_prefix": "foo-bar", "dashboard": True}
1334+
)
1335+
async def test_prefix_redirect_bokeh(c, s, a, b):
1336+
prefix = "foo-bar"
1337+
http_client = AsyncHTTPClient()
1338+
response = await http_client.fetch(
1339+
f"http://localhost:{s.http_server.port}/{prefix}"
1340+
)
1341+
assert response.code == 200
1342+
assert "/status" in response.effective_url
1343+
1344+
bokeh_app = s.http_application.applications[0]
1345+
assert isinstance(bokeh_app, BokehTornado)
1346+
assert bokeh_app.prefix == f"/{prefix}"
1347+
1348+
13321349
@gen_cluster(scheduler_kwargs={"dashboard": True})
13331350
async def test_bokeh_relative(s, a, b):
13341351
http_client = AsyncHTTPClient()

0 commit comments

Comments
 (0)