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

    https://github.com/apache/spark/pull/9571#discussion_r74963037
  
    --- Diff: 
core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala ---
    @@ -226,6 +259,135 @@ class HistoryServer(
     }
     
     /**
    + * An abstract implementation of the metrics [[Source]] trait with some 
common operations.
    + */
    +private[history] abstract class HistoryMetricSource(val prefix: String) 
extends Source {
    +  override val metricRegistry = new MetricRegistry()
    +
    +  /**
    +   * Register a sequence of metrics
    +   * @param metrics sequence of metrics to register
    +   */
    +  def register(metrics: Seq[(String, Metric)]): Unit = {
    +    metrics.foreach { case (name, metric) =>
    +      metricRegistry.register(fullname(name), metric)
    +    }
    +  }
    +
    +  /**
    +   * Create the full name of a metric by prepending the prefix to the name
    +   * @param name short name
    +   * @return the full name to use in registration
    +   */
    +  def fullname(name: String): String = {
    +    MetricRegistry.name(prefix, name)
    +  }
    +
    +  /**
    +   * Dump the counters and gauges.
    +   * @return a string for logging and diagnostics -not for parsing by 
machines.
    +   */
    +  override def toString: String = {
    +    val sb = new StringBuilder(s"Metrics for $sourceName:\n")
    +    sb.append("  Counters\n")
    +    metricRegistry.getCounters.asScala.foreach { entry =>
    +        sb.append("    ").append(entry._1).append(" = 
").append(entry._2.getCount).append('\n')
    +    }
    +    sb.append("  Gauges\n")
    +    metricRegistry.getGauges.asScala.foreach { entry =>
    +      sb.append("    ").append(entry._1).append(" = 
").append(entry._2.getValue).append('\n')
    +    }
    +    sb.toString()
    +  }
    +
    +  /**
    +   * Get a named counter.
    +   * @param counterName name of the counter
    +   * @return the counter, if found
    +   */
    +  def getCounter(counterName: String): Option[Counter] = {
    +    Option(metricRegistry.getCounters(new MetricFilter {
    +      def matches(name: String, metric: Metric): Boolean = name == 
counterName
    +    }).get(counterName))
    +  }
    +
    +  /**
    +   * Get a gauge of an unknown numeric type.
    +   * @param gaugeName name of the gauge
    +   * @return gauge, if found
    +   */
    +  def getGauge(gaugeName: String): Option[Gauge[_]] = {
    +    Option(metricRegistry.getGauges(new MetricFilter {
    +      def matches(name: String, metric: Metric): Boolean = name == 
gaugeName
    +    }).get(gaugeName))
    +  }
    +
    +  /**
    +   * Get a Long gauge.
    +   * @param gaugeName name of the gauge
    +   * @return gauge, if found
    +   * @throws ClassCastException if the gauge is found but of the wrong type
    +   */
    +  def getLongGauge(gaugeName: String): Option[Gauge[Long]] = {
    +    Option(metricRegistry.getGauges(new MetricFilter {
    --- End diff --
    
    done, &  cleaned up all the filtering to have a single `MetricByName` 
filter.


---
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