You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2020/10/13 13:00:21 UTC
[lucene-solr] 02/02: SOLR-14914: Add RefGuide docs for this option.
Turn off metrics for most tests.
This is an automated email from the ASF dual-hosted git repository.
ab pushed a commit to branch jira/solr-14914
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 77ac8fb87d272c3ea325910ddeed38612f554dfe
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Tue Oct 13 14:59:29 2020 +0200
SOLR-14914: Add RefGuide docs for this option. Turn off metrics for most tests.
---
.../org/apache/solr/handler/admin/MetricsHandler.java | 16 ++++++++++------
.../apache/solr/handler/admin/MetricsHistoryHandler.java | 8 +++++++-
.../apache/solr/cloud/MetricsHistoryIntegrationTest.java | 1 +
.../solr/handler/admin/MetricsHistoryHandlerTest.java | 1 +
solr/solr-ref-guide/src/metrics-history.adoc | 3 +++
solr/solr-ref-guide/src/metrics-reporting.adoc | 15 +++++++++++++++
.../java/org/apache/solr/cloud/MiniSolrCloudCluster.java | 2 +-
7 files changed, 38 insertions(+), 8 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 b63a752..d3b5cb9 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,20 +71,24 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
public static final String ALL = "all";
private static final Pattern KEY_REGEX = Pattern.compile("(?<!" + Pattern.quote("\\") + ")" + Pattern.quote(":"));
- private CoreContainer cc;
+ private final CoreContainer cc;
private final Map<String, String> injectedSysProps = CommonTestInjection.injectAdditionalProps();
-
- public MetricsHandler() {
- this.metricManager = null;
- }
+ private final boolean enabled;
public MetricsHandler(CoreContainer coreContainer) {
this.metricManager = coreContainer.getMetricManager();
this.cc = coreContainer;
+ this.enabled = coreContainer.getConfig().getMetricsConfig().isEnabled();
}
public MetricsHandler(SolrMetricManager metricManager) {
this.metricManager = metricManager;
+ this.cc = null;
+ this.enabled = true;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
}
@Override
@@ -107,7 +111,7 @@ public class MetricsHandler extends RequestHandlerBase implements PermissionName
@SuppressWarnings({"unchecked"})
public void handleRequest(SolrParams params, BiConsumer<String, Object> consumer) throws Exception {
- if (!cc.getNodeConfig().getMetricsConfig().isEnabled()) {
+ if (!enabled) {
consumer.accept("error", "metrics collection is disabled");
return;
}
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java
index 56c4003..35c89b1 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/MetricsHistoryHandler.java
@@ -196,7 +196,9 @@ public class MetricsHistoryHandler extends RequestHandlerBase implements Permiss
}
this.nodeName = nodeName;
- this.enable = Boolean.parseBoolean(String.valueOf(args.getOrDefault(ENABLE_PROP, "true")));
+ // disable when metrics reporting is disabled
+ this.enable = Boolean.parseBoolean(String.valueOf(args.getOrDefault(ENABLE_PROP, "true")))
+ && metricsHandler.isEnabled();
// default to false - don't collect local per-replica metrics
this.enableReplicas = Boolean.parseBoolean(String.valueOf(args.getOrDefault(ENABLE_REPLICAS_PROP, "false")));
this.enableNodes = Boolean.parseBoolean(String.valueOf(args.getOrDefault(ENABLE_NODES_PROP, "false")));
@@ -699,6 +701,10 @@ public class MetricsHistoryHandler extends RequestHandlerBase implements Permiss
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
+ if (!enable) {
+ rsp.add("error", "metrics collection is disabled");
+ return;
+ }
String actionStr = req.getParams().get(CommonParams.ACTION);
if (actionStr == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'action' is a required param");
diff --git a/solr/core/src/test/org/apache/solr/cloud/MetricsHistoryIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/MetricsHistoryIntegrationTest.java
index 897f060..1a685d6 100644
--- a/solr/core/src/test/org/apache/solr/cloud/MetricsHistoryIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/MetricsHistoryIntegrationTest.java
@@ -59,6 +59,7 @@ public class MetricsHistoryIntegrationTest extends SolrCloudTestCase {
@BeforeClass
public static void setupCluster() throws Exception {
+ System.setProperty("metricsEnabled", "true");
configureCluster(1)
.addConfig("conf", configset("cloud-minimal"))
.configure();
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
index 2c2ce88..ea536be 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/MetricsHistoryHandlerTest.java
@@ -58,6 +58,7 @@ public class MetricsHistoryHandlerTest extends SolrCloudTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
+ System.setProperty("metricsEnabled", "true");
Map<String, Object> args = new HashMap<>();
args.put(MetricsHistoryHandler.SYNC_PERIOD_PROP, 1);
args.put(MetricsHistoryHandler.COLLECT_PERIOD_PROP, 1);
diff --git a/solr/solr-ref-guide/src/metrics-history.adoc b/solr/solr-ref-guide/src/metrics-history.adoc
index 992a36f..640736c 100644
--- a/solr/solr-ref-guide/src/metrics-history.adoc
+++ b/solr/solr-ref-guide/src/metrics-history.adoc
@@ -121,6 +121,9 @@ The handler assumes that a simple aggregation (sum of partial metric values from
sufficient. This happens to make sense for the default built-in sets of metrics. Future extensions will
provide other aggregation strategies (such as, average, max, min, etc.).
+This handler is automatically disabled when metrics collection is disabled using the
+`<metrics enabled="false">` element in `solr.xml`.
+
== Metrics History Configuration
There are two ways to configure this subsystem:
diff --git a/solr/solr-ref-guide/src/metrics-reporting.adoc b/solr/solr-ref-guide/src/metrics-reporting.adoc
index b319bb2..0688255 100644
--- a/solr/solr-ref-guide/src/metrics-reporting.adoc
+++ b/solr/solr-ref-guide/src/metrics-reporting.adoc
@@ -87,6 +87,21 @@ The metrics available in your system can be customized by modifying the `<metric
TIP: See also the section <<format-of-solr-xml.adoc#format-of-solr-xml,Format of Solr.xml>> for more information about the `solr.xml` file, where to find it, and how to edit it.
+=== Disabling the metrics collection ===
+The `<metrics>` element in `solr.xml` supports one attribute `enabled`, which takes a boolean value,
+for example `<metrics enabled="true">`.
+
+The default value of this attribute is `true`, meaning that metrics are being collected, processed and
+reported by Solr according to the configured metric reporters. They are also available from the
+metrics and metrics history APIs.
+
+The `false` value of this attribute (`<metrics enabled="false">`) turns off metrics collection, processing,
+and the collection of metrics history. Internally, all metrics suppliers are replaced by singleton no-op
+implementations, which effectively removes nearly all overheads related to metrics collection.
+All reporter configurations are skipped, and the metrics
+and metrics history APIs stop reporting any metrics and only return an `<error>`
+element in their responses.
+
=== The <metrics> <hiddenSysProps> Element
This section of `solr.xml` allows you to define the system properties which are considered system-sensitive and should not be exposed via the Metrics API.
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
index 9870a50..4af902b 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
@@ -118,7 +118,7 @@ public class MiniSolrCloudCluster {
" <str name=\"pkiHandlerPrivateKeyPath\">${pkiHandlerPrivateKeyPath:cryptokeys/priv_key512_pkcs8.pem}</str> \n" +
" <str name=\"pkiHandlerPublicKeyPath\">${pkiHandlerPublicKeyPath:cryptokeys/pub_key512.der}</str> \n" +
" </solrcloud>\n" +
- " <metrics enabled=\"${metricsEnabled:true}\">\n" +
+ " <metrics enabled=\"${metricsEnabled:false}\">\n" +
" <reporter name=\"default\" class=\"org.apache.solr.metrics.reporters.SolrJmxReporter\">\n" +
" <str name=\"rootName\">solr_${hostPort:8983}</str>\n" +
" </reporter>\n" +