lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject lucene-solr:jira/solr-9959: SOLR-9959 Add support for "regex" selectors to /admin/metrics.
Date Wed, 29 Mar 2017 17:58:17 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/jira/solr-9959 d285fa6c4 -> 5d028e0de


SOLR-9959 Add support for "regex" selectors to /admin/metrics.


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

Branch: refs/heads/jira/solr-9959
Commit: 5d028e0de5c091fef17f8074a7edc7dd4e20a780
Parents: d285fa6
Author: Andrzej Bialecki <ab@apache.org>
Authored: Wed Mar 29 19:57:24 2017 +0200
Committer: Andrzej Bialecki <ab@apache.org>
Committed: Wed Mar 29 19:57:24 2017 +0200

----------------------------------------------------------------------
 .../solr/handler/admin/MetricsHandler.java      | 40 +++++++++++++++-----
 .../apache/solr/metrics/SolrMetricManager.java  | 30 +++++++++++++++
 .../solr/handler/admin/MetricsHandlerTest.java  | 15 ++++++++
 3 files changed, 75 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d028e0d/solr/core/src/java/org/apache/solr/handler/admin/MetricsHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/MetricsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/MetricsHandler.java
index 25f317c..46c27cc 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/MetricsHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/MetricsHandler.java
@@ -19,6 +19,7 @@ package org.apache.solr.handler.admin;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -51,6 +52,13 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
   final SolrMetricManager metricManager;
 
   public static final String COMPACT_PARAM = "compact";
