Github user squito commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4435#discussion_r27977857
  
    --- Diff: 
core/src/main/scala/org/apache/spark/status/api/v1/AllStagesResource.scala ---
    @@ -0,0 +1,285 @@
    +/*
    + * 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.status.api.v1
    +
    +import java.util.Date
    +import javax.ws.rs.{GET, PathParam, Produces, QueryParam}
    +import javax.ws.rs.core.MediaType
    +
    +import org.apache.spark.executor.{InputMetrics => InternalInputMetrics, 
OutputMetrics => InternalOutputMetrics, ShuffleReadMetrics => 
InternalShuffleReadMetrics, ShuffleWriteMetrics => InternalShuffleWriteMetrics, 
TaskMetrics => InternalTaskMetrics}
    +import org.apache.spark.scheduler.{AccumulableInfo => 
InternalAccumulableInfo, StageInfo}
    +import org.apache.spark.ui.SparkUI
    +import org.apache.spark.ui.jobs.UIData.{StageUIData, TaskUIData}
    +import org.apache.spark.util.Distribution
    +
    +@Produces(Array(MediaType.APPLICATION_JSON))
    +private[v1] class AllStagesResource(uiRoot: UIRoot) {
    +
    +  @GET
    +  def stageList(
    +    @PathParam("appId") appId: String,
    +    @QueryParam("status") statuses: java.util.List[StageStatus]
    +  ): Seq[StageData] = {
    +    uiRoot.withSparkUI(appId) { ui =>
    +      val listener = ui.jobProgressListener
    +      val stageAndStatus = AllStagesResource.stagesAndStatus(ui)
    +      val adjStatuses = {
    +        if (statuses.isEmpty()) {
    +          java.util.Arrays.asList(StageStatus.values: _*)
    +        } else {
    +          statuses
    +        }
    +      }
    +      for {
    +        (status, stageList) <- stageAndStatus
    +        stageInfo: StageInfo <- stageList if adjStatuses.contains(status)
    +        stageUiData: StageUIData <- listener.synchronized {
    +          listener.stageIdToData.get((stageInfo.stageId, 
stageInfo.attemptId))
    +        }
    +      } yield {
    +        AllStagesResource.stageUiToStageData(status, stageInfo, 
stageUiData, includeDetails = false)
    +      }
    +    }
    +  }
    +}
    +
    +private[v1] object AllStagesResource {
    +  def stageUiToStageData(
    +    status: StageStatus,
    +    stageInfo: StageInfo,
    +    stageUiData: StageUIData,
    +    includeDetails: Boolean
    +  ): StageData = {
    +
    +    val taskData = if(includeDetails) {
    +      Some(stageUiData.taskData.map { case (k, v) => k -> 
convertTaskData(v) } )
    +    } else {
    +      None
    +    }
    +    val executorSummary = if(includeDetails) {
    +      Some(stageUiData.executorSummary.map { case (k, summary) =>
    +        k -> new ExecutorStageSummary(
    +          taskTime = summary.taskTime,
    +          failedTasks = summary.failedTasks,
    +          succeededTasks = summary.succeededTasks,
    +          inputBytes = summary.inputBytes,
    +          outputBytes = summary.outputBytes,
    +          shuffleRead = summary.shuffleRead,
    +          shuffleWrite = summary.shuffleWrite,
    +          memoryBytesSpilled = summary.memoryBytesSpilled,
    +          diskBytesSpilled = summary.diskBytesSpilled
    +        )
    +      })
    +    } else {
    +      None
    +    }
    +
    +    val accumulableInfo = stageUiData.accumulables.values.map { 
convertAccumulableInfo }.toSeq
    +
    +    new StageData(
    +      status = status,
    +      stageId = stageInfo.stageId,
    +      attemptId = stageInfo.attemptId,
    +      numActiveTasks = stageUiData.numActiveTasks,
    +      numCompleteTasks = stageUiData.numCompleteTasks,
    +      numFailedTasks = stageUiData.numFailedTasks,
    +      executorRunTime = stageUiData.executorRunTime,
    +      inputBytes = stageUiData.inputBytes,
    +      inputRecords = stageUiData.inputRecords,
    +      outputBytes = stageUiData.outputBytes,
    +      outputRecords = stageUiData.outputRecords,
    +      shuffleReadBytes = stageUiData.shuffleReadTotalBytes,
    +      shuffleReadRecords = stageUiData.shuffleReadRecords,
    +      shuffleWriteBytes = stageUiData.shuffleWriteBytes,
    +      shuffleWriteRecords = stageUiData.shuffleWriteRecords,
    +      memoryBytesSpilled = stageUiData.memoryBytesSpilled,
    +      diskBytesSpilled = stageUiData.diskBytesSpilled,
    +      schedulingPool = stageUiData.schedulingPool,
    +      name = stageInfo.name,
    +      details = stageInfo.details,
    +      accumulatorUpdates = accumulableInfo,
    +      tasks = taskData,
    +      executorSummary = executorSummary
    +    )
    +  }
    +
    +  def stagesAndStatus(ui: SparkUI): Seq[(StageStatus, Seq[StageInfo])] = {
    +    val listener = ui.jobProgressListener
    +    listener.synchronized {
    +      Seq(
    +        StageStatus.Active -> listener.activeStages.values.toSeq,
    +        StageStatus.Complete -> listener.completedStages.reverse.toSeq,
    +        StageStatus.Failed -> listener.failedStages.reverse.toSeq,
    +        StageStatus.Pending -> listener.pendingStages.values.toSeq
    +      )
    +    }
    +  }
    +
    +
    +  def convertTaskData(uiData: TaskUIData): TaskData = {
    +    new TaskData(
    +      taskId = uiData.taskInfo.taskId,
    +      index = uiData.taskInfo.index,
    +      attempt = uiData.taskInfo.attempt,
    +      launchTime = new Date(uiData.taskInfo.launchTime),
    +      executorId = uiData.taskInfo.executorId,
    +      host = uiData.taskInfo.host,
    +      taskLocality = uiData.taskInfo.taskLocality.toString(),
    +      speculative = uiData.taskInfo.speculative,
    +      accumulatorUpdates = uiData.taskInfo.accumulables.map { 
convertAccumulableInfo },
    +      errorMessage = uiData.errorMessage,
    +      taskMetrics = uiData.taskMetrics.map { convertUiTaskMetrics }
    +    )
    +  }
    +
    +  def taskMetricDistributions(
    +      allTaskData: Iterable[TaskUIData],
    +      quantiles: Array[Double]): TaskMetricDistributions = {
    +
    +    val rawMetrics = allTaskData.flatMap{_.taskMetrics}.toSeq
    +
    +    def getMetric[T](data: Seq[T], f: T => Double): IndexedSeq[Double] =
    +      Distribution(data.map{d=> f(d)}).get.getQuantiles(quantiles)
    +
    +    abstract class MetricHelper[I,O](f: InternalTaskMetrics => Option[I]) {
    +      val data: Seq[I] = rawMetrics.flatMap{x => f(x)}
    --- End diff --
    
    I don't understand why, but the compiler is unhappy with that:
    
    ```
    [error]  found   : org.apache.spark.executor.TaskMetrics => Option[I]
    [error]  required: org.apache.spark.executor.TaskMetrics => 
scala.collection.GenTraversableOnce[?]
    [error]       val data: Seq[I] = rawMetrics.flatMap(f)
    ```
    
    I'll add a comment explaining


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to