diff --git a/solr/core/src/java/org/apache/solr/response/PrometheusResponseWriter.java b/solr/core/src/java/org/apache/solr/response/PrometheusResponseWriter.java index d56a85b9bbe5..6d555be199ea 100644 --- a/solr/core/src/java/org/apache/solr/response/PrometheusResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/PrometheusResponseWriter.java @@ -63,6 +63,13 @@ public void write( // Otherwise handle MetricSnapshots var metrics = response.getValues().get("metrics"); if (metrics == null) { + // e.g. metrics collection disabled: emit the reason as a comment; the EOF marker required + // by OpenMetrics is harmless in Prometheus format + var error = response.getValues().get("error"); + if (error != null) { + out.write(("# " + error + "\n# EOF\n").getBytes(StandardCharsets.UTF_8)); + return; + } throw new IOException("No metrics found in response"); } MetricSnapshots snapshots = (MetricSnapshots) metrics; diff --git a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java index 610b7267cbe3..16761ec3ab31 100644 --- a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java @@ -19,6 +19,7 @@ import static org.apache.solr.client.solrj.response.InputStreamResponseParser.STREAM_KEY; import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP; +import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.lang.invoke.MethodHandles; import java.nio.charset.StandardCharsets; @@ -185,6 +186,16 @@ public void testDefaultPrometheusFormatNoWtParam() throws Exception { } } + @Test + public void testDisabledMetricsWritesErrorComment() throws Exception { + // SOLR-18400: disabled metrics must yield a graceful comment, not a 500 + SolrQueryResponse rsp = new SolrQueryResponse(); + rsp.add("error", "metrics collection is disabled"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new PrometheusResponseWriter().write(out, null, rsp, null); + assertEquals("# metrics collection is disabled\n# EOF\n", out.toString(StandardCharsets.UTF_8)); + } + @Test public void testUnsupportedMetricsFormat() throws Exception { var req = new MetricsRequest(); diff --git a/solr/webapp/web/js/angular/controllers/plugins.js b/solr/webapp/web/js/angular/controllers/plugins.js index bf0dd9bcac73..032a785fb17a 100644 --- a/solr/webapp/web/js/angular/controllers/plugins.js +++ b/solr/webapp/web/js/angular/controllers/plugins.js @@ -35,6 +35,7 @@ solrAdminApp.controller('PluginsController', var type = $location.search().type; Metrics.raw(params, function (response) { + $scope.metricsDisabled = (response.data || '').indexOf('metrics collection is disabled') !== -1; $scope.types = getPluginTypesFromMetrics(response.data, type); $scope.type = getSelectedType($scope.types, type); diff --git a/solr/webapp/web/partials/plugins.html b/solr/webapp/web/partials/plugins.html index 1e80b6f9b6e7..f858f4ce6ddf 100644 --- a/solr/webapp/web/partials/plugins.html +++ b/solr/webapp/web/partials/plugins.html @@ -17,6 +17,9 @@
+
+
Metrics collection is disabled in this node's solr.xml (<metrics enabled="false">), so no plugin information is available.
+