lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [22/50] [abbrv] lucene-solr:jira/solr-9854: SOLR-9805 Fix assertion error on Windows where SystemLoadAverage is reported as -1. Don't expose non-existent attributes.
Date Fri, 30 Dec 2016 15:56:58 GMT
SOLR-9805 Fix assertion error on Windows where SystemLoadAverage is reported as -1.
Don't expose non-existent attributes.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/56476fb8
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/56476fb8
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/56476fb8

Branch: refs/heads/jira/solr-9854
Commit: 56476fb8c70486c21324879f1bd1efc79df92ffb
Parents: 1d3fb3e
Author: Andrzej Bialecki <ab@apache.org>
Authored: Tue Dec 27 11:37:50 2016 +0100
Committer: Andrzej Bialecki <ab@apache.org>
Committed: Tue Dec 27 11:39:13 2016 +0100

----------------------------------------------------------------------
 .../solr/metrics/OperatingSystemMetricSet.java      | 16 ++++++++++++++--
 .../org/apache/solr/metrics/JvmMetricsTest.java     |  3 ++-
 2 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/56476fb8/solr/core/src/java/org/apache/solr/metrics/OperatingSystemMetricSet.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/OperatingSystemMetricSet.java b/solr/core/src/java/org/apache/solr/metrics/OperatingSystemMetricSet.java
index b26386a..34ef5d1 100644
--- a/solr/core/src/java/org/apache/solr/metrics/OperatingSystemMetricSet.java
+++ b/solr/core/src/java/org/apache/solr/metrics/OperatingSystemMetricSet.java
@@ -17,11 +17,15 @@
 package org.apache.solr.metrics;
 
 import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import java.lang.invoke.MethodHandles;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import com.codahale.metrics.JmxAttributeGauge;
 import com.codahale.metrics.Metric;
@@ -67,9 +71,17 @@ public class OperatingSystemMetricSet implements MetricSet {
     try {
       final ObjectName on = new ObjectName("java.lang:type=OperatingSystem");
       // verify that it exists
-      mBeanServer.getMBeanInfo(on);
+      MBeanInfo info = mBeanServer.getMBeanInfo(on);
+      // collect valid attributes
+      Set<String> attributes = new HashSet<>();
+      for (MBeanAttributeInfo ai : info.getAttributes()) {
+        attributes.add(ai.getName());
+      }
       for (String metric : METRICS) {
-        metrics.put(metric, new JmxAttributeGauge(mBeanServer, on, metric));
+        // verify that an attribute exists before attempting to add it
+        if (attributes.contains(metric)) {
+          metrics.put(metric, new JmxAttributeGauge(mBeanServer, on, metric));
+        }
       }
     } catch (JMException ignored) {
       log.debug("Unable to load OperatingSystem MBean", ignored);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/56476fb8/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java b/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java
index 6d597cb..72adc68 100644
--- a/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java
+++ b/solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java
@@ -48,7 +48,8 @@ public class JvmMetricsTest extends SolrJettyTestBase {
         continue;
       }
       double value = ((Number)gauge.getValue()).doubleValue();
-      assertTrue(value >= 0);
+      // SystemLoadAverage on Windows may be -1.0
+      assertTrue("unexpected value of " + metric + ": " + value, value >= 0 || value ==
-1.0);
     }
   }
 


Mime
View raw message