diff --git a/prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterFilterProperties.java b/prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterFilterProperties.java index e9cc46767..10b600360 100644 --- a/prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterFilterProperties.java +++ b/prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterFilterProperties.java @@ -1,6 +1,5 @@ package io.prometheus.metrics.config; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -26,10 +25,10 @@ private ExporterFilterProperties(List allowedNames, List exclude } private ExporterFilterProperties(List allowedNames, List excludedNames, List allowedPrefixes, List excludedPrefixes, String prefix) { - this.allowedNames = allowedNames == null ? null : Collections.unmodifiableList(new ArrayList<>(allowedNames)); - this.excludedNames = excludedNames == null ? null : Collections.unmodifiableList(new ArrayList<>(excludedNames)); - this.allowedPrefixes = allowedPrefixes == null ? null : Collections.unmodifiableList(new ArrayList<>(allowedPrefixes)); - this.excludedPrefixes = excludedPrefixes == null ? null : Collections.unmodifiableList(new ArrayList<>(excludedPrefixes)); + this.allowedNames = allowedNames == null ? null : Collections.unmodifiableList(allowedNames); + this.excludedNames = excludedNames == null ? null : Collections.unmodifiableList(excludedNames); + this.allowedPrefixes = allowedPrefixes == null ? null : Collections.unmodifiableList(allowedPrefixes); + this.excludedPrefixes = excludedPrefixes == null ? null : Collections.unmodifiableList(excludedPrefixes); validate(prefix); } diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MetricNameFilter.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MetricNameFilter.java index c0c345a1b..8c531ae4a 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MetricNameFilter.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MetricNameFilter.java @@ -1,8 +1,8 @@ package io.prometheus.metrics.model.registry; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.function.Predicate; import static java.util.Collections.unmodifiableCollection; @@ -23,10 +23,10 @@ public class MetricNameFilter implements Predicate { private final Collection nameDoesNotStartWith; private MetricNameFilter(Collection nameIsEqualTo, Collection nameIsNotEqualTo, Collection nameStartsWith, Collection nameDoesNotStartWith) { - this.nameIsEqualTo = unmodifiableCollection(new ArrayList<>(nameIsEqualTo)); - this.nameIsNotEqualTo = unmodifiableCollection(new ArrayList<>(nameIsNotEqualTo)); - this.nameStartsWith = unmodifiableCollection(new ArrayList<>(nameStartsWith)); - this.nameDoesNotStartWith = unmodifiableCollection(new ArrayList<>(nameDoesNotStartWith)); + this.nameIsEqualTo = unmodifiableCollection(nameIsEqualTo); + this.nameIsNotEqualTo = unmodifiableCollection(nameIsNotEqualTo); + this.nameStartsWith = unmodifiableCollection(nameStartsWith); + this.nameDoesNotStartWith = unmodifiableCollection(nameDoesNotStartWith); } @Override @@ -107,7 +107,8 @@ private Builder() { * @see #nameMustBeEqualTo(Collection) */ public Builder nameMustBeEqualTo(String... names) { - return nameMustBeEqualTo(Arrays.asList(names)); + Collections.addAll(nameEqualTo, names); + return this; } /** @@ -132,7 +133,8 @@ public Builder nameMustBeEqualTo(Collection names) { * @see #nameMustNotBeEqualTo(Collection) */ public Builder nameMustNotBeEqualTo(String... names) { - return nameMustNotBeEqualTo(Arrays.asList(names)); + Collections.addAll(nameNotEqualTo, names); + return this; } /** @@ -155,7 +157,8 @@ public Builder nameMustNotBeEqualTo(Collection names) { * @see #nameMustStartWith(Collection) */ public Builder nameMustStartWith(String... prefixes) { - return nameMustStartWith(Arrays.asList(prefixes)); + Collections.addAll(nameStartsWith, prefixes); + return this; } /** @@ -174,7 +177,8 @@ public Builder nameMustStartWith(Collection prefixes) { * @see #nameMustNotStartWith(Collection) */ public Builder nameMustNotStartWith(String... prefixes) { - return nameMustNotStartWith(Arrays.asList(prefixes)); + Collections.addAll(nameDoesNotStartWith, prefixes); + return this; } /** diff --git a/simpleclient-archive/simpleclient_caffeine/src/main/java/io/prometheus/client/cache/caffeine/CacheMetricsCollector.java b/simpleclient-archive/simpleclient_caffeine/src/main/java/io/prometheus/client/cache/caffeine/CacheMetricsCollector.java index bc48dd86f..c5773ef3d 100644 --- a/simpleclient-archive/simpleclient_caffeine/src/main/java/io/prometheus/client/cache/caffeine/CacheMetricsCollector.java +++ b/simpleclient-archive/simpleclient_caffeine/src/main/java/io/prometheus/client/cache/caffeine/CacheMetricsCollector.java @@ -99,7 +99,7 @@ public void clear(){ @Override public List collect() { List mfs = new ArrayList(); - List labelNames = Arrays.asList("cache"); + List labelNames = Collections.singletonList("cache"); CounterMetricFamily cacheHitTotal = new CounterMetricFamily("caffeine_cache_hit_total", "Cache hit totals", labelNames); @@ -138,7 +138,7 @@ public List collect() { mfs.add(cacheLoadSummary); for(Map.Entry c: children.entrySet()) { - List cacheName = Arrays.asList(c.getKey()); + List cacheName = Collections.singletonList(c.getKey()); CacheStats stats = c.getValue().stats(); try{ diff --git a/simpleclient-archive/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java b/simpleclient-archive/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java index 4bf89899f..607ea2311 100644 --- a/simpleclient-archive/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java +++ b/simpleclient-archive/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java @@ -86,7 +86,7 @@ private static String getHelpMessage(String metricName, Metric metric) { MetricFamilySamples fromCounter(String dropwizardName, Counter counter) { MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "", new ArrayList(), new ArrayList(), new Long(counter.getCount()).doubleValue()); - return new MetricFamilySamples(sample.name, Type.GAUGE, getHelpMessage(dropwizardName, counter), Arrays.asList(sample)); + return new MetricFamilySamples(sample.name, Type.GAUGE, getHelpMessage(dropwizardName, counter), Collections.singletonList(sample)); } /** @@ -106,7 +106,7 @@ MetricFamilySamples fromGauge(String dropwizardName, Gauge gauge) { } MetricFamilySamples.Sample sample = sampleBuilder.createSample(dropwizardName, "", new ArrayList(), new ArrayList(), value); - return new MetricFamilySamples(sample.name, Type.GAUGE, getHelpMessage(dropwizardName, gauge), Arrays.asList(sample)); + return new MetricFamilySamples(sample.name, Type.GAUGE, getHelpMessage(dropwizardName, gauge), Collections.singletonList(sample)); } /** @@ -155,7 +155,7 @@ MetricFamilySamples fromMeter(String dropwizardName, Meter meter) { new ArrayList(), meter.getCount()); return new MetricFamilySamples(sample.name, Type.COUNTER, getHelpMessage(dropwizardName, meter), - Arrays.asList(sample)); + Collections.singletonList(sample)); } @Override diff --git a/simpleclient-archive/simpleclient_guava/src/main/java/io/prometheus/client/guava/cache/CacheMetricsCollector.java b/simpleclient-archive/simpleclient_guava/src/main/java/io/prometheus/client/guava/cache/CacheMetricsCollector.java index 5ed0276bb..1136bd124 100644 --- a/simpleclient-archive/simpleclient_guava/src/main/java/io/prometheus/client/guava/cache/CacheMetricsCollector.java +++ b/simpleclient-archive/simpleclient_guava/src/main/java/io/prometheus/client/guava/cache/CacheMetricsCollector.java @@ -86,7 +86,7 @@ public void clear(){ @Override public List collect() { List mfs = new ArrayList(); - List labelNames = Arrays.asList("cache"); + List labelNames = Collections.singletonList("cache"); CounterMetricFamily cacheHitTotal = new CounterMetricFamily("guava_cache_hit_total", "Cache hit totals", labelNames); @@ -121,7 +121,7 @@ public List collect() { mfs.add(cacheLoadSummary); for(Map.Entry c: children.entrySet()) { - List cacheName = Arrays.asList(c.getKey()); + List cacheName = Collections.singletonList(c.getKey()); CacheStats stats = c.getValue().stats(); cacheHitTotal.addMetric(cacheName, stats.hitCount()); diff --git a/simpleclient-archive/simpleclient_hibernate/src/main/java/io/prometheus/client/hibernate/HibernateStatisticsCollector.java b/simpleclient-archive/simpleclient_hibernate/src/main/java/io/prometheus/client/hibernate/HibernateStatisticsCollector.java index 32f07f8f9..b0350107d 100644 --- a/simpleclient-archive/simpleclient_hibernate/src/main/java/io/prometheus/client/hibernate/HibernateStatisticsCollector.java +++ b/simpleclient-archive/simpleclient_hibernate/src/main/java/io/prometheus/client/hibernate/HibernateStatisticsCollector.java @@ -44,7 +44,7 @@ public class HibernateStatisticsCollector extends Collector { private static final List LABEL_NAMES = Collections.singletonList("unit"); - private static final List LABEL_NAMES_PER_QUERY = Arrays.asList("unit", "query"); + private static final List LABEL_NAMES_PER_QUERY = Collections.unmodifiableList(Arrays.asList("unit", "query")); private final Map sessionFactories = new ConcurrentHashMap(); @@ -476,7 +476,7 @@ public double getValue(Statistics statistics) { private List getPerQueryMetrics() { List metrics = new ArrayList(); - metrics.addAll(Arrays.asList( + Collections.addAll(metrics, createCounterForQuery("hibernate_per_query_cache_hit_total", "Global number of cache hits for query (getCacheHitCount)", @@ -558,7 +558,7 @@ public double getValue(Statistics statistics, String query) { } } ) - )); + ); return metrics; } diff --git a/simpleclient-archive/simpleclient_jetty/src/main/java/io/prometheus/client/jetty/JettyStatisticsCollector.java b/simpleclient-archive/simpleclient_jetty/src/main/java/io/prometheus/client/jetty/JettyStatisticsCollector.java index 7dddb00aa..c0fe93fe3 100644 --- a/simpleclient-archive/simpleclient_jetty/src/main/java/io/prometheus/client/jetty/JettyStatisticsCollector.java +++ b/simpleclient-archive/simpleclient_jetty/src/main/java/io/prometheus/client/jetty/JettyStatisticsCollector.java @@ -32,7 +32,7 @@ */ public class JettyStatisticsCollector extends Collector { private final StatisticsHandler statisticsHandler; - private static final List EMPTY_LIST = new ArrayList(); + private static final List EMPTY_LIST = Collections.emptyList(); public JettyStatisticsCollector(StatisticsHandler statisticsHandler) { this.statisticsHandler = statisticsHandler; diff --git a/simpleclient-archive/simpleclient_servlet_common/src/main/java/io/prometheus/client/servlet/common/exporter/Exporter.java b/simpleclient-archive/simpleclient_servlet_common/src/main/java/io/prometheus/client/servlet/common/exporter/Exporter.java index 8a76dd218..29406c30c 100644 --- a/simpleclient-archive/simpleclient_servlet_common/src/main/java/io/prometheus/client/servlet/common/exporter/Exporter.java +++ b/simpleclient-archive/simpleclient_servlet_common/src/main/java/io/prometheus/client/servlet/common/exporter/Exporter.java @@ -87,7 +87,9 @@ private Set parse(HttpServletRequestAdapter req) { if (includedParam == null) { return Collections.emptySet(); } else { - return new HashSet(Arrays.asList(includedParam)); + Set result = new HashSet(); + Collections.addAll(result, includedParam); + return result; } }