Nflrijal commented on code in PR #58243:
URL: https://github.com/apache/spark/pull/58243#discussion_r3929752943
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2405,6 +2416,12 @@ class SparkContext(config: SparkConf) extends Logging {
ResourceProfile.clearDefaultProfile()
// Unset YARN mode system env variable, to allow switching between cluster
types.
SparkContext.clearActiveContext()
+ if (_conf.get(UI_REVERSE_PROXY)) {
+ _previousProxyBase match {
+ case Some(oldBase) => System.setProperty("spark.ui.proxyBase", oldBase)
+ case None => System.clearProperty("spark.ui.proxyBase")
Review Comment:
Introduced _proxyBaseSetByContext flag so stop() only restores or clears
spark.ui.proxyBase if this context actually initialized and modified it,
preserving pre-existing JVM properties when context creation fails earlier.
##########
core/src/test/scala/org/apache/spark/deploy/master/ui/MasterWebUISuite.scala:
##########
@@ -128,6 +128,78 @@ class MasterWebUISuite extends SparkFunSuite {
denyWebUI.stop()
}
}
+
+ test("SPARK-58893: kill application redirect location with reverse proxy") {
+ val reverseProxyConf = new SparkConf()
+ .set(DECOMMISSION_ENABLED, true)
+ .set(UI_REVERSE_PROXY, true)
+ .set(UI_REVERSE_PROXY_URL, "http://proxyhost:8080/myproxy")
+ val mockMaster = mock(classOf[Master])
+ when(mockMaster.securityMgr).thenReturn(securityMgr)
+ when(mockMaster.conf).thenReturn(reverseProxyConf)
+ when(mockMaster.rpcEnv).thenReturn(rpcEnv)
+ when(mockMaster.self).thenReturn(masterEndpointRef)
+
+ val activeApp = new ApplicationInfo(
+ new Date().getTime, "app-proxy-0", createAppDesc(), new Date(), null,
Int.MaxValue)
+ val appMap = HashMap[String, ApplicationInfo]((activeApp.id, activeApp))
+ when(mockMaster.idToApp).thenReturn(appMap)
+
+ val webUI = new MasterWebUI(mockMaster, 0)
+ try {
+ webUI.bind()
+ val url =
s"http://${Utils.localHostNameForURI()}:${webUI.boundPort}/app/kill/"
+ val body = convPostDataToString(Map(("id", activeApp.id), ("terminate",
"true")))
+ val conn = new
URI(url).toURL.openConnection().asInstanceOf[HttpURLConnection]
+ conn.setInstanceFollowRedirects(false)
+ conn.setRequestMethod("POST")
+ conn.setDoOutput(true)
+ conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded")
+ val out = new DataOutputStream(conn.getOutputStream)
+ out.write(body.getBytes(StandardCharsets.UTF_8))
+ out.close()
+ assert(conn.getResponseCode === 302)
+ assert(conn.getHeaderField("Location") ===
"http://proxyhost:8080/myproxy/")
+ } finally {
+ webUI.stop()
+ }
+ }
+
+ test("SPARK-58893: honor reverseProxy=false when choosing kill redirect") {
+ val noProxyConf = new SparkConf()
+ .set(DECOMMISSION_ENABLED, true)
+ .set(UI_REVERSE_PROXY, false)
+ .set(UI_REVERSE_PROXY_URL, "http://proxyhost:8080/myproxy")
+ val mockMaster = mock(classOf[Master])
+ when(mockMaster.securityMgr).thenReturn(securityMgr)
+ when(mockMaster.conf).thenReturn(noProxyConf)
+ when(mockMaster.rpcEnv).thenReturn(rpcEnv)
+ when(mockMaster.self).thenReturn(masterEndpointRef)
+
+ val activeApp = new ApplicationInfo(
+ new Date().getTime, "app-proxy-1", createAppDesc(), new Date(), null,
Int.MaxValue)
+ val appMap = HashMap[String, ApplicationInfo]((activeApp.id, activeApp))
+ when(mockMaster.idToApp).thenReturn(appMap)
+
+ val webUI = new MasterWebUI(mockMaster, 0)
+ try {
+ webUI.bind()
+ val url =
s"http://${Utils.localHostNameForURI()}:${webUI.boundPort}/app/kill/"
+ val body = convPostDataToString(Map(("id", activeApp.id), ("terminate",
"true")))
+ val conn = new
URI(url).toURL.openConnection().asInstanceOf[HttpURLConnection]
+ conn.setInstanceFollowRedirects(false)
+ conn.setRequestMethod("POST")
+ conn.setDoOutput(true)
+ conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded")
+ val out = new DataOutputStream(conn.getOutputStream)
+ out.write(body.getBytes(StandardCharsets.UTF_8))
+ out.close()
+ assert(conn.getResponseCode === 302)
+ assert(conn.getHeaderField("Location") === "/")
Review Comment:
Updated test assertion to expect the absolute local root
(http://${Utils.localHostNameForURI()}:${webUI.boundPort}/) returned by Jetty's
redirect handler.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]