Skip to content

Commit 800c0fc

Browse files
author
Andrew Or
committed
[SPARK-7391] DAG visualization: auto expand if linked from another viz
This is an addition to #5729. If you click into a stage from the DAG viz on the job page, you might expect to expand on the stage. However, once you get to the stage page, you actually have to expand the DAG viz there yourself. This patch makes this happen automatically. It's a small UX improvement. Author: Andrew Or <[email protected]> Closes #5958 from andrewor14/viz-auto-expand and squashes the following commits: 03cd157 [Andrew Or] Automatically expand DAG viz if from job page (cherry picked from commit f121651) Signed-off-by: Andrew Or <[email protected]>
1 parent 226033c commit 800c0fc

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)