Skip to content

Commit 03cd157

Browse files
author
Andrew Or
committed
Automatically expand DAG viz if from job page
1 parent 14502d5 commit 03cd157

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

core/src/main/resources/org/apache/spark/ui/static/spark-dag-viz.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ function renderDagVizForJob(svgContainer) {
178178
var stageId = metadata.attr("stage-id");
179179
var containerId = VizConstants.graphPrefix + stageId;
180180
// Link each graph to the corresponding stage page (TODO: handle stage attempts)
181-
var stageLink =
182-
"/stages/stage/?id=" + stageId.replace(VizConstants.stagePrefix, "") + "&attempt=0";
181+
var stageLink = "/stages/stage/?id=" +
182+
stageId.replace(VizConstants.stagePrefix, "") + "&attempt=0&expandDagViz=true";
183183
var container = svgContainer
184184
.append("a")
185185
.attr("xlink:href", stageLink)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.spark.ui
2020
import java.text.SimpleDateFormat
2121
import java.util.{Locale, Date}
2222

23-
import scala.xml.{Node, Text}
23+
import scala.xml.{Node, Text, Unparsed}
2424

2525
import org.apache.spark.Logging
2626
import org.apache.spark.ui.scope.RDDOperationGraph
@@ -371,4 +371,12 @@ private[spark] object UIUtils extends Logging {
371371
</div>
372372
</div>
373373
}
374+
375+
/** Return a script element that automatically expands the DAG visualization on page load. */
376+
def expandDagVizOnLoad(forJob: Boolean): Seq[Node] = {
377+
<script type="text/javascript">
378+
{Unparsed("$(document).ready(function() { toggleDagViz(" + forJob + ") });")}
379+
</script>
380+
}
381+
374382
}

core/src/main/scala/org/apache/spark/ui/jobs/StagePage.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ private[ui] class StagePage(parent: StagesTab) extends WebUIPage("stage") {
4444
val parameterAttempt = request.getParameter("attempt")
4545
require(parameterAttempt != null && parameterAttempt.nonEmpty, "Missing attempt parameter")
4646

47+
// If this is set, expand the dag visualization by default
48+
val expandDagVizParam = request.getParameter("expandDagViz")
49+
val expandDagViz = expandDagVizParam != null && expandDagVizParam.toBoolean
50+
4751
val stageId = parameterId.toInt
4852
val stageAttemptId = parameterAttempt.toInt
4953
val stageDataOption = progressListener.stageIdToData.get((stageId, stageAttemptId))
@@ -174,6 +178,13 @@ private[ui] class StagePage(parent: StagesTab) extends WebUIPage("stage") {
174178
val dagViz = UIUtils.showDagVizForStage(
175179
stageId, operationGraphListener.getOperationGraphForStage(stageId))
176180

181+
val maybeExpandDagViz: Seq[Node] =
182+
if (expandDagViz) {
183+
UIUtils.expandDagVizOnLoad(forJob = false)
184+
} else {
185+
Seq.empty
186+
}
187+
177188
val accumulableHeaders: Seq[String] = Seq("Accumulable", "Value")
178189
def accumulableRow(acc: AccumulableInfo): Elem =
179190
<tr><td>{acc.name}</td><td>{acc.value}</td></tr>
@@ -440,6 +451,7 @@ private[ui] class StagePage(parent: StagesTab) extends WebUIPage("stage") {
440451
summary ++
441452
showAdditionalMetrics ++
442453
dagViz ++
454+
maybeExpandDagViz ++
443455
<h4>Summary Metrics for {numCompleted} Completed Tasks</h4> ++
444456
<div>{summaryTable.getOrElse("No tasks have reported metrics yet.")}</div> ++
445457
<h4>Aggregated Metrics by Executor</h4> ++ executorTable.toNodeSeq ++

0 commit comments

Comments
 (0)