Github user steveloughran commented on a diff in the pull request:
https://github.com/apache/spark/pull/17747#discussion_r122256050
--- Diff:
core/src/main/scala/org/apache/spark/deploy/history/HistoryMetricSource.scala
---
@@ -0,0 +1,166 @@
+/*
+ * 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.deploy.history
+
+import scala.collection.JavaConverters._
+
+import com.codahale.metrics.{Counter, Gauge, Metric, MetricFilter,
MetricRegistry, Timer}
+
+import org.apache.spark.metrics.source.Source
+import org.apache.spark.util.Clock
+
+/**
+ * An abstract implementation of the metrics [[Source]] trait with some
common operations for
+ * retrieving entries; the `toString()` operation dumps all counters and
gauges.
+ */
+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")
+ def robustAppend(s : => Long) = {
+ try {
+ sb.append(s)
+ } catch {
+ case e: Exception =>
+ sb.append(s"(exception: $e)")
+ }
+ }
+
+ sb.append(" Counters\n")
+
+ metricRegistry.getCounters.asScala.foreach { case (name, counter) =>
+ sb.append(" ").append(name).append(" = ")
+ .append(counter.getCount).append('\n')
+ }
+ sb.append(" Gauges\n")
+ metricRegistry.getGauges.asScala.foreach { case (name, gauge) =>
+ sb.append(" ").append(name).append(" = ")
+ try {
+ sb.append(gauge.getValue)
--- End diff --
yes, I'm trying to work why I *didn't* use that method given it was there.
Widened it to a generic type and used. It's probably overkill, but as anything
can be a Gauge, its possible that they will NPE or similar, and that just ruins
logging & debugging.
---
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]