Apache Solr open-source search software
SOLR-16035: Enable spotless for prometheus-exporter
Kevin Risden71732e46adf6
diff --git a/gradle/validation/spotless.gradle b/gradle/validation/spotless.gradleindex 8f4f0f56e6c..bfb00bcf734 100644--- a/gradle/validation/spotless.gradle+++ b/gradle/validation/spotless.gradle@@ -54,7 +54,6 @@ configure(project(":solr").subprojects) { prj ->case ":solr:modules:langid":case ":solr:modules:ltr":case ":solr:modules:scripting":- case ":solr:prometheus-exporter":case ":solr:core":case ":solr:solrj":case ":solr:solr-ref-guide":diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/CollectionsCollector.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/CollectionsCollector.javaindex fa8f1ceb93f..c6262b784c7 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/CollectionsCollector.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/CollectionsCollector.java@@ -34,5 +34,4 @@ public class CollectionsCollector implements MetricCollector {public MetricSamples collect() throws Exception {return solrClient.collections(metricsQuery);}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricSamples.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricSamples.javaindex d71616c98d5..9fae6ce23ed 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricSamples.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricSamples.java@@ -17,13 +17,12 @@package org.apache.solr.prometheus.collector;+import io.prometheus.client.Collector;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.stream.Collectors;-import io.prometheus.client.Collector;-public class MetricSamples {private final Map<String, Collector.MetricFamilySamples> samplesByMetricName;@@ -40,7 +39,8 @@ public class MetricSamples {samplesByMetricName.putIfAbsent(metricName, samples);}- public void addSampleIfMetricExists(String metricName, Collector.MetricFamilySamples.Sample sample) {+ public void addSampleIfMetricExists(+ String metricName, Collector.MetricFamilySamples.Sample sample) {Collector.MetricFamilySamples sampleFamily = samplesByMetricName.get(metricName);if (sampleFamily == null) {@@ -53,7 +53,8 @@ public class MetricSamples {}public void addAll(MetricSamples other) {- for (Map.Entry<String, Collector.MetricFamilySamples> entry : other.samplesByMetricName.entrySet()) {+ for (Map.Entry<String, Collector.MetricFamilySamples> entry :+ other.samplesByMetricName.entrySet()) {String key = entry.getKey();if (this.samplesByMetricName.containsKey(key)) {for (Collector.MetricFamilySamples.Sample sample : entry.getValue().samples) {@@ -70,5 +71,4 @@ public class MetricSamples {.filter(value -> !value.samples.isEmpty()).collect(Collectors.toList());}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollector.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollector.javaindex 4fee6c83164..c96b70c9b73 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollector.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollector.java@@ -34,11 +34,8 @@ public class MetricsCollector implements MetricCollector {public MetricSamples collect() throws Exception {MetricSamples results = new MetricSamples();- solrClient.metricsForAllHosts(metricsQuery)- .forEach((host, samples) -> results.addAll(samples));+ solrClient.metricsForAllHosts(metricsQuery).forEach((host, samples) -> results.addAll(samples));return results;}--}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollectorFactory.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollectorFactory.javaindex fdf8c8ea83f..bbb2dd7ca8c 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollectorFactory.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/MetricsCollectorFactory.java@@ -22,7 +22,6 @@ import java.util.concurrent.ExecutorService;import java.util.concurrent.TimeUnit;import java.util.stream.Collectors;import java.util.stream.Stream;-import org.apache.solr.prometheus.exporter.MetricsConfiguration;import org.apache.solr.prometheus.scraper.SolrScraper;@@ -45,28 +44,28 @@ public class MetricsCollectorFactory {}public SchedulerMetricsCollector create() {- Stream<MetricCollector> pings = metricsConfiguration.getPingConfiguration()- .stream()- .map(query -> new PingCollector(solrScraper, query));+ Stream<MetricCollector> pings =+ metricsConfiguration.getPingConfiguration().stream()+ .map(query -> new PingCollector(solrScraper, query));- Stream<MetricCollector> metrics = metricsConfiguration.getMetricsConfiguration()- .stream()- .map(query -> new MetricsCollector(solrScraper, query));+ Stream<MetricCollector> metrics =+ metricsConfiguration.getMetricsConfiguration().stream()+ .map(query -> new MetricsCollector(solrScraper, query));- Stream<MetricCollector> searches = metricsConfiguration.getSearchConfiguration()- .stream()- .map(query -> new SearchCollector(solrScraper, query));+ Stream<MetricCollector> searches =+ metricsConfiguration.getSearchConfiguration().stream()+ .map(query -> new SearchCollector(solrScraper, query));- Stream<MetricCollector> collections = metricsConfiguration.getCollectionsConfiguration()- .stream()- .map(query -> new CollectionsCollector(solrScraper, query));+ Stream<MetricCollector> collections =+ metricsConfiguration.getCollectionsConfiguration().stream()+ .map(query -> new CollectionsCollector(solrScraper, query));- List<MetricCollector> collectors = Stream.of(pings, metrics, searches, collections)- .reduce(Stream::concat)- .orElseGet(Stream::empty)- .collect(Collectors.toList());+ List<MetricCollector> collectors =+ Stream.of(pings, metrics, searches, collections)+ .reduce(Stream::concat)+ .orElseGet(Stream::empty)+ .collect(Collectors.toList());return new SchedulerMetricsCollector(executor, refreshInSeconds, TimeUnit.SECONDS, collectors);}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/PingCollector.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/PingCollector.javaindex c35c57070f4..c0fed75c727 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/PingCollector.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/PingCollector.java@@ -34,13 +34,14 @@ public class PingCollector implements MetricCollector {public MetricSamples collect() throws Exception {MetricSamples results = new MetricSamples();- solrScraper.pingAllCollections(metricsQuery)+ solrScraper+ .pingAllCollections(metricsQuery).forEach((collection, metrics) -> results.addAll(metrics));- solrScraper.pingAllCores(metricsQuery)+ solrScraper+ .pingAllCores(metricsQuery).forEach((collection, metrics) -> results.addAll(metrics));return results;}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SchedulerMetricsCollector.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SchedulerMetricsCollector.javaindex f258932c2a1..8a1a3f60638 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SchedulerMetricsCollector.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SchedulerMetricsCollector.java@@ -17,6 +17,8 @@package org.apache.solr.prometheus.collector;+import io.prometheus.client.Collector;+import io.prometheus.client.Histogram;import java.io.Closeable;import java.lang.invoke.MethodHandles;import java.util.List;@@ -29,11 +31,8 @@ import java.util.concurrent.Future;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.TimeUnit;import java.util.stream.Collectors;--import io.prometheus.client.Collector;-import io.prometheus.client.Histogram;-import org.apache.solr.prometheus.exporter.SolrExporter;import org.apache.solr.common.util.SolrNamedThreadFactory;+import org.apache.solr.prometheus.exporter.SolrExporter;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -49,18 +48,19 @@ public class SchedulerMetricsCollector implements Closeable {private final int duration;private final TimeUnit timeUnit;- private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(- 1,- new SolrNamedThreadFactory("scheduled-metrics-collector"));+ private final ScheduledExecutorService scheduler =+ Executors.newScheduledThreadPool(+ 1, new SolrNamedThreadFactory("scheduled-metrics-collector"));private final ExecutorService executor;private final List<Observer> observers = new CopyOnWriteArrayList<>();- private static final Histogram metricsCollectionTime = Histogram.build()- .name("solr_exporter_duration_seconds")- .help("Duration taken to record all metrics")- .register(SolrExporter.defaultRegistry);+ private static final Histogram metricsCollectionTime =+ Histogram.build()+ .name("solr_exporter_duration_seconds")+ .help("Duration taken to record all metrics")+ .register(SolrExporter.defaultRegistry);public SchedulerMetricsCollector(ExecutorService executor,@@ -82,17 +82,17 @@ public class SchedulerMetricsCollector implements Closeable {try (Histogram.Timer timer = metricsCollectionTime.startTimer()) {log.info("Beginning metrics collection");- final List<Future<MetricSamples>> futures = executor.invokeAll(- metricCollectors.stream()- .map(metricCollector -> (Callable<MetricSamples>) metricCollector::collect)- .collect(Collectors.toList())- );+ final List<Future<MetricSamples>> futures =+ executor.invokeAll(+ metricCollectors.stream()+ .map(metricCollector -> (Callable<MetricSamples>) metricCollector::collect)+ .collect(Collectors.toList()));MetricSamples metricSamples = new MetricSamples();for (Future<MetricSamples> future : futures) {try {metricSamples.addAll(future.get());} catch (ExecutionException e) {- log.error("Error occurred during metrics collection", e.getCause());//nowarn+ log.error("Error occurred during metrics collection", e.getCause()); // nowarn// continue any ways; do not fail}}@@ -104,7 +104,6 @@ public class SchedulerMetricsCollector implements Closeable {log.warn("Interrupted waiting for metric collection to complete", e);Thread.currentThread().interrupt();}-}public void addObserver(Observer observer) {@@ -123,5 +122,4 @@ public class SchedulerMetricsCollector implements Closeable {public void close() {scheduler.shutdownNow();}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SearchCollector.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SearchCollector.javaindex 4300f754d78..b33ddf98a0a 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SearchCollector.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/SearchCollector.java@@ -34,5 +34,4 @@ public class SearchCollector implements MetricCollector {public MetricSamples collect() throws Exception {return solrClient.search(metricsQuery);}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/package-info.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/package-info.javaindex e49fdac346a..8d7c28cd97f 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/package-info.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/collector/package-info.java@@ -15,7 +15,5 @@* limitations under the License.*/-/**- * Collects metrics from Solr via various endpoints.- */+/** Collects metrics from Solr via various endpoints. */package org.apache.solr.prometheus.collector;diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/CachedPrometheusCollector.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/CachedPrometheusCollector.javaindex 73fd9f52767..835b1709a77 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/CachedPrometheusCollector.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/CachedPrometheusCollector.java@@ -17,12 +17,12 @@package org.apache.solr.prometheus.exporter;-import java.util.List;-import io.prometheus.client.Collector;+import java.util.List;import org.apache.solr.prometheus.collector.SchedulerMetricsCollector;-public class CachedPrometheusCollector extends Collector implements SchedulerMetricsCollector.Observer {+public class CachedPrometheusCollector extends Collector+ implements SchedulerMetricsCollector.Observer {private volatile List<MetricFamilySamples> samples;@@ -35,5 +35,4 @@ public class CachedPrometheusCollector extends Collector implements SchedulerMetpublic void metricsUpdated(List<MetricFamilySamples> samples) {this.samples = samples;}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsConfiguration.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsConfiguration.javaindex 1e3ec01aff5..28b923b2e4c 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsConfiguration.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsConfiguration.java@@ -17,10 +17,6 @@package org.apache.solr.prometheus.exporter;-import javax.xml.parsers.DocumentBuilderFactory;-import javax.xml.xpath.XPath;-import javax.xml.xpath.XPathConstants;-import javax.xml.xpath.XPathFactory;import java.io.File;import java.io.InputStream;import java.lang.invoke.MethodHandles;@@ -30,7 +26,10 @@ import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;-+import javax.xml.parsers.DocumentBuilderFactory;+import javax.xml.xpath.XPath;+import javax.xml.xpath.XPathConstants;+import javax.xml.xpath.XPathFactory;import net.thisptr.jackson.jq.exception.JsonQueryException;import org.apache.solr.common.StringUtils;import org.slf4j.Logger;@@ -98,7 +97,11 @@ public class MetricsConfiguration {if (Files.exists(path)) {document = dbf.newDocumentBuilder().parse(path.toUri().toASCIIString());} else {- try (InputStream configInputStream = MethodHandles.lookup().lookupClass().getClassLoader().getResourceAsStream(resource.replace(File.separatorChar, '/'))) {+ try (InputStream configInputStream =+ MethodHandles.lookup()+ .lookupClass()+ .getClassLoader()+ .getResourceAsStream(resource.replace(File.separatorChar, '/'))) {document = dbf.newDocumentBuilder().parse(configInputStream);}}@@ -110,9 +113,13 @@ public class MetricsConfiguration {Node settings = getNode(config, "/config/settings");NodeList jqTemplates =- (NodeList)(xpathFactory.newXPath()).evaluate("/config/jq-templates/template", config, XPathConstants.NODESET);- Map<String,MetricsQueryTemplate> jqTemplatesMap =- (jqTemplates != null && jqTemplates.getLength() > 0) ? loadJqTemplates(jqTemplates) : Collections.emptyMap();+ (NodeList)+ (xpathFactory.newXPath())+ .evaluate("/config/jq-templates/template", config, XPathConstants.NODESET);+ Map<String, MetricsQueryTemplate> jqTemplatesMap =+ (jqTemplates != null && jqTemplates.getLength() > 0)+ ? loadJqTemplates(jqTemplates)+ : Collections.emptyMap();Node pingConfig = getNode(config, "/config/rules/ping");Node metricsConfig = getNode(config, "/config/rules/metrics");@@ -120,12 +127,13 @@ public class MetricsConfiguration {Node searchConfiguration = getNode(config, "/config/rules/search");return new MetricsConfiguration(- settings == null ? PrometheusExporterSettings.builder().build() : PrometheusExporterSettings.from(settings),+ settings == null+ ? PrometheusExporterSettings.builder().build()+ : PrometheusExporterSettings.from(settings),toMetricQueries(pingConfig, jqTemplatesMap),toMetricQueries(metricsConfig, jqTemplatesMap),toMetricQueries(collectionsConfig, jqTemplatesMap),- toMetricQueries(searchConfiguration, jqTemplatesMap)- );+ toMetricQueries(searchConfiguration, jqTemplatesMap));}static final XPathFactory xpathFactory = XPathFactory.newInstance();@@ -133,11 +141,10 @@ public class MetricsConfiguration {private static Node getNode(Document doc, String path) {// Copied from solr-core XmlConfigFile.getNode with simplificationsXPath xpath = xpathFactory.newXPath();- String xstr = path; //normalize(path);+ String xstr = path; // normalize(path);try {- NodeList nodes = (NodeList) xpath.evaluate(xstr, doc,- XPathConstants.NODESET);+ NodeList nodes = (NodeList) xpath.evaluate(xstr, doc, XPathConstants.NODESET);if (nodes == null || 0 == nodes.getLength()) {return null;}@@ -150,7 +157,8 @@ public class MetricsConfiguration {}}- private static List<MetricsQuery> toMetricQueries(Node node, Map<String,MetricsQueryTemplate> jqTemplatesMap) throws JsonQueryException {+ private static List<MetricsQuery> toMetricQueries(+ Node node, Map<String, MetricsQueryTemplate> jqTemplatesMap) throws JsonQueryException {if (node == null) {return Collections.emptyList();}@@ -158,9 +166,9 @@ public class MetricsConfiguration {return MetricsQuery.from(node, jqTemplatesMap);}- static Map<String,MetricsQueryTemplate> loadJqTemplates(NodeList jqTemplates) {- Map<String,MetricsQueryTemplate> map = new HashMap<>();- for (int t=0; t < jqTemplates.getLength(); t++) {+ static Map<String, MetricsQueryTemplate> loadJqTemplates(NodeList jqTemplates) {+ Map<String, MetricsQueryTemplate> map = new HashMap<>();+ for (int t = 0; t < jqTemplates.getLength(); t++) {Node template = jqTemplates.item(t);if (template.getNodeType() == Node.ELEMENT_NODE && template.hasAttributes()) {Node nameAttr = template.getAttributes().getNamedItem("name");diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQuery.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQuery.javaindex 8de9693af97..5c3ba1f5303 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQuery.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQuery.java@@ -23,7 +23,6 @@ import java.util.List;import java.util.Map;import java.util.Optional;import java.util.regex.Matcher;-import net.thisptr.jackson.jq.JsonQuery;import net.thisptr.jackson.jq.exception.JsonQueryException;import org.apache.solr.client.solrj.request.QueryRequest;@@ -55,22 +54,12 @@ public class MetricsQuery {public MetricsQuery withCore(String core) {return new MetricsQuery(- getPath(),- getParameters(),- core,- getCollection().orElse(null),- getJsonQueries()- );+ getPath(), getParameters(), core, getCollection().orElse(null), getJsonQueries());}public MetricsQuery withCollection(String collection) {return new MetricsQuery(- getPath(),- getParameters(),- getCore().orElse(null),- collection,- getJsonQueries()- );+ getPath(), getParameters(), getCore().orElse(null), collection, getJsonQueries());}public String getPath() {@@ -89,7 +78,8 @@ public class MetricsQuery {return jsonQueries;}- public static List<MetricsQuery> from(Node node, Map<String,MetricsQueryTemplate> jqTemplates) throws JsonQueryException {+ public static List<MetricsQuery> from(Node node, Map<String, MetricsQueryTemplate> jqTemplates)+ throws JsonQueryException {List<MetricsQuery> metricsQueries = new ArrayList<>();NamedList<?> config = DOMUtil.childNodesToNamedList(node);@@ -137,7 +127,8 @@ public class MetricsQuery {String templateName = matcher.group("TEMPLATE");MetricsQueryTemplate template = jqTemplates.get(templateName);if (template == null) {- throw new IllegalStateException("jq template '" + matcher.group("TEMPLATE") + "' not found!");+ throw new IllegalStateException(+ "jq template '" + matcher.group("TEMPLATE") + "' not found!");}jsonQuery = template.applyTemplate(matcher);@@ -149,12 +140,7 @@ public class MetricsQuery {}}- metricsQueries.add(new MetricsQuery(- path,- params,- core,- collection,- compiledQueries));+ metricsQueries.add(new MetricsQuery(path, params, core, collection, compiledQueries));}return metricsQueries;diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQueryTemplate.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQueryTemplate.javaindex 0b89455b1b5..336dc2867ce 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQueryTemplate.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/MetricsQueryTemplate.java@@ -39,7 +39,8 @@ public class MetricsQueryTemplate {TYPE = COUNTER*/private static final Pattern matchJqTemplate =- Pattern.compile("^\\$jq:(?<TEMPLATE>.*?)\\(\\s?(?<UNIQUE>[^,]*),\\s?(?<KEYSELECTOR>[^,]*)(,\\s?(?<METRIC>[^,]*)\\s?)?(,\\s?(?<TYPE>[^,]*)\\s?)?\\)$");+ Pattern.compile(+ "^\\$jq:(?<TEMPLATE>.*?)\\(\\s?(?<UNIQUE>[^,]*),\\s?(?<KEYSELECTOR>[^,]*)(,\\s?(?<METRIC>[^,]*)\\s?)?(,\\s?(?<TYPE>[^,]*)\\s?)?\\)$");public static Optional<Matcher> matches(String jsonQuery) {Optional<Matcher> maybe = Optional.empty();@@ -103,7 +104,8 @@ public class MetricsQueryTemplate {metric = "$object.value." + metric;}} // else some kind of function, pass thru as-is- } // else there's a $ so just assume it is a fully qualified reference to the desired value, leave as-is+ } // else there's a $ so just assume it is a fully qualified reference to the desired value,+ // leave as-isreturn template.replace("{UNIQUE}", unique)@@ -117,9 +119,9 @@ public class MetricsQueryTemplate {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;MetricsQueryTemplate that = (MetricsQueryTemplate) o;- return name.equals(that.name) &&- Objects.equals(defaultType, that.defaultType) &&- template.equals(that.template);+ return name.equals(that.name)+ && Objects.equals(defaultType, that.defaultType)+ && template.equals(that.template);}@Overridediff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/PrometheusExporterSettings.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/PrometheusExporterSettings.javaindex 964dfe3565f..e6caea25f52 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/PrometheusExporterSettings.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/PrometheusExporterSettings.java@@ -18,9 +18,8 @@package org.apache.solr.prometheus.exporter;import java.util.List;--import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.DOMUtil;+import org.apache.solr.common.util.NamedList;import org.w3c.dom.Node;public class PrometheusExporterSettings {@@ -36,9 +35,7 @@ public class PrometheusExporterSettings {private int httpConnectionTimeout = 10000;private int httpReadTimeout = 60000;- private Builder() {-- }+ private Builder() {}public Builder withConnectionHttpTimeout(int httpConnectionTimeout) {this.httpConnectionTimeout = httpConnectionTimeout;@@ -53,7 +50,6 @@ public class PrometheusExporterSettings {public PrometheusExporterSettings build() {return new PrometheusExporterSettings(httpConnectionTimeout, httpReadTimeout);}-}public static PrometheusExporterSettings from(Node settings) {@@ -79,9 +75,7 @@ public class PrometheusExporterSettings {return builder.build();}- private PrometheusExporterSettings(- int httpConnectionTimeout,- int httpReadTimeout) {+ private PrometheusExporterSettings(int httpConnectionTimeout, int httpReadTimeout) {this.httpConnectionTimeout = httpConnectionTimeout;this.httpReadTimeout = httpReadTimeout;}@@ -93,5 +87,4 @@ public class PrometheusExporterSettings {public int getHttpReadTimeout() {return httpReadTimeout;}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.javaindex 102d649e34a..2c7d2c35530 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrClientFactory.java@@ -17,10 +17,8 @@package org.apache.solr.prometheus.exporter;-import java.util.Locale;import java.util.Optional;import java.util.stream.Collectors;-import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.impl.NoOpResponseParser;@@ -42,7 +40,8 @@ public class SolrClientFactory {standaloneBuilder.withBaseSolrUrl(solrHost);- standaloneBuilder.withConnectionTimeout(settings.getHttpConnectionTimeout())+ standaloneBuilder+ .withConnectionTimeout(settings.getHttpConnectionTimeout()).withSocketTimeout(settings.getHttpReadTimeout());HttpSolrClient httpSolrClient = standaloneBuilder.build();@@ -57,13 +56,15 @@ public class SolrClientFactory {ConnectStringParser parser = new ConnectStringParser(zookeeperConnectionString);- CloudSolrClient.Builder cloudBuilder = new CloudSolrClient.Builder(- parser.getServerAddresses().stream()- .map(address -> String.format(Locale.ROOT, "%s:%s", address.getHostString(), address.getPort()))- .collect(Collectors.toList()),- Optional.ofNullable(parser.getChrootPath()));+ CloudSolrClient.Builder cloudBuilder =+ new CloudSolrClient.Builder(+ parser.getServerAddresses().stream()+ .map(address -> address.getHostString() + ":" + address.getPort())+ .collect(Collectors.toList()),+ Optional.ofNullable(parser.getChrootPath()));- cloudBuilder.withConnectionTimeout(settings.getHttpConnectionTimeout())+ cloudBuilder+ .withConnectionTimeout(settings.getHttpConnectionTimeout()).withSocketTimeout(settings.getHttpReadTimeout());CloudSolrClient client = cloudBuilder.build();@@ -73,6 +74,4 @@ public class SolrClientFactory {return client;}--}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.javaindex 3a605801fde..eedddd1e6ed 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java@@ -16,26 +16,24 @@*/package org.apache.solr.prometheus.exporter;+import io.prometheus.client.CollectorRegistry;+import io.prometheus.client.exporter.HTTPServer;import java.io.IOException;import java.lang.invoke.MethodHandles;import java.net.InetSocketAddress;-import java.util.Locale;import java.util.concurrent.ExecutorService;--import io.prometheus.client.CollectorRegistry;-import io.prometheus.client.exporter.HTTPServer;import net.sourceforge.argparse4j.ArgumentParsers;import net.sourceforge.argparse4j.inf.ArgumentParser;import net.sourceforge.argparse4j.inf.ArgumentParserException;import net.sourceforge.argparse4j.inf.Namespace;import org.apache.solr.common.util.ExecutorUtil;import org.apache.solr.common.util.IOUtils;+import org.apache.solr.common.util.SolrNamedThreadFactory;import org.apache.solr.prometheus.collector.MetricsCollectorFactory;import org.apache.solr.prometheus.collector.SchedulerMetricsCollector;import org.apache.solr.prometheus.scraper.SolrCloudScraper;import org.apache.solr.prometheus.scraper.SolrScraper;import org.apache.solr.prometheus.scraper.SolrStandaloneScraper;-import org.apache.solr.common.util.SolrNamedThreadFactory;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -47,37 +45,47 @@ public class SolrExporter {private static final String ARG_PORT_METAVAR = "PORT";private static final String ARG_PORT_DEST = "port";private static final int ARG_PORT_DEFAULT = 8989;- private static final String ARG_PORT_HELP = "Specify the solr-exporter HTTP listen port; default is " + ARG_PORT_DEFAULT + ".";+ private static final String ARG_PORT_HELP =+ "Specify the solr-exporter HTTP listen port; default is " + ARG_PORT_DEFAULT + ".";private static final String[] ARG_BASE_URL_FLAGS = {"-b", "--baseurl"};private static final String ARG_BASE_URL_METAVAR = "BASE_URL";private static final String ARG_BASE_URL_DEST = "baseUrl";private static final String ARG_BASE_URL_DEFAULT = "http://localhost:8983/solr";- private static final String ARG_BASE_URL_HELP = "Specify the Solr base URL when connecting to Solr in standalone mode. If omitted both the -b parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'http://localhost:8983/solr'.";+ private static final String ARG_BASE_URL_HELP =+ "Specify the Solr base URL when connecting to Solr in standalone mode. If omitted both the -b parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'http://localhost:8983/solr'.";private static final String[] ARG_ZK_HOST_FLAGS = {"-z", "--zkhost"};private static final String ARG_ZK_HOST_METAVAR = "ZK_HOST";private static final String ARG_ZK_HOST_DEST = "zkHost";private static final String ARG_ZK_HOST_DEFAULT = "";- private static final String ARG_ZK_HOST_HELP = "Specify the ZooKeeper connection string when connecting to Solr in SolrCloud mode. If omitted both the -b parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'localhost:2181/solr'.";+ private static final String ARG_ZK_HOST_HELP =+ "Specify the ZooKeeper connection string when connecting to Solr in SolrCloud mode. If omitted both the -b parameter and the -z parameter, connect to http://localhost:8983/solr. For example 'localhost:2181/solr'.";private static final String[] ARG_CONFIG_FLAGS = {"-f", "--config-file"};private static final String ARG_CONFIG_METAVAR = "CONFIG";private static final String ARG_CONFIG_DEST = "configFile";private static final String ARG_CONFIG_DEFAULT = "solr-exporter-config.xml";- private static final String ARG_CONFIG_HELP = "Specify the configuration file; the default is " + ARG_CONFIG_DEFAULT + ".";+ private static final String ARG_CONFIG_HELP =+ "Specify the configuration file; the default is " + ARG_CONFIG_DEFAULT + ".";private static final String[] ARG_SCRAPE_INTERVAL_FLAGS = {"-s", "--scrape-interval"};private static final String ARG_SCRAPE_INTERVAL_METAVAR = "SCRAPE_INTERVAL";private static final String ARG_SCRAPE_INTERVAL_DEST = "scrapeInterval";private static final int ARG_SCRAPE_INTERVAL_DEFAULT = 60;- private static final String ARG_SCRAPE_INTERVAL_HELP = "Specify the delay between scraping Solr metrics; the default is " + ARG_SCRAPE_INTERVAL_DEFAULT + " seconds.";+ private static final String ARG_SCRAPE_INTERVAL_HELP =+ "Specify the delay between scraping Solr metrics; the default is "+ + ARG_SCRAPE_INTERVAL_DEFAULT+ + " seconds.";private static final String[] ARG_NUM_THREADS_FLAGS = {"-n", "--num-threads"};private static final String ARG_NUM_THREADS_METAVAR = "NUM_THREADS";private static final String ARG_NUM_THREADS_DEST = "numThreads";private static final Integer ARG_NUM_THREADS_DEFAULT = 1;- private static final String ARG_NUM_THREADS_HELP = "Specify the number of threads. solr-exporter creates a thread pools for request to Solr. If you need to improve request latency via solr-exporter, you can increase the number of threads; the default is " + ARG_NUM_THREADS_DEFAULT + ".";+ private static final String ARG_NUM_THREADS_HELP =+ "Specify the number of threads. solr-exporter creates a thread pools for request to Solr. If you need to improve request latency via solr-exporter, you can increase the number of threads; the default is "+ + ARG_NUM_THREADS_DEFAULT+ + ".";public static final CollectorRegistry defaultRegistry = new CollectorRegistry();@@ -99,16 +107,19 @@ public class SolrExporter {MetricsConfiguration metricsConfiguration) {this.port = port;- this.metricCollectorExecutor = ExecutorUtil.newMDCAwareFixedThreadPool(- numberThreads,- new SolrNamedThreadFactory("solr-exporter-collectors"));+ this.metricCollectorExecutor =+ ExecutorUtil.newMDCAwareFixedThreadPool(+ numberThreads, new SolrNamedThreadFactory("solr-exporter-collectors"));- this.requestExecutor = ExecutorUtil.newMDCAwareFixedThreadPool(- numberThreads,- new SolrNamedThreadFactory("solr-exporter-requests"));+ this.requestExecutor =+ ExecutorUtil.newMDCAwareFixedThreadPool(+ numberThreads, new SolrNamedThreadFactory("solr-exporter-requests"));this.solrScraper = createScraper(scrapeConfiguration, metricsConfiguration.getSettings());- this.metricsCollector = new MetricsCollectorFactory(metricCollectorExecutor, scrapeInterval, solrScraper, metricsConfiguration).create();+ this.metricsCollector =+ new MetricsCollectorFactory(+ metricCollectorExecutor, scrapeInterval, solrScraper, metricsConfiguration)+ .create();this.prometheusCollector = new CachedPrometheusCollector();}@@ -135,7 +146,8 @@ public class SolrExporter {defaultRegistry.unregister(this.prometheusCollector);}- private SolrScraper createScraper(SolrScrapeConfiguration configuration, PrometheusExporterSettings settings) {+ private SolrScraper createScraper(+ SolrScrapeConfiguration configuration, PrometheusExporterSettings settings) {SolrClientFactory factory = new SolrClientFactory(settings);switch (configuration.getType()) {@@ -144,39 +156,67 @@ public class SolrExporter {factory.createStandaloneSolrClient(configuration.getSolrHost().get()), requestExecutor);case CLOUD:return new SolrCloudScraper(- factory.createCloudSolrClient(configuration.getZookeeperConnectionString().get()), requestExecutor, factory);+ factory.createCloudSolrClient(configuration.getZookeeperConnectionString().get()),+ requestExecutor,+ factory);default:- throw new RuntimeException(String.format(Locale.ROOT, "Invalid type: %s", configuration.getType()));+ throw new RuntimeException("Invalid type: " + configuration.getType());}}public static void main(String[] args) {- ArgumentParser parser = ArgumentParsers.newFor(SolrExporter.class.getSimpleName()).build()- .description("Prometheus exporter for Apache Solr.");-- parser.addArgument(ARG_PORT_FLAGS)- .metavar(ARG_PORT_METAVAR).dest(ARG_PORT_DEST).type(Integer.class)- .setDefault(ARG_PORT_DEFAULT).help(ARG_PORT_HELP);-- parser.addArgument(ARG_BASE_URL_FLAGS)- .metavar(ARG_BASE_URL_METAVAR).dest(ARG_BASE_URL_DEST).type(String.class)- .setDefault(ARG_BASE_URL_DEFAULT).help(ARG_BASE_URL_HELP);-- parser.addArgument(ARG_ZK_HOST_FLAGS)- .metavar(ARG_ZK_HOST_METAVAR).dest(ARG_ZK_HOST_DEST).type(String.class)- .setDefault(ARG_ZK_HOST_DEFAULT).help(ARG_ZK_HOST_HELP);-- parser.addArgument(ARG_CONFIG_FLAGS)- .metavar(ARG_CONFIG_METAVAR).dest(ARG_CONFIG_DEST).type(String.class)- .setDefault(ARG_CONFIG_DEFAULT).help(ARG_CONFIG_HELP);-- parser.addArgument(ARG_SCRAPE_INTERVAL_FLAGS)- .metavar(ARG_SCRAPE_INTERVAL_METAVAR).dest(ARG_SCRAPE_INTERVAL_DEST).type(Integer.class)- .setDefault(ARG_SCRAPE_INTERVAL_DEFAULT).help(ARG_SCRAPE_INTERVAL_HELP);-- parser.addArgument(ARG_NUM_THREADS_FLAGS)- .metavar(ARG_NUM_THREADS_METAVAR).dest(ARG_NUM_THREADS_DEST).type(Integer.class)- .setDefault(ARG_NUM_THREADS_DEFAULT).help(ARG_NUM_THREADS_HELP);+ ArgumentParser parser =+ ArgumentParsers.newFor(SolrExporter.class.getSimpleName())+ .build()+ .description("Prometheus exporter for Apache Solr.");++ parser+ .addArgument(ARG_PORT_FLAGS)+ .metavar(ARG_PORT_METAVAR)+ .dest(ARG_PORT_DEST)+ .type(Integer.class)+ .setDefault(ARG_PORT_DEFAULT)+ .help(ARG_PORT_HELP);++ parser+ .addArgument(ARG_BASE_URL_FLAGS)+ .metavar(ARG_BASE_URL_METAVAR)+ .dest(ARG_BASE_URL_DEST)+ .type(String.class)+ .setDefault(ARG_BASE_URL_DEFAULT)+ .help(ARG_BASE_URL_HELP);++ parser+ .addArgument(ARG_ZK_HOST_FLAGS)+ .metavar(ARG_ZK_HOST_METAVAR)+ .dest(ARG_ZK_HOST_DEST)+ .type(String.class)+ .setDefault(ARG_ZK_HOST_DEFAULT)+ .help(ARG_ZK_HOST_HELP);++ parser+ .addArgument(ARG_CONFIG_FLAGS)+ .metavar(ARG_CONFIG_METAVAR)+ .dest(ARG_CONFIG_DEST)+ .type(String.class)+ .setDefault(ARG_CONFIG_DEFAULT)+ .help(ARG_CONFIG_HELP);++ parser+ .addArgument(ARG_SCRAPE_INTERVAL_FLAGS)+ .metavar(ARG_SCRAPE_INTERVAL_METAVAR)+ .dest(ARG_SCRAPE_INTERVAL_DEST)+ .type(Integer.class)+ .setDefault(ARG_SCRAPE_INTERVAL_DEFAULT)+ .help(ARG_SCRAPE_INTERVAL_HELP);++ parser+ .addArgument(ARG_NUM_THREADS_FLAGS)+ .metavar(ARG_NUM_THREADS_METAVAR)+ .dest(ARG_NUM_THREADS_DEST)+ .type(Integer.class)+ .setDefault(ARG_NUM_THREADS_DEFAULT)+ .help(ARG_NUM_THREADS_HELP);try {Namespace res = parser.parseArgs(args);@@ -194,16 +234,18 @@ public class SolrExporter {}int port = res.getInt(ARG_PORT_DEST);- SolrExporter solrExporter = new SolrExporter(- port,- res.getInt(ARG_NUM_THREADS_DEST),- res.getInt(ARG_SCRAPE_INTERVAL_DEST),- scrapeConfiguration,- loadMetricsConfiguration(res.getString(ARG_CONFIG_DEST)));+ SolrExporter solrExporter =+ new SolrExporter(+ port,+ res.getInt(ARG_NUM_THREADS_DEST),+ res.getInt(ARG_SCRAPE_INTERVAL_DEST),+ scrapeConfiguration,+ loadMetricsConfiguration(res.getString(ARG_CONFIG_DEST)));log.info("Starting Solr Prometheus Exporting on port {}", port);solrExporter.start();- log.info("Solr Prometheus Exporter is running. Collecting metrics for {}", scrapeConfiguration);+ log.info(+ "Solr Prometheus Exporter is running. Collecting metrics for {}", scrapeConfiguration);} catch (IOException e) {log.error("Failed to start Solr Prometheus Exporter: ", e);} catch (ArgumentParserException e) {@@ -219,5 +261,4 @@ public class SolrExporter {throw new RuntimeException(e);}}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrScrapeConfiguration.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrScrapeConfiguration.javaindex 0ac400d1b0b..a1e1fbdf27b 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrScrapeConfiguration.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrScrapeConfiguration.java@@ -30,7 +30,8 @@ public class SolrScrapeConfiguration {private final String zookeeperConnectionString;private final String solrHost;- private SolrScrapeConfiguration(ConnectionType type, String zookeeperConnectionString, String solrHost) {+ private SolrScrapeConfiguration(+ ConnectionType type, String zookeeperConnectionString, String solrHost) {this.type = type;this.zookeeperConnectionString = zookeeperConnectionString;this.solrHost = solrHost;@@ -66,5 +67,4 @@ public class SolrScrapeConfiguration {return "None";}}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/package-info.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/package-info.javaindex c2e68867e72..8c85dee8593 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/package-info.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/package-info.java@@ -15,7 +15,5 @@* limitations under the License.*/-/**- * Prometheus Metrics Exporter.- */+/** Prometheus Metrics Exporter. */package org.apache.solr.prometheus.exporter;diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrCloudScraper.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrCloudScraper.javaindex eedb2162ab7..188914fbc4e 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrCloudScraper.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrCloudScraper.java@@ -16,6 +16,8 @@*/package org.apache.solr.prometheus.scraper;+import com.github.benmanes.caffeine.cache.Cache;+import com.github.benmanes.caffeine.cache.Caffeine;import java.io.IOException;import java.util.List;import java.util.Map;@@ -23,9 +25,6 @@ import java.util.Set;import java.util.concurrent.ExecutorService;import java.util.function.Function;import java.util.stream.Collectors;--import com.github.benmanes.caffeine.cache.Cache;-import com.github.benmanes.caffeine.cache.Caffeine;import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.common.cloud.DocCollection;@@ -43,7 +42,8 @@ public class SolrCloudScraper extends SolrScraper {private Cache<String, HttpSolrClient> hostClientCache = Caffeine.newBuilder().build();- public SolrCloudScraper(CloudSolrClient solrClient, ExecutorService executor, SolrClientFactory solrClientFactory) {+ public SolrCloudScraper(+ CloudSolrClient solrClient, ExecutorService executor, SolrClientFactory solrClientFactory) {super(executor);this.solrClient = solrClient;this.solrClientFactory = solrClientFactory;@@ -53,31 +53,34 @@ public class SolrCloudScraper extends SolrScraper {public Map<String, MetricSamples> pingAllCores(MetricsQuery query) throws IOException {Map<String, HttpSolrClient> httpSolrClients = createHttpSolrClients();- Map<String, DocCollection> collectionState = solrClient.getClusterStateProvider().getClusterState().getCollectionsMap();-- List<Replica> replicas = collectionState.values()- .stream()- .map(DocCollection::getReplicas)- .flatMap(List::stream)- .collect(Collectors.toList());-- List<String> coreNames = replicas- .stream()- .map(Replica::getCoreName)- .collect(Collectors.toList());-- Map<String, HttpSolrClient> coreToClient = replicas- .stream()- .map(replica -> new Pair<>(replica.getCoreName(), httpSolrClients.get(replica.getBaseUrl())))- .collect(Collectors.toMap(Pair::first, Pair::second));-- return sendRequestsInParallel(coreNames, core -> {- try {- return request(coreToClient.get(core), query.withCore(core));- } catch (IOException exception) {- throw new RuntimeException(exception);- }- });+ Map<String, DocCollection> collectionState =+ solrClient.getClusterStateProvider().getClusterState().getCollectionsMap();++ List<Replica> replicas =+ collectionState.values().stream()+ .map(DocCollection::getReplicas)+ .flatMap(List::stream)+ .collect(Collectors.toList());++ List<String> coreNames =+ replicas.stream().map(Replica::getCoreName).collect(Collectors.toList());++ Map<String, HttpSolrClient> coreToClient =+ replicas.stream()+ .map(+ replica ->+ new Pair<>(replica.getCoreName(), httpSolrClients.get(replica.getBaseUrl())))+ .collect(Collectors.toMap(Pair::first, Pair::second));++ return sendRequestsInParallel(+ coreNames,+ core -> {+ try {+ return request(coreToClient.get(core), query.withCore(core));+ } catch (IOException exception) {+ throw new RuntimeException(exception);+ }+ });}private Map<String, HttpSolrClient> createHttpSolrClients() throws IOException {@@ -88,26 +91,30 @@ public class SolrCloudScraper extends SolrScraper {@Overridepublic Map<String, MetricSamples> pingAllCollections(MetricsQuery query) throws IOException {- return sendRequestsInParallel(getCollections(), (collection) -> {- try {- return request(solrClient, query.withCollection(collection));- } catch (IOException exception) {- throw new RuntimeException(exception);- }- });+ return sendRequestsInParallel(+ getCollections(),+ (collection) -> {+ try {+ return request(solrClient, query.withCollection(collection));+ } catch (IOException exception) {+ throw new RuntimeException(exception);+ }+ });}@Overridepublic Map<String, MetricSamples> metricsForAllHosts(MetricsQuery query) throws IOException {Map<String, HttpSolrClient> httpSolrClients = createHttpSolrClients();- return sendRequestsInParallel(httpSolrClients.keySet(), (baseUrl) -> {- try {- return request(httpSolrClients.get(baseUrl), query);- } catch (IOException exception) {- throw new RuntimeException(exception);- }- });+ return sendRequestsInParallel(+ httpSolrClients.keySet(),+ (baseUrl) -> {+ try {+ return request(httpSolrClients.get(baseUrl), query);+ } catch (IOException exception) {+ throw new RuntimeException(exception);+ }+ });}@Override@@ -121,7 +128,11 @@ public class SolrCloudScraper extends SolrScraper {}private Set<String> getBaseUrls() throws IOException {- return solrClient.getClusterStateProvider().getClusterState().getCollectionsMap().values()+ return solrClient+ .getClusterStateProvider()+ .getClusterState()+ .getCollectionsMap()+ .values().stream().map(DocCollection::getReplicas).flatMap(List::stream)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.javaindex c1ee6aacb38..2b86efbebfd 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@@ -16,6 +16,10 @@*/package org.apache.solr.prometheus.scraper;+import com.fasterxml.jackson.databind.JsonNode;+import com.fasterxml.jackson.databind.ObjectMapper;+import io.prometheus.client.Collector;+import io.prometheus.client.Counter;import java.io.Closeable;import java.io.IOException;import java.lang.invoke.MethodHandles;@@ -28,11 +32,6 @@ import java.util.concurrent.Callable;import java.util.concurrent.ExecutorService;import java.util.function.Function;import java.util.stream.Collectors;--import com.fasterxml.jackson.databind.JsonNode;-import com.fasterxml.jackson.databind.ObjectMapper;-import io.prometheus.client.Collector;-import io.prometheus.client.Counter;import net.thisptr.jackson.jq.JsonQuery;import net.thisptr.jackson.jq.exception.JsonQueryException;import org.apache.solr.client.solrj.SolrClient;@@ -49,22 +48,27 @@ import org.slf4j.LoggerFactory;public abstract class SolrScraper implements Closeable {- private static final Counter scrapeErrorTotal = Counter.build()- .name("solr_exporter_scrape_error_total")- .help("Number of scrape error.")- .register(SolrExporter.defaultRegistry);+ private static final Counter scrapeErrorTotal =+ Counter.build()+ .name("solr_exporter_scrape_error_total")+ .help("Number of scrape error.")+ .register(SolrExporter.defaultRegistry);protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());protected final ExecutorService executor;- public abstract Map<String, MetricSamples> metricsForAllHosts(MetricsQuery query) throws IOException;+ public abstract Map<String, MetricSamples> metricsForAllHosts(MetricsQuery query)+ throws IOException;public abstract Map<String, MetricSamples> pingAllCores(MetricsQuery query) throws IOException;- public abstract Map<String, MetricSamples> pingAllCollections(MetricsQuery query) throws IOException;++ public abstract Map<String, MetricSamples> pingAllCollections(MetricsQuery query)+ throws IOException;public abstract MetricSamples search(MetricsQuery query) throws IOException;+public abstract MetricSamples collections(MetricsQuery metricsQuery) throws IOException;public SolrScraper(ExecutorService executor) {@@ -72,29 +76,32 @@ public abstract class SolrScraper implements Closeable {}protected Map<String, MetricSamples> sendRequestsInParallel(- Collection<String> items,- Function<String, MetricSamples> samplesCallable) throws IOException {+ Collection<String> items, Function<String, MetricSamples> samplesCallable)+ throws IOException {Map<String, MetricSamples> result = new HashMap<>(); // sync on this when adding to it belowtry {- // invoke each samplesCallable with each item and putting the results in the above "result" map.+ // invoke each samplesCallable with each item and putting the results in the above "result"+ // map.executor.invokeAll(items.stream()- .map(item -> (Callable<MetricSamples>) () -> {- try {- final MetricSamples samples = samplesCallable.apply(item);- synchronized (result) {- result.put(item, samples);- }- } catch (Exception e) {- // do NOT totally fail; just log and move on- log.warn("Error occurred during metrics collection", e);- }- return null;//not used- })- .collect(Collectors.toList())- );+ .map(+ item ->+ (Callable<MetricSamples>)+ () -> {+ try {+ final MetricSamples samples = samplesCallable.apply(item);+ synchronized (result) {+ result.put(item, samples);+ }+ } catch (Exception e) {+ // do NOT totally fail; just log and move on+ log.warn("Error occurred during metrics collection", e);+ }+ return null; // not used+ })+ .collect(Collectors.toList()));} catch (InterruptedException e) {Thread.currentThread().interrupt();throw new RuntimeException(e);@@ -157,7 +164,10 @@ public abstract class SolrScraper implements Closeable {}// Deduce core if not there- if (labelNames.indexOf("core") < 0 && labelNames.indexOf("collection") >= 0 && labelNames.indexOf("shard") >= 0 && labelNames.indexOf("replica") >= 0) {+ if (labelNames.indexOf("core") < 0+ && labelNames.indexOf("collection") >= 0+ && labelNames.indexOf("shard") >= 0+ && labelNames.indexOf("replica") >= 0) {labelNames.add("core");String collection = labelValues.get(labelNames.indexOf("collection"));@@ -167,14 +177,13 @@ public abstract class SolrScraper implements Closeable {labelValues.add(collection + "_" + shard + "_" + replica);}- samples.addSamplesIfNotPresent(name, new Collector.MetricFamilySamples(+ samples.addSamplesIfNotPresent(name,- Collector.Type.valueOf(type),- help,- new ArrayList<>()));+ new Collector.MetricFamilySamples(+ name, Collector.Type.valueOf(type), help, new ArrayList<>()));- samples.addSampleIfMetricExists(name, new Collector.MetricFamilySamples.Sample(- name, labelNames, labelValues, value));+ samples.addSampleIfMetricExists(+ name, new Collector.MetricFamilySamples.Sample(name, labelNames, labelValues, value));}} catch (JsonQueryException e) {log.error("Error apply JSON query={} to result", jsonQuery, e);@@ -184,5 +193,4 @@ public abstract class SolrScraper implements Closeable {return samples;}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrStandaloneScraper.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrStandaloneScraper.javaindex 4bd8370cf5b..7c87407a59a 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrStandaloneScraper.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrStandaloneScraper.java@@ -16,6 +16,7 @@*/package org.apache.solr.prometheus.scraper;+import com.fasterxml.jackson.databind.JsonNode;import java.io.IOException;import java.util.Collections;import java.util.HashMap;@@ -23,8 +24,6 @@ import java.util.HashSet;import java.util.Map;import java.util.Set;import java.util.concurrent.ExecutorService;--import com.fasterxml.jackson.databind.JsonNode;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.request.CoreAdminRequest;@@ -45,13 +44,15 @@ public class SolrStandaloneScraper extends SolrScraper {@Overridepublic Map<String, MetricSamples> pingAllCores(MetricsQuery query) throws IOException {- return sendRequestsInParallel(getCores(), core -> {- try {- return request(solrClient, query.withCore(core));- } catch (IOException e) {- throw new RuntimeException(e);- }- });+ return sendRequestsInParallel(+ getCores(),+ core -> {+ try {+ return request(solrClient, query.withCore(core));+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ });}@Override@@ -90,7 +91,8 @@ public class SolrStandaloneScraper extends SolrScraper {throw new IOException("Failed to get cores", e);}- JsonNode statusJsonNode = OBJECT_MAPPER.readTree((String) coreAdminResponse.get("response")).get("status");+ JsonNode statusJsonNode =+ OBJECT_MAPPER.readTree((String) coreAdminResponse.get("response")).get("status");for (JsonNode jsonNode : statusJsonNode) {cores.add(jsonNode.get("name").textValue());@@ -103,5 +105,4 @@ public class SolrStandaloneScraper extends SolrScraper {public void close() {IOUtils.closeQuietly(solrClient);}-}diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/package-info.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/package-info.javaindex a1e0366c3fc..22683e3f3e7 100644--- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/package-info.java+++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/package-info.java@@ -15,7 +15,5 @@* limitations under the License.*/-/**- * Send the raw requests to Solr endpoints.- */+/** Send the raw requests to Solr endpoints. */package org.apache.solr.prometheus.scraper;diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.javaindex 933312504b5..5bfbca12736 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.java@@ -18,7 +18,6 @@package org.apache.solr.prometheus;import java.util.Map;-import org.apache.solr.client.solrj.request.CollectionAdminRequest;import org.apache.solr.cloud.AbstractDistribZkTestBase;import org.apache.solr.cloud.SolrCloudTestCase;@@ -35,17 +34,18 @@ public class PrometheusExporterTestBase extends SolrCloudTestCase {public static final int NUM_NODES = NUM_SHARDS * NUM_REPLICAS;public static final int TIMEOUT = 60;- public static final Map<String, Double> FACET_VALUES = Map.of(- "electronics", 14.0,- "currency", 4.0,- "memory", 3.0,- "and", 2.0,- "card", 2.0,- "connector", 2.0,- "drive", 2.0,- "graphics", 2.0,- "hard", 2.0,- "search", 2.0);+ public static final Map<String, Double> FACET_VALUES =+ Map.of(+ "electronics", 14.0,+ "currency", 4.0,+ "memory", 3.0,+ "and", 2.0,+ "card", 2.0,+ "connector", 2.0,+ "drive", 2.0,+ "graphics", 2.0,+ "hard", 2.0,+ "search", 2.0);@Overridepublic void setUp() throws Exception {@@ -60,19 +60,14 @@ public class PrometheusExporterTestBase extends SolrCloudTestCase {@BeforeClasspublic static void setupCluster() throws Exception {System.setProperty("metricsEnabled", "true");- configureCluster(NUM_NODES)- .addConfig(CONF_NAME, getFile(CONF_DIR).toPath())- .configure();+ configureCluster(NUM_NODES).addConfig(CONF_NAME, getFile(CONF_DIR).toPath()).configure();- CollectionAdminRequest- .createCollection(COLLECTION, CONF_NAME, NUM_SHARDS, NUM_REPLICAS)+ CollectionAdminRequest.createCollection(COLLECTION, CONF_NAME, NUM_SHARDS, NUM_REPLICAS).process(cluster.getSolrClient());- AbstractDistribZkTestBase- .waitForRecoveriesToFinish(COLLECTION, cluster.getSolrClient().getZkStateReader(), true, true, TIMEOUT);+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(+ COLLECTION, cluster.getSolrClient().getZkStateReader(), true, true, TIMEOUT);Helpers.indexAllDocs(cluster.getSolrClient());}--}diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/collector/MetricSamplesTest.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/collector/MetricSamplesTest.javaindex e33e75de9ae..7e9254780c0 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/collector/MetricSamplesTest.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/collector/MetricSamplesTest.java@@ -17,33 +17,29 @@package org.apache.solr.prometheus.collector;+import static org.junit.Assert.assertEquals;++import io.prometheus.client.Collector;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.HashMap;import java.util.List;-import java.util.Locale;import java.util.Map;import java.util.stream.Collectors;--import io.prometheus.client.Collector;import org.junit.Test;-import static org.junit.Assert.assertEquals;-public class MetricSamplesTest {private Collector.MetricFamilySamples.Sample sample(String name, Double value) {- return new Collector.MetricFamilySamples.Sample(name, Collections.emptyList(), Collections.emptyList(), value);+ return new Collector.MetricFamilySamples.Sample(+ name, Collections.emptyList(), Collections.emptyList(), value);}- private Collector.MetricFamilySamples samples(String metricName, Collector.Type type, Collector.MetricFamilySamples.Sample...samples) {+ private Collector.MetricFamilySamples samples(+ String metricName, Collector.Type type, Collector.MetricFamilySamples.Sample... samples) {return new Collector.MetricFamilySamples(- metricName,- type,- "help",- new ArrayList<>(Arrays.asList(samples))- );+ metricName, type, "help", new ArrayList<>(Arrays.asList(samples)));}private void validateMetricSamples(@@ -51,20 +47,25 @@ public class MetricSamplesTest {String metricName,List<Double> expectedValues) {- Collector.MetricFamilySamples test1 = allMetrics.stream()- .filter(s -> s.name.equals(metricName))- .findFirst()- .orElseThrow(() -> new RuntimeException(String.format(Locale.ROOT, "Unable to find item %s", metricName)));+ Collector.MetricFamilySamples test1 =+ allMetrics.stream()+ .filter(s -> s.name.equals(metricName))+ .findFirst()+ .orElseThrow(() -> new RuntimeException("Unable to find item " + metricName));- assertEquals(expectedValues, test1.samples.stream().map(s -> s.value).collect(Collectors.toList()));+ assertEquals(+ expectedValues, test1.samples.stream().map(s -> s.value).collect(Collectors.toList()));}@Testpublic void asList() {- MetricSamples samples = new MetricSamples(Map.of(- "test1", samples("test1", Collector.Type.GAUGE, sample("test1", 1.0), sample("test1", 2.0)),- "test2", samples("test2", Collector.Type.GAUGE, sample("test2", 1.0))- ));+ MetricSamples samples =+ new MetricSamples(+ Map.of(+ "test1",+ samples(+ "test1", Collector.Type.GAUGE, sample("test1", 1.0), sample("test1", 2.0)),+ "test2", samples("test2", Collector.Type.GAUGE, sample("test2", 1.0))));List<Collector.MetricFamilySamples> output = samples.asList();@@ -76,15 +77,22 @@ public class MetricSamplesTest {@Testpublic void addAll() {- MetricSamples lhs = new MetricSamples(new HashMap<>(Map.of(- "same", samples("same", Collector.Type.GAUGE, sample("same", 1.0), sample("same", 2.0)),- "diff1", samples("diff1", Collector.Type.GAUGE, sample("diff1", 1.0))- )));-- MetricSamples rhs = new MetricSamples(Map.of(- "same", samples("test1", Collector.Type.GAUGE, sample("test1", 3.0), sample("test1", 4.0)),- "diff2", samples("diff2", Collector.Type.GAUGE, sample("diff2", 1.0))- ));+ MetricSamples lhs =+ new MetricSamples(+ new HashMap<>(+ Map.of(+ "same",+ samples(+ "same", Collector.Type.GAUGE, sample("same", 1.0), sample("same", 2.0)),+ "diff1", samples("diff1", Collector.Type.GAUGE, sample("diff1", 1.0)))));++ MetricSamples rhs =+ new MetricSamples(+ Map.of(+ "same",+ samples(+ "test1", Collector.Type.GAUGE, sample("test1", 3.0), sample("test1", 4.0)),+ "diff2", samples("diff2", Collector.Type.GAUGE, sample("diff2", 1.0))));lhs.addAll(rhs);List<Collector.MetricFamilySamples> output = lhs.asList();@@ -93,5 +101,4 @@ public class MetricSamplesTest {validateMetricSamples(output, "diff1", Collections.singletonList(1.0));validateMetricSamples(output, "diff2", Collections.singletonList(1.0));}--}\ No newline at end of file+}diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.javaindex 515871569e2..c315a81b1fa 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.java@@ -17,14 +17,18 @@package org.apache.solr.prometheus.exporter;-import javax.xml.parsers.DocumentBuilderFactory;-import javax.xml.xpath.XPathConstants;-import java.util.List;-import java.util.Optional;-import java.util.regex.Matcher;+import static org.apache.solr.prometheus.exporter.MetricsConfiguration.xpathFactory;+import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertNotNull;+import static org.junit.Assert.assertTrue;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;+import java.util.List;+import java.util.Optional;+import java.util.regex.Matcher;+import javax.xml.parsers.DocumentBuilderFactory;+import javax.xml.xpath.XPathConstants;import net.thisptr.jackson.jq.JsonQuery;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.prometheus.utils.Helpers;@@ -32,11 +36,6 @@ import org.junit.Test;import org.w3c.dom.Document;import org.w3c.dom.NodeList;-import static org.apache.solr.prometheus.exporter.MetricsConfiguration.xpathFactory;-import static org.junit.Assert.assertEquals;-import static org.junit.Assert.assertNotNull;-import static org.junit.Assert.assertTrue;-public class MetricsQueryTemplateTest {@Testpublic void testTemplatesApplyDuringInit() throws Exception {@@ -45,7 +44,8 @@ public class MetricsQueryTemplateTest {List<JsonQuery> jsonQueries = metrics.get(0).getJsonQueries();final int expectedJqQueriesInConfig = 6;assertEquals(expectedJqQueriesInConfig, jsonQueries.size());- // JsonQuery does not implement an equals so use the string expression with whitespace collapsed to a single space+ // JsonQuery does not implement an equals so use the string expression with whitespace collapsed+ // to a single spacefor (int q = 0; q < jsonQueries.size(); q += 2) {String expected = jsonQueries.get(q + 1).toString().replaceAll("\\s+", " ").trim();String actual = jsonQueries.get(q).toString().replaceAll("\\s+", " ").trim();@@ -55,18 +55,20 @@ public class MetricsQueryTemplateTest {@Testpublic void testTemplateRegexMatchAndApply() {- final String[] matches = new String[]{- "$jq:jvm-item(memory_bytes,select(.key | startswith(\"memory.total.\")),object.value,\n\nGAUGE)",- "$jq:node( client_errors_total, select(.key | endswith(\".clientErrors\")), count )",- "$jq:node(time_seconds_total,\nselect(.key == \"UPDATE.updateHandler.autoCommits\"), ($object.value / 1000)) ",- "$jq:core-query( 1minRate, select(.key | endswith(\".distrib.requestTimes\")) )"- };- final String[] expectedApply = new String[]{- "memory_bytes, select(.key | startswith(\"memory.total.\")), $object.value, GAUGE",- "client_errors_total, select(.key | endswith(\".clientErrors\")), $object.value.count, COUNTER",- "time_seconds_total, select(.key == \"UPDATE.updateHandler.autoCommits\"), ($object.value / 1000), COUNTER",- "1minRate, select(.key | endswith(\".distrib.requestTimes\")), $object.value[\"1minRate\"], COUNTER"- };+ final String[] matches =+ new String[] {+ "$jq:jvm-item(memory_bytes,select(.key | startswith(\"memory.total.\")),object.value,\n\nGAUGE)",+ "$jq:node( client_errors_total, select(.key | endswith(\".clientErrors\")), count )",+ "$jq:node(time_seconds_total,\nselect(.key == \"UPDATE.updateHandler.autoCommits\"), ($object.value / 1000)) ",+ "$jq:core-query( 1minRate, select(.key | endswith(\".distrib.requestTimes\")) )"+ };+ final String[] expectedApply =+ new String[] {+ "memory_bytes, select(.key | startswith(\"memory.total.\")), $object.value, GAUGE",+ "client_errors_total, select(.key | endswith(\".clientErrors\")), $object.value.count, COUNTER",+ "time_seconds_total, select(.key == \"UPDATE.updateHandler.autoCommits\"), ($object.value / 1000), COUNTER",+ "1minRate, select(.key | endswith(\".distrib.requestTimes\")), $object.value[\"1minRate\"], COUNTER"+ };MetricsQueryTemplate template =new MetricsQueryTemplate("test", "{UNIQUE}, {KEYSELECTOR}, {METRIC}, {TYPE}", "COUNTER");@@ -82,35 +84,42 @@ public class MetricsQueryTemplateTest {@Testpublic void testQueryMetricTemplate() throws Exception {Document config =- DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(SolrTestCaseJ4.getFile("conf/test-config-with-templates.xml"));+ DocumentBuilderFactory.newInstance()+ .newDocumentBuilder()+ .parse(SolrTestCaseJ4.getFile("conf/test-config-with-templates.xml"));NodeList jqTemplates =- (NodeList) (xpathFactory.newXPath()).evaluate("/config/jq-templates/template", config, XPathConstants.NODESET);+ (NodeList)+ (xpathFactory.newXPath())+ .evaluate("/config/jq-templates/template", config, XPathConstants.NODESET);assertNotNull(jqTemplates);assertTrue(jqTemplates.getLength() > 0);- MetricsQueryTemplate coreQueryTemplate = MetricsConfiguration.loadJqTemplates(jqTemplates).get("core-query");+ MetricsQueryTemplate coreQueryTemplate =+ MetricsConfiguration.loadJqTemplates(jqTemplates).get("core-query");assertNotNull(coreQueryTemplate);ObjectMapper objectMapper = new ObjectMapper();JsonNode parsedMetrics = objectMapper.readTree(SolrTestCaseJ4.getFile("query-metrics.json"));- final String[] queryMetrics = new String[]{- "$jq:core-query(1minRate, select(.key | endswith(\".distrib.requestTimes\")), 1minRate)",- "$jq:core-query(p75_ms, select(.key | endswith(\".distrib.requestTimes\")), p75_ms)",- "$jq:core-query(mean_rate, select(.key | endswith(\".distrib.requestTimes\")), meanRate)",- "$jq:core-query(local_5minRate, select(.key | endswith(\".local.requestTimes\")), 5minRate)",- "$jq:core-query(local_median_ms, select(.key | endswith(\".local.requestTimes\")), median_ms)",- "$jq:core-query(local_p95_ms, select(.key | endswith(\".local.requestTimes\")), p95_ms)",- "$jq:core-query(local_count, select(.key | endswith(\".local.requestTimes\")), count, COUNTER)"- };+ final String[] queryMetrics =+ new String[] {+ "$jq:core-query(1minRate, select(.key | endswith(\".distrib.requestTimes\")), 1minRate)",+ "$jq:core-query(p75_ms, select(.key | endswith(\".distrib.requestTimes\")), p75_ms)",+ "$jq:core-query(mean_rate, select(.key | endswith(\".distrib.requestTimes\")), meanRate)",+ "$jq:core-query(local_5minRate, select(.key | endswith(\".local.requestTimes\")), 5minRate)",+ "$jq:core-query(local_median_ms, select(.key | endswith(\".local.requestTimes\")), median_ms)",+ "$jq:core-query(local_p95_ms, select(.key | endswith(\".local.requestTimes\")), p95_ms)",+ "$jq:core-query(local_count, select(.key | endswith(\".local.requestTimes\")), count, COUNTER)"+ };- final double[] expectedMetrics = new double[]{- 5.156897804421665,- 1.31788,- 0.0031956674240800156,- 0.030666407244305586,- 0.079579,- 0.105268,- 4712- };+ final double[] expectedMetrics =+ new double[] {+ 5.156897804421665,+ 1.31788,+ 0.0031956674240800156,+ 0.030666407244305586,+ 0.079579,+ 0.105268,+ 4712+ };for (int m = 0; m < queryMetrics.length; m++) {Optional<Matcher> maybe = MetricsQueryTemplate.matches(queryMetrics[m]);diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterIntegrationTest.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterIntegrationTest.javaindex fa65ec0dfdd..11c9e1687d2 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterIntegrationTest.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterIntegrationTest.java@@ -18,12 +18,11 @@ package org.apache.solr.prometheus.exporter;import java.util.Map;import java.util.stream.Collectors;-import org.apache.lucene.util.LuceneTestCase.Slow;import org.junit.Before;import org.junit.Test;-//@org.apache.lucene.util.LuceneTestCase.AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-13786")+// @org.apache.lucene.util.LuceneTestCase.AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-13786")@Slowpublic class SolrExporterIntegrationTest extends SolrExporterTestBase {@@ -31,12 +30,13 @@ public class SolrExporterIntegrationTest extends SolrExporterTestBase {@Beforepublic void setUp() throws Exception {super.setUp();- startMetricsExporterWithConfiguration("conf/prometheus-solr-exporter-integration-test-config.xml");+ startMetricsExporterWithConfiguration(+ "conf/prometheus-solr-exporter-integration-test-config.xml");}- private Map<String, Double> metricsWithName(Map<String, Double> allMetrics, String desiredMetricName) {- return allMetrics.entrySet()- .stream()+ private Map<String, Double> metricsWithName(+ Map<String, Double> allMetrics, String desiredMetricName) {+ return allMetrics.entrySet().stream().filter(entry -> entry.getKey().startsWith(desiredMetricName)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));}@@ -54,7 +54,8 @@ public class SolrExporterIntegrationTest extends SolrExporterTestBase {@Testpublic void solrExporterDurationMetric() throws Exception {- Map<String, Double> durationHistogram = metricsWithName(getAllMetrics(), "solr_exporter_duration");+ Map<String, Double> durationHistogram =+ metricsWithName(getAllMetrics(), "solr_exporter_duration");assertTrue(durationHistogram.get("solr_exporter_duration_seconds_count") > 0);assertTrue(durationHistogram.get("solr_exporter_duration_seconds_sum") > 0);@@ -65,13 +66,12 @@ public class SolrExporterIntegrationTest extends SolrExporterTestBase {@Testpublic void jvmMetrics() throws Exception {- Map<String, Double> jvmMetrics = metricsWithName(- getAllMetrics(), "solr_metrics_jvm_threads");+ Map<String, Double> jvmMetrics = metricsWithName(getAllMetrics(), "solr_metrics_jvm_threads");// exact set of metrics can vary based on JVM impl (ie: windows)// but there should always be at least one per known thread state per node...- assertTrue(jvmMetrics.toString(),- (NUM_NODES * Thread.State.values().length) < jvmMetrics.size());+ assertTrue(+ jvmMetrics.toString(), (NUM_NODES * Thread.State.values().length) < jvmMetrics.size());}@Test@@ -83,21 +83,22 @@ public class SolrExporterIntegrationTest extends SolrExporterTestBase {@Testpublic void collectionMetrics() throws Exception {Map<String, Double> allMetrics = getAllMetrics();- Map<String, Double> liveNodeMetrics = metricsWithName(allMetrics, "solr_collections_live_nodes");+ Map<String, Double> liveNodeMetrics =+ metricsWithName(allMetrics, "solr_collections_live_nodes");assertEquals(1, liveNodeMetrics.size());- liveNodeMetrics.forEach((metric, value) -> {- assertEquals((double) NUM_NODES, value, 0.001);- });+ liveNodeMetrics.forEach(+ (metric, value) -> {+ assertEquals((double) NUM_NODES, value, 0.001);+ });- Map<String, Double> shardLeaderMetrics = metricsWithName(allMetrics, "solr_collections_shard_leader");+ Map<String, Double> shardLeaderMetrics =+ metricsWithName(allMetrics, "solr_collections_shard_leader");assertEquals(NUM_NODES, shardLeaderMetrics.size());- double totalLeaderCount = shardLeaderMetrics.values()- .stream()- .mapToDouble(Double::doubleValue)- .sum();+ double totalLeaderCount =+ shardLeaderMetrics.values().stream().mapToDouble(Double::doubleValue).sum();assertEquals(NUM_SHARDS, totalLeaderCount, 0.001);}diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterTestBase.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterTestBase.javaindex aac2840e305..0e648fe37f6 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterTestBase.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/SolrExporterTestBase.java@@ -16,6 +16,7 @@*/package org.apache.solr.prometheus.exporter;+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;@@ -25,8 +26,6 @@ import java.net.URISyntaxException;import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.Map;--import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;import org.apache.commons.io.IOUtils;import org.apache.http.HttpStatus;import org.apache.http.client.methods.CloseableHttpResponse;@@ -38,9 +37,7 @@ import org.apache.solr.prometheus.PrometheusExporterTestBase;import org.apache.solr.prometheus.utils.Helpers;import org.junit.After;-/**- * Test base class.- */+/** Test base class. */@ThreadLeakScope(ThreadLeakScope.Scope.NONE)public class SolrExporterTestBase extends PrometheusExporterTestBase {@@ -58,17 +55,19 @@ public class SolrExporterTestBase extends PrometheusExporterTestBase {super.tearDown();}- protected void startMetricsExporterWithConfiguration(String scrapeConfiguration) throws Exception {+ protected void startMetricsExporterWithConfiguration(String scrapeConfiguration)+ throws Exception {try (ServerSocket socket = new ServerSocket(0)) {promtheusExporterPort = socket.getLocalPort();}- solrExporter = new SolrExporter(- promtheusExporterPort,- 25,- 10,- SolrScrapeConfiguration.solrCloud(cluster.getZkServer().getZkAddress()),- Helpers.loadConfiguration(scrapeConfiguration));+ solrExporter =+ new SolrExporter(+ promtheusExporterPort,+ 25,+ 10,+ SolrScrapeConfiguration.solrCloud(cluster.getZkServer().getZkAddress()),+ Helpers.loadConfiguration(scrapeConfiguration));solrExporter.start();httpClient = HttpClients.createDefault();@@ -97,7 +96,9 @@ public class SolrExporterTestBase extends PrometheusExporterTestBase {try (CloseableHttpResponse response = httpClient.execute(request)) {assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());- try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8))) {+ try (BufferedReader reader =+ new BufferedReader(+ new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8))) {String currentLine;while ((currentLine = reader.readLine()) != null) {@@ -115,5 +116,4 @@ public class SolrExporterTestBase extends PrometheusExporterTestBase {return metrics;}-}diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrCloudScraperTest.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrCloudScraperTest.javaindex 68618eb58a7..abeaf99c16a 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrCloudScraperTest.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrCloudScraperTest.java@@ -18,6 +18,7 @@package org.apache.solr.prometheus.scraper;import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;+import io.prometheus.client.Collector;import java.util.Arrays;import java.util.Collection;import java.util.Collections;@@ -27,8 +28,6 @@ import java.util.Optional;import java.util.Set;import java.util.concurrent.ExecutorService;import java.util.stream.Collectors;--import io.prometheus.client.Collector;import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.impl.NoOpResponseParser;import org.apache.solr.common.cloud.ClusterState;@@ -37,13 +36,13 @@ import org.apache.solr.common.cloud.Replica;import org.apache.solr.common.cloud.Slice;import org.apache.solr.common.util.ExecutorUtil;import org.apache.solr.common.util.IOUtils;+import org.apache.solr.common.util.SolrNamedThreadFactory;import org.apache.solr.prometheus.PrometheusExporterTestBase;import org.apache.solr.prometheus.collector.MetricSamples;import org.apache.solr.prometheus.exporter.MetricsConfiguration;import org.apache.solr.prometheus.exporter.PrometheusExporterSettings;import org.apache.solr.prometheus.exporter.SolrClientFactory;import org.apache.solr.prometheus.utils.Helpers;-import org.apache.solr.common.util.SolrNamedThreadFactory;import org.junit.After;import org.junit.Before;import org.junit.Test;@@ -56,9 +55,10 @@ public class SolrCloudScraperTest extends PrometheusExporterTestBase {private ExecutorService executor;private SolrCloudScraper createSolrCloudScraper() {- CloudSolrClient solrClient = new CloudSolrClient.Builder(- Collections.singletonList(cluster.getZkServer().getZkAddress()), Optional.empty())- .build();+ CloudSolrClient solrClient =+ new CloudSolrClient.Builder(+ Collections.singletonList(cluster.getZkServer().getZkAddress()), Optional.empty())+ .build();NoOpResponseParser responseParser = new NoOpResponseParser();responseParser.setWriterType("json");@@ -84,8 +84,11 @@ public class SolrCloudScraperTest extends PrometheusExporterTestBase {@Beforepublic void setUp() throws Exception {super.setUp();- executor = ExecutorUtil.newMDCAwareFixedThreadPool(25, new SolrNamedThreadFactory("solr-cloud-scraper-tests"));- configuration = Helpers.loadConfiguration("conf/prometheus-solr-exporter-scraper-test-config.xml");+ executor =+ ExecutorUtil.newMDCAwareFixedThreadPool(+ 25, new SolrNamedThreadFactory("solr-cloud-scraper-tests"));+ configuration =+ Helpers.loadConfiguration("conf/prometheus-solr-exporter-scraper-test-config.xml");solrCloudScraper = createSolrCloudScraper();}@@ -102,34 +105,38 @@ public class SolrCloudScraperTest extends PrometheusExporterTestBase {@Testpublic void pingCollections() throws Exception {- Map<String, MetricSamples> collectionMetrics = solrCloudScraper.pingAllCollections(- configuration.getPingConfiguration().get(0));+ Map<String, MetricSamples> collectionMetrics =+ solrCloudScraper.pingAllCollections(configuration.getPingConfiguration().get(0));assertEquals(1, collectionMetrics.size());assertTrue(collectionMetrics.containsKey(PrometheusExporterTestBase.COLLECTION));- List<Collector.MetricFamilySamples> collectionSamples = collectionMetrics.get(PrometheusExporterTestBase.COLLECTION).asList();+ List<Collector.MetricFamilySamples> collectionSamples =+ collectionMetrics.get(PrometheusExporterTestBase.COLLECTION).asList();assertEquals(1, collectionSamples.size());Collector.MetricFamilySamples collection1Metrics = collectionSamples.get(0);assertEquals("solr_ping", collection1Metrics.name);assertEquals(1, collection1Metrics.samples.size());assertEquals(1.0, collection1Metrics.samples.get(0).value, 0.001);- assertEquals(Collections.singletonList("zk_host"), collection1Metrics.samples.get(0).labelNames);- assertEquals(Collections.singletonList(cluster.getZkServer().getZkAddress()), collection1Metrics.samples.get(0).labelValues);+ assertEquals(+ Collections.singletonList("zk_host"), collection1Metrics.samples.get(0).labelNames);+ assertEquals(+ Collections.singletonList(cluster.getZkServer().getZkAddress()),+ collection1Metrics.samples.get(0).labelValues);}@Testpublic void pingCores() throws Exception {- Map<String, MetricSamples> allCoreMetrics = solrCloudScraper.pingAllCores(- configuration.getPingConfiguration().get(0));+ Map<String, MetricSamples> allCoreMetrics =+ solrCloudScraper.pingAllCores(configuration.getPingConfiguration().get(0));Map<String, DocCollection> collectionStates = getClusterState().getCollectionsMap();- long coreCount = collectionStates.entrySet()- .stream()- .mapToInt(entry -> entry.getValue().getReplicas().size())- .sum();+ long coreCount =+ collectionStates.entrySet().stream()+ .mapToInt(entry -> entry.getValue().getReplicas().size())+ .sum();assertEquals(coreCount, allCoreMetrics.size());@@ -146,18 +153,19 @@ public class SolrCloudScraperTest extends PrometheusExporterTestBase {@Testpublic void queryCollections() throws Exception {- List<Collector.MetricFamilySamples> collection1Metrics = solrCloudScraper.collections(- configuration.getCollectionsConfiguration().get(0)).asList();+ List<Collector.MetricFamilySamples> collection1Metrics =+ solrCloudScraper.collections(configuration.getCollectionsConfiguration().get(0)).asList();assertEquals(2, collection1Metrics.size());Collector.MetricFamilySamples liveNodeSamples = collection1Metrics.get(0);assertEquals("solr_collections_live_nodes", liveNodeSamples.name);- assertEquals("See following URL: https://solr.apache.org/guide/collections-api.html#clusterstatus", liveNodeSamples.help);+ assertEquals(+ "See following URL: https://solr.apache.org/guide/collections-api.html#clusterstatus",+ liveNodeSamples.help);assertEquals(1, liveNodeSamples.samples.size());assertEquals(- getClusterState().getLiveNodes().size(),- liveNodeSamples.samples.get(0).value, 0.001);+ getClusterState().getLiveNodes().size(), liveNodeSamples.samples.get(0).value, 0.001);Collector.MetricFamilySamples shardLeaderSamples = collection1Metrics.get(1);@@ -167,26 +175,32 @@ public class SolrCloudScraperTest extends PrometheusExporterTestBase {Collection<Slice> slices = getCollectionState().getSlices();- Set<String> leaderCoreNames = slices.stream()- .map(slice -> collection.getLeader(slice.getName()).getCoreName())- .collect(Collectors.toSet());+ Set<String> leaderCoreNames =+ slices.stream()+ .map(slice -> collection.getLeader(slice.getName()).getCoreName())+ .collect(Collectors.toSet());for (Collector.MetricFamilySamples.Sample sample : shardLeaderSamples.samples) {assertEquals("solr_collections_shard_leader", sample.name);- assertEquals(Arrays.asList("collection", "shard", "replica", "core", "type", "zk_host"), sample.labelNames);- assertEquals(leaderCoreNames.contains(sample.labelValues.get(3)) ? 1.0 : 0.0, sample.value, 0.001);+ assertEquals(+ Arrays.asList("collection", "shard", "replica", "core", "type", "zk_host"),+ sample.labelNames);+ assertEquals(+ leaderCoreNames.contains(sample.labelValues.get(3)) ? 1.0 : 0.0, sample.value, 0.001);}}@Testpublic void metricsForEachHost() throws Exception {- Map<String, MetricSamples> metricsByHost = solrCloudScraper.metricsForAllHosts(configuration.getMetricsConfiguration().get(0));+ Map<String, MetricSamples> metricsByHost =+ solrCloudScraper.metricsForAllHosts(configuration.getMetricsConfiguration().get(0));List<Replica> replicas = getCollectionState().getReplicas();assertEquals(replicas.size(), metricsByHost.size());for (Replica replica : replicas) {- List<Collector.MetricFamilySamples> replicaSamples = metricsByHost.get(replica.getBaseUrl()).asList();+ List<Collector.MetricFamilySamples> replicaSamples =+ metricsByHost.get(replica.getBaseUrl()).asList();assertEquals(1, replicaSamples.size());assertEquals("solr_metrics_jvm_buffers", replicaSamples.get(0).name);}@@ -194,7 +208,8 @@ public class SolrCloudScraperTest extends PrometheusExporterTestBase {@Testpublic void search() throws Exception {- List<Collector.MetricFamilySamples> samples = solrCloudScraper.search(configuration.getSearchConfiguration().get(0)).asList();+ List<Collector.MetricFamilySamples> samples =+ solrCloudScraper.search(configuration.getSearchConfiguration().get(0)).asList();assertEquals(1, samples.size());@@ -206,5 +221,4 @@ public class SolrCloudScraperTest extends PrometheusExporterTestBase {assertEquals(FACET_VALUES.get(sample.labelValues.get(0)), sample.value, 0.001);}}-}diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrStandaloneScraperTest.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrStandaloneScraperTest.javaindex 7ca2d4144a1..7442c44d488 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrStandaloneScraperTest.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/scraper/SolrStandaloneScraperTest.java@@ -17,24 +17,23 @@package org.apache.solr.prometheus.scraper;+import io.prometheus.client.Collector;import java.io.File;import java.io.IOException;import java.util.Collections;import java.util.List;import java.util.Map;import java.util.concurrent.ExecutorService;--import io.prometheus.client.Collector;import org.apache.commons.io.FileUtils;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.impl.NoOpResponseParser;import org.apache.solr.common.util.ExecutorUtil;import org.apache.solr.common.util.IOUtils;+import org.apache.solr.common.util.SolrNamedThreadFactory;import org.apache.solr.prometheus.PrometheusExporterTestBase;import org.apache.solr.prometheus.collector.MetricSamples;import org.apache.solr.prometheus.exporter.MetricsConfiguration;import org.apache.solr.prometheus.utils.Helpers;-import org.apache.solr.common.util.SolrNamedThreadFactory;import org.apache.solr.util.RestTestBase;import org.junit.AfterClass;import org.junit.BeforeClass;@@ -57,15 +56,13 @@ public class SolrStandaloneScraperTest extends RestTestBase {initCore("solrconfig.xml", "managed-schema");createJettyAndHarness(- tmpSolrHome.getAbsolutePath(),- "solrconfig.xml",- "managed-schema",- "/solr",- true,- null);+ tmpSolrHome.getAbsolutePath(), "solrconfig.xml", "managed-schema", "/solr", true, null);- executor = ExecutorUtil.newMDCAwareFixedThreadPool(25, new SolrNamedThreadFactory("solr-cloud-scraper-tests"));- configuration = Helpers.loadConfiguration("conf/prometheus-solr-exporter-scraper-test-config.xml");+ executor =+ ExecutorUtil.newMDCAwareFixedThreadPool(+ 25, new SolrNamedThreadFactory("solr-cloud-scraper-tests"));+ configuration =+ Helpers.loadConfiguration("conf/prometheus-solr-exporter-scraper-test-config.xml");solrClient = getHttpSolrClient(restTestHarness.getAdminURL());solrScraper = new SolrStandaloneScraper(solrClient, executor);@@ -97,16 +94,16 @@ public class SolrStandaloneScraperTest extends RestTestBase {@Testpublic void pingCollections() throws IOException {- Map<String, MetricSamples> collectionMetrics = solrScraper.pingAllCollections(- configuration.getPingConfiguration().get(0));+ Map<String, MetricSamples> collectionMetrics =+ solrScraper.pingAllCollections(configuration.getPingConfiguration().get(0));assertTrue(collectionMetrics.isEmpty());}@Testpublic void pingCores() throws Exception {- Map<String, MetricSamples> allCoreMetrics = solrScraper.pingAllCores(- configuration.getPingConfiguration().get(0));+ Map<String, MetricSamples> allCoreMetrics =+ solrScraper.pingAllCores(configuration.getPingConfiguration().get(0));assertEquals(1, allCoreMetrics.size());@@ -117,24 +114,28 @@ public class SolrStandaloneScraperTest extends RestTestBase {assertEquals(1, samples.samples.size());assertEquals(1.0, samples.samples.get(0).value, 0.001);assertEquals(Collections.singletonList("base_url"), samples.samples.get(0).labelNames);- assertEquals(Collections.singletonList(restTestHarness.getAdminURL()), samples.samples.get(0).labelValues);+ assertEquals(+ Collections.singletonList(restTestHarness.getAdminURL()),+ samples.samples.get(0).labelValues);}@Testpublic void queryCollections() throws Exception {- List<Collector.MetricFamilySamples> collection1Metrics = solrScraper.collections(- configuration.getCollectionsConfiguration().get(0)).asList();+ List<Collector.MetricFamilySamples> collection1Metrics =+ solrScraper.collections(configuration.getCollectionsConfiguration().get(0)).asList();assertTrue(collection1Metrics.isEmpty());}@Testpublic void metricsForHost() throws Exception {- Map<String, MetricSamples> metricsByHost = solrScraper.metricsForAllHosts(configuration.getMetricsConfiguration().get(0));+ Map<String, MetricSamples> metricsByHost =+ solrScraper.metricsForAllHosts(configuration.getMetricsConfiguration().get(0));assertEquals(1, metricsByHost.size());- List<Collector.MetricFamilySamples> replicaSamples = metricsByHost.get(restTestHarness.getAdminURL()).asList();+ List<Collector.MetricFamilySamples> replicaSamples =+ metricsByHost.get(restTestHarness.getAdminURL()).asList();assertEquals(1, replicaSamples.size());@@ -144,7 +145,8 @@ public class SolrStandaloneScraperTest extends RestTestBase {@Testpublic void search() throws Exception {- List<Collector.MetricFamilySamples> samples = solrScraper.search(configuration.getSearchConfiguration().get(0)).asList();+ List<Collector.MetricFamilySamples> samples =+ solrScraper.search(configuration.getSearchConfiguration().get(0)).asList();assertEquals(1, samples.size());@@ -153,8 +155,10 @@ public class SolrStandaloneScraperTest extends RestTestBase {assertEquals(PrometheusExporterTestBase.FACET_VALUES.size(), sampleFamily.samples.size());for (Collector.MetricFamilySamples.Sample sample : sampleFamily.samples) {- assertEquals(PrometheusExporterTestBase.FACET_VALUES.get(sample.labelValues.get(0)), sample.value, 0.001);+ assertEquals(+ PrometheusExporterTestBase.FACET_VALUES.get(sample.labelValues.get(0)),+ sample.value,+ 0.001);}}-}diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.javaindex cb8d24c30ca..0ab7a03ac05 100644--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.java+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.java@@ -20,7 +20,6 @@ package org.apache.solr.prometheus.utils;import java.io.File;import java.io.IOException;import java.util.Objects;-import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.client.solrj.SolrClient;import org.apache.solr.client.solrj.SolrServerException;@@ -37,7 +36,8 @@ public class Helpers {public static void indexAllDocs(SolrClient client) throws IOException, SolrServerException {File exampleDocsDir = new File(SolrTestCaseJ4.getFile("exampledocs").getAbsolutePath());- File[] xmlFiles = Objects.requireNonNull(exampleDocsDir.listFiles((dir, name) -> name.endsWith(".xml")));+ File[] xmlFiles =+ Objects.requireNonNull(exampleDocsDir.listFiles((dir, name) -> name.endsWith(".xml")));for (File xml : xmlFiles) {ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update");req.addFile(xml, "application/xml");@@ -52,8 +52,9 @@ public class Helpers {public static Pair<String, Double> parseMetricsLine(String line) {int spaceIdx = line.lastIndexOf(" ");if (spaceIdx == -1) {- throw new IllegalArgumentException("Failed parsing metrics line, must contain a space. Line was: " + line);+ throw new IllegalArgumentException(+ "Failed parsing metrics line, must contain a space. Line was: " + line);}- return new Pair<>(line.substring(0,spaceIdx), Double.parseDouble(line.substring(spaceIdx)));+ return new Pair<>(line.substring(0, spaceIdx), Double.parseDouble(line.substring(spaceIdx)));}}