lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject lucene-solr:feature/metrics: SOLR-4735 Add gauges that report the current number of cores.
Date Mon, 19 Dec 2016 12:34:56 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/feature/metrics 5a17c1b5c -> 92ef10dbd


SOLR-4735 Add gauges that report the current number of cores.


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

Branch: refs/heads/feature/metrics
Commit: 92ef10dbdea6d8764d2a1ecba3d53abee542542d
Parents: 5a17c1b
Author: Andrzej Bialecki <ab@apache.org>
Authored: Mon Dec 19 13:34:15 2016 +0100
Committer: Andrzej Bialecki <ab@apache.org>
Committed: Mon Dec 19 13:34:15 2016 +0100

----------------------------------------------------------------------
 .../src/java/org/apache/solr/core/CoreContainer.java   | 13 +++++++++++++
 .../org/apache/solr/metrics/SolrMetricManager.java     |  8 ++++----
 .../apache/solr/handler/admin/MetricsHandlerTest.java  |  2 ++
 3 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92ef10db/solr/core/src/java/org/apache/solr/core/CoreContainer.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index c423985..0703212 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -33,6 +33,7 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
+import com.codahale.metrics.Gauge;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import org.apache.http.auth.AuthSchemeProvider;
@@ -491,6 +492,18 @@ public class CoreContainer {
 
     containerProperties.putAll(cfg.getSolrProperties());
 
+    // initialize gauges for reporting the number of cores
+    Gauge<Integer> loadedCores = () -> solrCores.getCores().size();
+    Gauge<Integer> lazyCores = () -> solrCores.getCoreNames().size() - solrCores.getCores().size();
+    Gauge<Integer> unloadedCores = () -> solrCores.getAllCoreNames().size() - solrCores.getCoreNames().size();
+
+    SolrMetricManager.register(SolrMetricManager.getRegistryName(SolrInfoMBean.Group.node),
+        loadedCores, true, "loaded", "cores");
+    SolrMetricManager.register(SolrMetricManager.getRegistryName(SolrInfoMBean.Group.node),
+        lazyCores, true, "lazy", "cores");
+    SolrMetricManager.register(SolrMetricManager.getRegistryName(SolrInfoMBean.Group.node),
+        unloadedCores, true, "unloaded", "cores");
+
     // setup executor to load cores in parallel
     ExecutorService coreLoadExecutor = ExecutorUtil.newMDCAwareFixedThreadPool(
         cfg.getCoreLoadThreadCount(isZooKeeperAware()),

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92ef10db/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
index 2063689..b700782 100644
--- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
@@ -280,18 +280,18 @@ public class SolrMetricManager {
    * Register an instance of {@link Metric}.
    * @param registry registry name
    * @param metric metric instance
-   * @param skipExisting if true then already an existing metric with the same name will
be kept.
+   * @param force if true then an already existing metric with the same name will be replaced.
    *                     When false and a metric with the same name already exists an exception
    *                     will be thrown.
    * @param metricName metric name, either final name or a fully-qualified name
    *                   using dotted notation
    * @param metricPath (optional) additional top-most metric name path elements
    */
-  public static void register(String registry, Metric metric, boolean skipExisting, String
metricName, String... metricPath) {
+  public static void register(String registry, Metric metric, boolean force, String metricName,
String... metricPath) {
     MetricRegistry metricRegistry = registry(registry);
     String fullName = mkName(metricName, metricPath);
-    if (skipExisting && metricRegistry.getMetrics().containsKey(fullName)) {
-      return;
+    if (force && metricRegistry.getMetrics().containsKey(fullName)) {
+      metricRegistry.remove(fullName);
     }
     metricRegistry.register(fullName, metric);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92ef10db/solr/core/src/test/org/apache/solr/handler/admin/MetricsHandlerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/MetricsHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/MetricsHandlerTest.java
index 83ce74f..3667285 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/MetricsHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/MetricsHandlerTest.java
@@ -53,6 +53,8 @@ public class MetricsHandlerTest extends SolrTestCaseJ4 {
     assertNotNull(((NamedList) nl.get("newSearcherErrors")).get("requests"));
     assertEquals(0L, ((NamedList) nl.get("newSearcherErrors")).get("requests"));
     nl = (NamedList) values.get("solr.node");
+    assertNotNull(nl.get("cores.loaded")); // int gauge
+    assertEquals(1, ((NamedList) nl.get("cores.loaded")).get("value"));
     assertNotNull(nl.get("QUERYHANDLER./admin/authorization.clientErrors")); // timer type
     assertEquals(5, ((NamedList) nl.get("QUERYHANDLER./admin/authorization.clientErrors")).size());
 


Mime
View raw message