From 26ed40bcdbd42fc94e18d9e491536da5515ac9fe Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki <ab@apache.org> Date: Thu, 7 Sep 2017 18:21:55 +0200 Subject: [PATCH] SOLR-11215: Support retrieval of any property of a regular metric when using 'key' parameter. --- .../org/apache/solr/handler/admin/MetricsHandler.java | 11 ++++++++--- .../apache/solr/handler/admin/MetricsHandlerTest.java | 9 +++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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 a9a2d1f81e1..ed1e4747e7f 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 @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -139,14 +140,18 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName continue; } MetricUtils.PropertyFilter propertyFilter = MetricUtils.PropertyFilter.ALL; - boolean simple = false; if (propertyName != null) { propertyFilter = (name) -> name.equals(propertyName); - simple = true; // use escaped versions key = parts[0] + ":" + parts[1]; } - MetricUtils.convertMetric(key, m, propertyFilter, false, true, true, simple, ":", (k, v) -> result.add(k, v)); + MetricUtils.convertMetric(key, m, propertyFilter, false, true, true, false, ":", (k, v) -> { + if ((v instanceof Map) && propertyName != null) { + ((Map)v).forEach((k1, v1) -> result.add(k + ":" + k1, v1)); + } else { + result.add(k, v); + } + }); } rsp.getValues().add("metrics", result); if (errors.size() > 0) { 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 7eb8f12ba51..0fe5ad75fc6 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 @@ -277,6 +277,15 @@ public class MetricsHandlerTest extends SolrTestCaseJ4 { val = values.findRecursive("metrics", key3); assertNotNull(val); + String key4 = "solr.core.collection1:QUERY./select.requestTimes:1minRate"; + resp = new SolrQueryResponse(); + handler.handleRequestBody(req(CommonParams.QT, "/admin/metrics", CommonParams.WT, "json", + MetricsHandler.KEY_PARAM, key4), resp); + values = resp.getValues(); + val = values.findRecursive("metrics", key4); + assertNotNull(val); + assertTrue(val instanceof Number); + // test errors // invalid keys