SOLR-11215: Support retrieval of any property of a regular metric when

using 'key' parameter.
This commit is contained in:
Andrzej Bialecki 2017-09-07 18:21:55 +02:00
parent 5324c7436c
commit 26ed40bcdb
2 changed files with 17 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -139,14 +140,18 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
continue; continue;
} }
MetricUtils.PropertyFilter propertyFilter = MetricUtils.PropertyFilter.ALL; MetricUtils.PropertyFilter propertyFilter = MetricUtils.PropertyFilter.ALL;
boolean simple = false;
if (propertyName != null) { if (propertyName != null) {
propertyFilter = (name) -> name.equals(propertyName); propertyFilter = (name) -> name.equals(propertyName);
simple = true;
// use escaped versions // use escaped versions
key = parts[0] + ":" + parts[1]; 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); rsp.getValues().add("metrics", result);
if (errors.size() > 0) { if (errors.size() > 0) {

View File

@ -277,6 +277,15 @@ public class MetricsHandlerTest extends SolrTestCaseJ4 {
val = values.findRecursive("metrics", key3); val = values.findRecursive("metrics", key3);
assertNotNull(val); 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 // test errors
// invalid keys // invalid keys