Skip to content

Commit ceaa392

Browse files
sarutakdongjoon-hyun
authored andcommitted
[SPARK-32200][WEBUI] Redirect to the history page when accessed to /history on the HistoryServer without appliation id
### What changes were proposed in this pull request? This PR proposes to change the HistoryServer to redirect to the history page when we access to /history without application id. ### Why are the changes needed? In the current master, status code 400 will be returned when we access to /history. So I wonder it's better to redirect to the history page for the better UX. ### Does this PR introduce _any_ user-facing change? Yes. In the current master, if we access to /history without application id, we will see like the following page. ![history-400](https://user-images.githubusercontent.com/4736016/86649650-e9105380-c01c-11ea-93bb-78fd8d2e6f7b.png) After this change applied, we will be redirected to the history page. ### How was this patch tested? New test added. Closes #29016 from sarutak/history-redirect. Authored-by: Kousuke Saruta <sarutak@oss.nttdata.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent b84ed41 commit ceaa392

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ class HistoryServer(
7676
// attempt ID (separated by a slash).
7777
val parts = Option(req.getPathInfo()).getOrElse("").split("/")
7878
if (parts.length < 2) {
79-
res.sendError(HttpServletResponse.SC_BAD_REQUEST,
80-
s"Unexpected path info in request (URI = ${req.getRequestURI()}")
81-
return
79+
res.sendRedirect("/")
8280
}
8381

8482
val appId = parts(1)

core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,19 @@ class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with Matchers
643643
val actualContentType = conn.getContentType
644644
assert(actualContentType === expectedContentType)
645645
}
646+
647+
test("Redirect to the root page when accessed to /history/") {
648+
val port = server.boundPort
649+
val url = new URL(s"http://localhost:$port/history/")
650+
val conn = url.openConnection().asInstanceOf[HttpURLConnection]
651+
conn.setRequestMethod("GET")
652+
conn.setUseCaches(false)
653+
conn.setDefaultUseCaches(false)
654+
conn.setInstanceFollowRedirects(false)
655+
conn.connect()
656+
assert(conn.getResponseCode === 302)
657+
assert(conn.getHeaderField("Location") === s"http://localhost:$port/")
658+
}
646659
}
647660

648661
object HistoryServerSuite {

0 commit comments

Comments
 (0)