This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new afa6cfcdba1 SOLR-17108: Prometheus Exporter: do not throw
NullPointerException. (#2057)
afa6cfcdba1 is described below
commit afa6cfcdba1ea55e82abea09f0bcd722e44689d6
Author: David Smiley <[email protected]>
AuthorDate: Mon Jan 1 17:41:08 2024 -0500
SOLR-17108: Prometheus Exporter: do not throw NullPointerException. (#2057)
Prometheus Exporter: don't throw NPE; gracefully handle no metrics
---
.../java/org/apache/solr/prometheus/scraper/SolrScraper.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git
a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java
b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java
index a65de0de431..273f6826176 100644
---
a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java
+++
b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java
@@ -133,17 +133,23 @@ public abstract class SolrScraper implements Closeable {
QueryRequest queryRequest = new QueryRequest(query.getParameters());
queryRequest.setPath(query.getPath());
- NamedList<Object> queryResponse = null;
+ NamedList<Object> queryResponse;
try {
- if (!query.getCollection().isPresent() && !query.getCore().isPresent()) {
+ if (query.getCollection().isEmpty() && query.getCore().isEmpty()) {
queryResponse = client.request(queryRequest);
} else if (query.getCore().isPresent()) {
queryResponse = client.request(queryRequest, query.getCore().get());
} else if (query.getCollection().isPresent()) {
queryResponse = client.request(queryRequest,
query.getCollection().get());
+ } else {
+ throw new AssertionError("Invalid configuration");
+ }
+ if (queryResponse == null) { // ideally we'd make this impossible
+ throw new RuntimeException("no response from server");
}
} catch (SolrServerException | IOException e) {
log.error("failed to request: {}", queryRequest.getPath(), e);
+ return samples;
}
JsonNode jsonNode = OBJECT_MAPPER.readTree((String)
queryResponse.get("response"));