kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: KAFKA-5746; Return 0.0 from Metric.value() instead of throwing exception
Date Sun, 01 Oct 2017 00:29:49 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 0ef960304 -> 4f4f99532


KAFKA-5746; Return 0.0 from Metric.value() instead of throwing exception

This is less likely to break custom metric reporters and since the method
is deprecated, people will be warned about this potential issue.

Author: Ismael Juma <ismael@juma.me.uk>

Reviewers: Ewen Cheslack-Postava <ewen@confluent.io>, Xavier Léauté <xavier@confluent.io>

Closes #3996 from ijuma/avoid-exception-in-measurable-value


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/4f4f9953
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/4f4f9953
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/4f4f9953

Branch: refs/heads/trunk
Commit: 4f4f99532557439c6e85b18a23df59c2ae45a71b
Parents: 0ef9603
Author: Ismael Juma <ismael@juma.me.uk>
Authored: Sun Oct 1 01:29:33 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Sun Oct 1 01:29:33 2017 +0100

----------------------------------------------------------------------
 clients/src/main/java/org/apache/kafka/common/Metric.java | 10 +++++-----
 .../java/org/apache/kafka/common/metrics/KafkaMetric.java |  2 +-
 docs/upgrade.html                                         |  6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/4f4f9953/clients/src/main/java/org/apache/kafka/common/Metric.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/Metric.java b/clients/src/main/java/org/apache/kafka/common/Metric.java
index 1f8d618..61a5d67 100644
--- a/clients/src/main/java/org/apache/kafka/common/Metric.java
+++ b/clients/src/main/java/org/apache/kafka/common/Metric.java
@@ -24,19 +24,19 @@ public interface Metric {
     /**
      * A name for this metric
      */
-    public MetricName metricName();
+    MetricName metricName();
 
     /**
-     * The value of the metric as double if the metric is measurable
-     * @throws IllegalStateException if this metric does not have a measurable double value
+     * The value of the metric as double if the metric is measurable and `0.0` otherwise.
+     *
      * @deprecated As of 1.0.0, use {@link #metricValue()} instead. This will be removed
in a future major release.
      */
     @Deprecated
-    public double value();
+    double value();
 
     /**
      * The value of the metric, which may be measurable or a non-measurable gauge
      */
-    public Object metricValue();
+    Object metricValue();
 
 }

http://git-wip-us.apache.org/repos/asf/kafka/blob/4f4f9953/clients/src/main/java/org/apache/kafka/common/metrics/KafkaMetric.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/metrics/KafkaMetric.java b/clients/src/main/java/org/apache/kafka/common/metrics/KafkaMetric.java
index 0cdd844..37c2b1b 100644
--- a/clients/src/main/java/org/apache/kafka/common/metrics/KafkaMetric.java
+++ b/clients/src/main/java/org/apache/kafka/common/metrics/KafkaMetric.java
@@ -83,7 +83,7 @@ public final class KafkaMetric implements Metric {
         if (this.metricValueProvider instanceof Measurable)
             return ((Measurable) metricValueProvider).measure(config, timeMs);
         else
-            throw new IllegalStateException("Not a measurable metric");
+            return 0;
     }
 
     public void config(MetricConfig config) {

http://git-wip-us.apache.org/repos/asf/kafka/blob/4f4f9953/docs/upgrade.html
----------------------------------------------------------------------
diff --git a/docs/upgrade.html b/docs/upgrade.html
index 1806cb0..8c3fbab 100644
--- a/docs/upgrade.html
+++ b/docs/upgrade.html
@@ -71,9 +71,9 @@
     <li>The <code>app-info</code> mbean registered with JMX to provide
version and commit id will be deprecated and replaced with
         metrics providing these attributes.</li>
     <li>Kafka metrics may now contain non-numeric values. <code>org.apache.kafka.common.Metric#value()</code>
has been deprecated and
-        may throw an <code>IllegalStateException</code> when iterating over metrics
of <code>KafkaProducer/KafkaConsumer/KafkaAdminClient</code>.
-        <code>org.apache.kafka.common.Metric#metricValue()</code> can be used
to safely iterate over any metric value.</code>
-
+        will return <code>0.0</code> in such cases to minimise the probability
of breaking users who read the value of every client
+        metric (via a <code>MetricsReporter</code> implementation or by calling
the <code>metrics()</code> method).
+        <code>org.apache.kafka.common.Metric#metricValue()</code> can be used
to retrieve numeric and non-numeric metric values.</li>
 </ul>
 
 <h5><a id="upgrade_100_new_protocols" href="#upgrade_100_new_protocols">New Protocol
Versions</a></h5>


Mime
View raw message