You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2024/01/02 17:35:14 UTC
(solr) branch branch_9x updated: SOLR-17108: Prometheus Exporter: do not throw NullPointerException. (#2057)
This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 617ed3845d2 SOLR-17108: Prometheus Exporter: do not throw NullPointerException. (#2057)
617ed3845d2 is described below
commit 617ed3845d239ab294f07f8fb747ae56ad920c89
Author: David Smiley <ds...@apache.org>
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"));