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

    https://github.com/apache/spark/pull/15307#discussion_r81437765
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamMetrics.scala
 ---
    @@ -0,0 +1,250 @@
    +/*
    + * 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.execution.streaming
    +
    +import scala.collection.mutable
    +
    +import com.codahale.metrics.{Gauge, MetricRegistry}
    +
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.metrics.source.{Source => CodahaleSource}
    +import org.apache.spark.util.Clock
    +
    +class StreamMetrics(sources: Set[Source], triggerClock: Clock, 
codahaleSourceName: String)
    +  extends CodahaleSource with Logging {
    +
    +  import StreamMetrics._
    +
    +  // Trigger infos
    +  private val triggerInfo = new mutable.HashMap[String, String]
    +  private val sourceTriggerInfo = new mutable.HashMap[Source, 
mutable.HashMap[String, String]]
    +
    +  // Rate estimators for sources and sinks
    +  private val inputRates = new mutable.HashMap[Source, RateCalculator]
    +  private val processingRates = new mutable.HashMap[Source, RateCalculator]
    +  private val outputRate = new RateCalculator
    +
    +  // Number of input rows in the current trigger
    +  private val numInputRows = new mutable.HashMap[Source, Long]
    +  private var numOutputRows: Option[Long] = None
    +  private var currentTriggerStartTimestamp: Long = -1
    +  private var previousTriggerStartTimestamp: Long = -1
    +  private var latency: Option[Double] = None
    +
    +  override val sourceName: String = codahaleSourceName
    +  override val metricRegistry: MetricRegistry = new MetricRegistry
    +
    +  // =========== Initialization ===========
    +
    +  registerGauge("inputRate.total", currentInputRate)
    +  registerGauge("processingRate.total", () => currentProcessingRate)
    +  registerGauge("outputRate.total", () => currentOutputRate)
    +  registerGauge("latencyMs", () => currentLatency().getOrElse(-1.0))
    +
    +  sources.foreach { s =>
    +    inputRates.put(s, new RateCalculator)
    +    processingRates.put(s, new RateCalculator)
    +    sourceTriggerInfo.put(s, new mutable.HashMap[String, String])
    +
    +    registerGauge(s"inputRate.${s.toString}", () => 
currentSourceInputRate(s))
    +    registerGauge(s"processingRate.${s.toString}", () => 
currentSourceProcessingRate(s))
    +  }
    +
    +  // =========== Setter methods ===========
    +
    +  def reportTriggerStarted(triggerId: Long): Unit = synchronized {
    +    numInputRows.clear()
    +    numOutputRows = None
    +    triggerInfo.clear()
    +    sourceTriggerInfo.values.foreach(_.clear())
    +
    +    reportTriggerInfo(TRIGGER_ID, triggerId)
    +    sources.foreach(s => reportSourceTriggerInfo(s, TRIGGER_ID, triggerId))
    +    reportTriggerInfo(ACTIVE, true)
    +    currentTriggerStartTimestamp = triggerClock.getTimeMillis()
    +    reportTriggerInfo(START_TIMESTAMP, currentTriggerStartTimestamp)
    +  }
    +
    +  def reportTimestamp(key: String): Unit = synchronized {
    +    triggerInfo.put(key, triggerClock.getTimeMillis().toString)
    +  }
    +
    +  def reportLatency(key: String, latencyMs: Long): Unit = synchronized {
    +    triggerInfo.put(key, latencyMs.toString)
    +  }
    +
    +  def reportLatency(source: Source, key: String, latencyMs: Long): Unit = 
synchronized {
    +    sourceTriggerInfo(source).put(key, latencyMs.toString)
    +  }
    +
    +  def reportTriggerInfo[T](key: String, value: T): Unit = synchronized {
    +    triggerInfo.put(key, value.toString)
    +  }
    +
    +  def reportSourceTriggerInfo[T](source: Source, key: String, value: T): 
Unit = synchronized {
    +    sourceTriggerInfo(source).put(key, value.toString)
    +  }
    +
    +  def reportNumRows(inputRows: Map[Source, Long], outputRows: 
Option[Long]): Unit = synchronized {
    +    numInputRows ++= inputRows
    +    numOutputRows = outputRows
    --- End diff --
    
    no .. its numOutputRows in the current trigger.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to