HeartSaVioR commented on a change in pull request #26201: [SPARK-29543][SS][UI] 
Init structured streaming ui
URL: https://github.com/apache/spark/pull/26201#discussion_r365658608
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/streaming/ui/StreamingQueryPage.scala
 ##########
 @@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.streaming.ui
+
+import java.text.SimpleDateFormat
+import javax.servlet.http.HttpServletRequest
+
+import scala.xml.Node
+
+import org.apache.commons.lang3.StringEscapeUtils
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.catalyst.util.DateTimeUtils.getTimeZone
+import org.apache.spark.sql.streaming.ui.UIUtils._
+import org.apache.spark.ui.{UIUtils => SparkUIUtils, WebUIPage}
+
+class StreamingQueryPage(parent: StreamingQueryTab, statusListener: 
StreamingQueryStatusListener)
+    extends WebUIPage("") with Logging {
+  val df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+  df.setTimeZone(getTimeZone("UTC"))
+
+  override def render(request: HttpServletRequest): Seq[Node] = {
+    val content = generateStreamingQueryTable(request)
+    SparkUIUtils.headerSparkPage(request, "Streaming Query", content, parent)
+  }
+
+  def generateDataRow(request: HttpServletRequest, queryActive: Boolean)
+    (query: StreamingQueryUIData): Seq[Node] = {
+
+    def details(detail: Any): Seq[Node] = {
+      if (queryActive) {
+        return Seq.empty[Node]
+      }
+      val s = detail.asInstanceOf[String]
+      val isMultiline = s.indexOf('\n') >= 0
+      val summary = StringEscapeUtils.escapeHtml4(
+        if (isMultiline) s.substring(0, s.indexOf('\n')) else s
+      )
+      val details = if (isMultiline) {
+        // scalastyle:off
+        <span 
onclick="this.parentNode.querySelector('.stacktrace-details').classList.toggle('collapsed')"
+              class="expand-details">
+          +details
+        </span> ++
+          <div class="stacktrace-details collapsed">
+            <pre>{s}</pre>
+          </div>
+        // scalastyle:on
+      } else {
+        ""
+      }
+      <td>{summary}{details}</td>
+    }
+
+    val statisticsLink = "%s/%s/statistics?id=%s"
+      .format(SparkUIUtils.prependBaseUri(request, parent.basePath), 
parent.prefix, query.runId)
+
+    val name = UIUtils.getQueryName(query)
+    val status = UIUtils.getQueryStatus(query)
+    val duration = if (queryActive) {
+      SparkUIUtils.formatDurationVerbose(System.currentTimeMillis() - 
query.submitTime)
+    } else {
+      withNoProgress(query, {
+        val endTimeMs = query.lastProgress.timestamp
+        SparkUIUtils.formatDurationVerbose(df.parse(endTimeMs).getTime - 
query.submitTime)
+      }, "-")
+    }
+
+    <tr>
+      <td> {name} </td>
+      <td> {status} </td>
+      <td> {query.id} </td>
+      <td> <a href={statisticsLink}> {query.runId} </a> </td>
+      <td> {SparkUIUtils.formatDate(query.submitTime)} </td>
+      <td> {duration} </td>
+      <td> {withNoProgress(query, {
+        (query.recentProgress.map(p => 
withNumberInvalid(p.inputRowsPerSecond)).sum /
 
 Review comment:
   Given we have a function for constructing exception message, why not add 
another one for constructing average message for this and below?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to