+  public static final String PREFIX_PARAM = "prefix";
+  public static final String REGEX_PARAM = "regex";
+  public static final String REGISTRY_PARAM = "registry";
+  public static final String GROUP_PARAM = "group";
+  public static final String TYPE_PARAM = "type";
+
+  public static final String ALL = "all";
 
   public MetricsHandler() {
     this.container = null;
@@ -89,23 +97,32 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
   }
 
   private MetricFilter parseMustMatchFilter(SolrQueryRequest req) {
-    String[] prefixes = req.getParams().getParams("prefix");
-    MetricFilter mustMatchFilter;
+    String[] prefixes = req.getParams().getParams(PREFIX_PARAM);
+    MetricFilter prefixFilter = null;
     if (prefixes != null && prefixes.length > 0) {
       Set<String> prefixSet = new HashSet<>();
       for (String prefix : prefixes) {
         prefixSet.addAll(StrUtils.splitSmart(prefix, ','));
       }
-      mustMatchFilter = new SolrMetricManager.PrefixFilter((String[])prefixSet.toArray(new
String[prefixSet.size()]));
-    } else  {
+      prefixFilter = new SolrMetricManager.PrefixFilter((String[])prefixSet.toArray(new String[prefixSet.size()]));
+    }
+    String[] regexes = req.getParams().getParams(REGEX_PARAM);
+    MetricFilter regexFilter = null;
+    if (regexes != null && regexes.length > 0) {
+      regexFilter = new SolrMetricManager.RegexFilter(regexes);
+    }
+    MetricFilter mustMatchFilter;
+    if (prefixFilter == null && regexFilter == null) {
       mustMatchFilter = MetricFilter.ALL;
+    } else {
+      mustMatchFilter = new SolrMetricManager.OrFilter(prefixFilter, regexFilter);
     }
     return mustMatchFilter;
   }
 
   private Set<String> parseRegistries(SolrQueryRequest req) {
-    String[] groupStr = req.getParams().getParams("group");
-    String[] registryStr = req.getParams().getParams("registry");
+    String[] groupStr = req.getParams().getParams(GROUP_PARAM);
+    String[] registryStr = req.getParams().getParams(REGISTRY_PARAM);
     if ((groupStr == null || groupStr.length == 0) && (registryStr == null || registryStr.length
== 0)) {
       // return all registries
       return container.getMetricManager().registryNames();
@@ -117,7 +134,7 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
       for (String g : groupStr) {
         List<String> split = StrUtils.splitSmart(g, ',');
         for (String s : split) {
-          if (s.trim().equals("all")) {
+          if (s.trim().equals(ALL)) {
             allRegistries = true;
             break;
           }
@@ -136,7 +153,7 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
       for (String r : registryStr) {
         List<String> split = StrUtils.splitSmart(r, ',');
         for (String s : split) {
-          if (s.trim().equals("all")) {
+          if (s.trim().equals(ALL)) {
             allRegistries = true;
             break;
           }
@@ -160,7 +177,7 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
   }
 
   private List<MetricType> parseMetricTypes(SolrQueryRequest req) {
-    String[] typeStr = req.getParams().getParams("type");
+    String[] typeStr = req.getParams().getParams(TYPE_PARAM);
     List<String> types = Collections.emptyList();
     if (typeStr != null && typeStr.length > 0)  {
       types = new ArrayList<>();
@@ -175,7 +192,8 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
         metricTypes = types.stream().map(String::trim).map(MetricType::valueOf).collect(Collectors.toList());
       }
     } catch (IllegalArgumentException e) {
-      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid metric type in:
" + types + " specified. Must be one of (all, meter, timer, histogram, counter, gauge)", e);
+      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid metric type in:
" + types +
+          " specified. Must be one of " + MetricType.SUPPORTED_TYPES_MSG, e);
     }
     return metricTypes;
   }
@@ -198,6 +216,8 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
     gauge(Gauge.class),
     all(null);
 
+    public static final String SUPPORTED_TYPES_MSG = EnumSet.allOf(MetricType.class).toString();
+
     private final Class klass;
 
     MetricType(Class klass) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d028e0d/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 3914508..ba9f9f2 100644
--- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
@@ -247,6 +247,36 @@ public class SolrMetricManager {
     }
   }
 
+  public static class OrFilter implements MetricFilter {
+    List<MetricFilter> filters = new ArrayList<>();
+
+    public OrFilter(Collection<MetricFilter> filters) {
+      if (filters != null) {
+        this.filters.addAll(filters);
+      }
+    }
+
+    public OrFilter(MetricFilter... filters) {
+      if (filters != null) {
+        for (MetricFilter filter : filters) {
+          if (filter != null) {
+            this.filters.add(filter);
+          }
+        }
+      }
+    }
+
+    @Override
+    public boolean matches(String s, Metric metric) {
+      for (MetricFilter filter : filters) {
+        if (filter.matches(s, metric)) {
+          return true;
+        }
+      }
+      return false;
+    }
+  }
+
   /**
    * Return a set of existing registry names.
    */

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d028e0d/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 81e14d9..3cdc8ef 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
@@ -17,6 +17,7 @@
 
 package org.apache.solr.handler.admin;
 
+import java.lang.management.ManagementFactory;
 import java.util.Map;
 
 import org.apache.solr.SolrTestCaseJ4;
@@ -32,6 +33,9 @@ import org.junit.Test;
 public class MetricsHandlerTest extends SolrTestCaseJ4 {
   @BeforeClass
   public static void beforeClass() throws Exception {
+    // this is needed to enable default SolrJmxReporter in TestHarness
+    ManagementFactory.getPlatformMBeanServer();
+
     initCore("solrconfig.xml", "schema.xml");
   }
 
@@ -135,6 +139,17 @@ public class MetricsHandlerTest extends SolrTestCaseJ4 {
     assertNotNull(values.get("CONTAINER.threadPool.coreLoadExecutor.completed"));
 
     resp = new SolrQueryResponse();
+    handler.handleRequestBody(req(CommonParams.QT, "/admin/metrics", CommonParams.WT, "json",
"prefix", "CONTAINER.cores", "regex", "C.*thread.*completed"), resp);
+    values = resp.getValues();
+    assertNotNull(values.get("metrics"));
+    values = (NamedList) values.get("metrics");
+    assertNotNull(values.get("solr.node"));
+    values = (NamedList) values.get("solr.node");
+    assertEquals(5, values.size());
+    assertNotNull(values.get("CONTAINER.threadPool.coreContainerWorkExecutor.completed"));
+    assertNotNull(values.get("CONTAINER.threadPool.coreLoadExecutor.completed"));
+
+    resp = new SolrQueryResponse();
     handler.handleRequestBody(req(CommonParams.QT, "/admin/metrics", CommonParams.WT, "json",
"group", "jvm", "prefix", "CONTAINER.cores"), resp);
     values = resp.getValues();
     assertNotNull(values.get("metrics"));


Mime
View raw message