Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions solr/webapp/web/js/angular/controllers/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions solr/webapp/web/partials/plugins.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<div id="plugins" class="clearfix">

<div id="frame">
<div class="message-container" ng-show="metricsDisabled">
<div class="message">Metrics collection is disabled in this node's solr.xml (&lt;metrics enabled="false"&gt;), so no plugin information is available.</div>
</div>
<ul>
<li class="entry" ng-class="{changed: plugin.changed}" ng-repeat="plugin in type.plugins">
<a ng-click="selectPlugin(plugin)">
Expand Down
Loading