You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kr...@apache.org on 2017/01/06 21:47:28 UTC
[08/25] lucene-solr:jira/solr-8593: SOLR-9911: Add a way to filter
metrics by prefix in the MetricsHandler API
SOLR-9911: Add a way to filter metrics by prefix in the MetricsHandler API
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0452cb8c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0452cb8c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0452cb8c
Branch: refs/heads/jira/solr-8593
Commit: 0452cb8c969f156dc7086d16b2ca0b7814fa322e
Parents: 12d8492
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Wed Jan 4 20:17:45 2017 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Wed Jan 4 20:17:45 2017 +0530
----------------------------------------------------------------------
solr/CHANGES.txt | 10 ++++--
.../solr/handler/admin/MetricsHandler.java | 16 +++++++--
.../org/apache/solr/util/stats/MetricUtils.java | 13 ++++++--
.../solr/handler/admin/MetricsHandlerTest.java | 35 +++++++++++++++++++-
4 files changed, 65 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0452cb8c/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1ad6359..82fd7ae 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -186,9 +186,13 @@ New Features
* SOLR-9805: Use metrics-jvm library to instrument jvm internals such as GC, memory usage and others. (shalin)
-* SOLR-9812: Added a new /admin/metrics API to return all metrics collected by Solr via API. API supports two
- optional parameters 'group' (all,jvm,jetty,http,node,core) and 'type' (all,counter,timer,gauge,histogram) both
- of which are multi-valued. Example: http://localhost:8983/solr/admin/metrics?group=jvm,jetty&type=counter
+* SOLR-9812: SOLR-9911: Added a new /admin/metrics API to return all metrics collected by Solr via API.
+ API supports three optional parameters:
+ * 'group' (all,jvm,jetty,http,node,core),
+ * 'type' (all,counter,timer,gauge,histogram) both of which are multi-valued
+ * 'prefix' that filters the return metrics
+ Example: http://localhost:8983/solr/admin/metrics?group=jvm,jetty&type=counter
+ Example: http://localhost:8983/solr/admin/metrics?group=jvm&prefix=buffers
(shalin)
* SOLR-9884: Add version to segments handler output (Steven Bower via Erick Erickson)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0452cb8c/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 78b2045..428a72b 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
@@ -71,6 +71,7 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "Core container instance not initialized");
}
+ MetricFilter mustMatchFilter = parseMustMatchFilter(req);
List<MetricType> metricTypes = parseMetricTypes(req);
List<MetricFilter> metricFilters = metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
List<Group> requestedGroups = parseGroups(req);
@@ -86,16 +87,27 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
coreRegistryName = core.getCoreMetricManager().getRegistryName();
}
MetricRegistry registry = metricManager.registry(coreRegistryName);
- response.add(coreRegistryName, MetricUtils.toNamedList(registry, metricFilters));
+ response.add(coreRegistryName, MetricUtils.toNamedList(registry, metricFilters, mustMatchFilter));
});
} else {
MetricRegistry registry = metricManager.registry(registryName);
- response.add(registryName, MetricUtils.toNamedList(registry, metricFilters));
+ response.add(registryName, MetricUtils.toNamedList(registry, metricFilters, mustMatchFilter));
}
}
rsp.getValues().add("metrics", response);
}
+ private MetricFilter parseMustMatchFilter(SolrQueryRequest req) {
+ String prefix = req.getParams().get("prefix");
+ MetricFilter mustMatchFilter;
+ if (prefix != null) {
+ mustMatchFilter = new SolrMetricManager.PrefixFilter(prefix.trim());
+ } else {
+ mustMatchFilter = MetricFilter.ALL;
+ }
+ return mustMatchFilter;
+ }
+
private List<Group> parseGroups(SolrQueryRequest req) {
String[] groupStr = req.getParams().getParams("group");
List<String> groups = Collections.emptyList();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0452cb8c/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java b/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java
index 4a83c86..0d386ae 100644
--- a/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/stats/MetricUtils.java
@@ -72,14 +72,21 @@ public class MetricUtils {
* are converted to NamedList which match at least one of the given MetricFilter instances.
*
* @param registry the {@link MetricRegistry} to be converted to NamedList
- * @param metricFilters a list of {@link MetricFilter} instances
+ * @param shouldMatchFilters a list of {@link MetricFilter} instances.
+ * A metric must match <em>any one</em> of the filters from this list to be
+ * included in the output
+ * @param mustMatchFilter a {@link MetricFilter}.
+ * A metric <em>must</em> match this filter to be included in the output.
* @return a {@link NamedList}
*/
- public static NamedList toNamedList(MetricRegistry registry, List<MetricFilter> metricFilters) {
+ public static NamedList toNamedList(MetricRegistry registry, List<MetricFilter> shouldMatchFilters, MetricFilter mustMatchFilter) {
NamedList response = new NamedList();
Map<String, Metric> metrics = registry.getMetrics();
SortedSet<String> names = registry.getNames();
- names.stream().filter(s -> metricFilters.stream().anyMatch(metricFilter -> metricFilter.matches(s, metrics.get(s)))).forEach(n -> {
+ names.stream()
+ .filter(s -> shouldMatchFilters.stream().anyMatch(metricFilter -> metricFilter.matches(s, metrics.get(s))))
+ .filter(s -> mustMatchFilter.matches(s, metrics.get(s)))
+ .forEach(n -> {
Metric metric = metrics.get(n);
if (metric instanceof Counter) {
Counter counter = (Counter) metric;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0452cb8c/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 e15778d..67bf0e3 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
@@ -91,7 +91,40 @@ public class MetricsHandlerTest extends SolrTestCaseJ4 {
assertNotNull(values.get("metrics"));
values = (NamedList) values.get("metrics");
assertEquals(1, values.size());
- assertNotNull(values.get("solr.node"));
+ values = (NamedList) values.get("solr.node");
+ assertNotNull(values);
assertNull(values.get("QUERYHANDLER./admin/authorization.errors")); // this is a timer node
+
+ resp = new SolrQueryResponse();
+ handler.handleRequestBody(req(CommonParams.QT, "/admin/metrics", CommonParams.WT, "json", "prefix", "cores"), resp);
+ values = resp.getValues();
+ assertNotNull(values.get("metrics"));
+ values = (NamedList) values.get("metrics");
+ assertEquals(5, values.size());
+ assertEquals(0, ((NamedList)values.get("solr.jvm")).size());
+ assertEquals(0, ((NamedList)values.get("solr.http")).size());
+ assertEquals(0, ((NamedList)values.get("solr.jetty")).size());
+ assertEquals(0, ((NamedList)values.get("solr.core.collection1")).size());
+ assertEquals(3, ((NamedList)values.get("solr.node")).size());
+ assertNotNull(values.get("solr.node"));
+ values = (NamedList) values.get("solr.node");
+ assertNotNull(values.get("cores.lazy")); // this is a gauge node
+
+ resp = new SolrQueryResponse();
+ handler.handleRequestBody(req(CommonParams.QT, "/admin/metrics", CommonParams.WT, "json", "group", "jvm", "prefix", "cores"), resp);
+ values = resp.getValues();
+ assertNotNull(values.get("metrics"));
+ values = (NamedList) values.get("metrics");
+ assertEquals(1, values.size());
+ assertEquals(0, ((NamedList)values.get("solr.jvm")).size());
+ assertNull(values.get("solr.node"));
+
+ resp = new SolrQueryResponse();
+ handler.handleRequestBody(req(CommonParams.QT, "/admin/metrics", CommonParams.WT, "json", "group", "node", "type", "timer", "prefix", "cores"), resp);
+ values = resp.getValues();
+ assertNotNull(values.get("metrics"));
+ values = (NamedList) values.get("metrics");
+ assertEquals(1, values.size());
+ assertEquals(0, ((NamedList)values.get("solr.node")).size());
}
}