You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2017/01/04 14:49:20 UTC
[1/2] lucene-solr:branch_6x: SOLR-9911: Add a way to filter metrics
by prefix in the MetricsHandler API
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 084f7a060 -> 78a3fdfdc
SOLR-9911: Add a way to filter metrics by prefix in the MetricsHandler API
(cherry picked from commit 0452cb8)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e2761473
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e2761473
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e2761473
Branch: refs/heads/branch_6x
Commit: e2761473f9bf44175b7f1b6298a3b2aac10a786c
Parents: 084f7a0
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:19:08 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/e2761473/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 346aeba..1bd59c3 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -130,9 +130,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-9880: Add Ganglia, Graphite and SLF4J metrics reporters. (ab)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e2761473/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/e2761473/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/e2761473/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());
}
}
[2/2] lucene-solr:branch_6x: SOLR-9911: Fix typo in CHANGES.txt
Posted by sh...@apache.org.
SOLR-9911: Fix typo in CHANGES.txt
(cherry picked from commit f87efac)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/78a3fdfd
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/78a3fdfd
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/78a3fdfd
Branch: refs/heads/branch_6x
Commit: 78a3fdfdcb83fa6786229802777a891248a62d54
Parents: e276147
Author: Shalin Shekhar Mangar <sh...@apache.org>
Authored: Wed Jan 4 20:18:18 2017 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Wed Jan 4 20:19:13 2017 +0530
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/78a3fdfd/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1bd59c3..e295bfc 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -134,7 +134,7 @@ New Features
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
+ * 'prefix' that filters the returned 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)