Skip to content

Commit f779fe0

Browse files
committed
Fix MetricsServlet not work issue
1 parent 0fe54cf commit f779fe0

File tree

6 files changed

+8
-5
lines changed

6 files changed

+8
-5
lines changed

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ class SparkContext(config: SparkConf) extends Logging {
344344
// The metrics system for Driver need to be set spark.app.id to app ID.
345345
// So it should start after we get app ID from the task scheduler and set spark.app.id.
346346
metricsSystem.start()
347+
// Attach the driver metrics servlet handler to the web ui after the metrics system is started.
348+
metricsSystem.getServletHandlers.foreach(handler => ui.foreach(_.attachHandler(handler)))
347349

348350
// Optionally log Spark events
349351
private[spark] val eventLogger: Option[EventLoggingListener] = {

core/src/main/scala/org/apache/spark/deploy/master/Master.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ private[spark] class Master(
129129
masterMetricsSystem.registerSource(masterSource)
130130
masterMetricsSystem.start()
131131
applicationMetricsSystem.start()
132+
// Attach the master and app metrics servlet handler to the web ui after the metrics systems are
133+
// started.
134+
masterMetricsSystem.getServletHandlers.foreach(webUi.attachHandler)
135+
applicationMetricsSystem.getServletHandlers.foreach(webUi.attachHandler)
132136

133137
val (persistenceEngine_, leaderElectionAgent_) = RECOVERY_MODE match {
134138
case "ZOOKEEPER" =>

core/src/main/scala/org/apache/spark/deploy/master/ui/MasterWebUI.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class MasterWebUI(val master: Master, requestedPort: Int)
4141
attachPage(new HistoryNotFoundPage(this))
4242
attachPage(new MasterPage(this))
4343
attachHandler(createStaticHandler(MasterWebUI.STATIC_RESOURCE_DIR, "/static"))
44-
master.masterMetricsSystem.getServletHandlers.foreach(attachHandler)
45-
master.applicationMetricsSystem.getServletHandlers.foreach(attachHandler)
4644
}
4745

4846
/** Attach a reconstructed UI to this Master UI. Only valid after bind(). */

core/src/main/scala/org/apache/spark/deploy/worker/Worker.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ private[spark] class Worker(
164164

165165
metricsSystem.registerSource(workerSource)
166166
metricsSystem.start()
167+
// Attach the worker metrics servlet handler to the web ui after the metrics system is started.
168+
metricsSystem.getServletHandlers.foreach(webUi.attachHandler)
167169
}
168170

169171
def changeMaster(url: String, uiUrl: String) {

core/src/main/scala/org/apache/spark/deploy/worker/ui/WorkerWebUI.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class WorkerWebUI(
5050
attachHandler(createStaticHandler(WorkerWebUI.STATIC_RESOURCE_BASE, "/static"))
5151
attachHandler(createServletHandler("/log",
5252
(request: HttpServletRequest) => logPage.renderLog(request), worker.securityMgr))
53-
worker.metricsSystem.getServletHandlers.foreach(attachHandler)
5453
}
5554
}
5655

core/src/main/scala/org/apache/spark/ui/SparkUI.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ private[spark] class SparkUI private (
5757
attachHandler(createRedirectHandler("/", "/jobs", basePath = basePath))
5858
attachHandler(
5959
createRedirectHandler("/stages/stage/kill", "/stages", stagesTab.handleKillRequest))
60-
// If the UI is live, then serve
61-
sc.foreach { _.env.metricsSystem.getServletHandlers.foreach(attachHandler) }
6260
}
6361
initialize()
6462

0 commit comments

Comments
 (0)