diff --git a/examples/example-exporter-multi-target/src/main/java/io/prometheus/metrics/examples/multitarget/SampleMultiCollector.java b/examples/example-exporter-multi-target/src/main/java/io/prometheus/metrics/examples/multitarget/SampleMultiCollector.java index dba3b1b9e..207c024a5 100644 --- a/examples/example-exporter-multi-target/src/main/java/io/prometheus/metrics/examples/multitarget/SampleMultiCollector.java +++ b/examples/example-exporter-multi-target/src/main/java/io/prometheus/metrics/examples/multitarget/SampleMultiCollector.java @@ -71,7 +71,7 @@ protected MetricSnapshots collectMetricSnapshots(PrometheusScrapeRequest scrapeR gaugeBuilder.dataPoint(gaugeDataPointBuilder.build()); } } - Collection> snaps = new ArrayList<>(); + Collection snaps = new ArrayList<>(); snaps.add(counterBuilder.build()); snaps.add(gaugeBuilder.build()); return new MetricSnapshots(snaps); diff --git a/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Metric.java b/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Metric.java index 4821e93cd..d3c00eca0 100644 --- a/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Metric.java +++ b/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Metric.java @@ -19,7 +19,7 @@ protected Metric(Builder builder) { } @Override - public abstract MetricSnapshot collect(); + public abstract MetricSnapshot collect(); protected abstract static class Builder, M extends Metric> { diff --git a/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/StatefulMetric.java b/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/StatefulMetric.java index 67523eeee..5a838c649 100644 --- a/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/StatefulMetric.java +++ b/prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/StatefulMetric.java @@ -45,10 +45,10 @@ protected StatefulMetric(Builder builder) { /** * labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i). */ - protected abstract MetricSnapshot collect(List labels, List metricData); + protected abstract MetricSnapshot collect(List labels, List metricData); @Override - public MetricSnapshot collect() { + public MetricSnapshot collect() { if (labelNames.length == 0 && data.isEmpty()) { // This is a metric without labels that has not been used yet. Initialize the data on the fly. labelValues(); diff --git a/prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/PrometheusMetricProducer.java b/prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/PrometheusMetricProducer.java index a3022289a..39a293640 100644 --- a/prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/PrometheusMetricProducer.java +++ b/prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/PrometheusMetricProducer.java @@ -51,7 +51,7 @@ public Collection collectAllMetrics() { resourceWithTargetInfo, scopeFromInfo != null ? scopeFromInfo : instrumentationScopeInfo, System.currentTimeMillis()); - for (MetricSnapshot snapshot : snapshots) { + for (MetricSnapshot snapshot : snapshots) { if (snapshot instanceof CounterSnapshot) { addUnlessNull(result, factory.create((CounterSnapshot) snapshot)); } else if (snapshot instanceof GaugeSnapshot) { @@ -78,7 +78,7 @@ public Collection collectAllMetrics() { private Resource resourceFromTargetInfo(MetricSnapshots snapshots) { ResourceBuilder result = Resource.builder(); - for (MetricSnapshot snapshot : snapshots) { + for (MetricSnapshot snapshot : snapshots) { if (snapshot.getMetadata().getName().equals("target") && snapshot instanceof InfoSnapshot) { InfoSnapshot targetInfo = (InfoSnapshot) snapshot; if (!targetInfo.getDataPoints().isEmpty()) { @@ -95,7 +95,7 @@ private Resource resourceFromTargetInfo(MetricSnapshots snapshots) { private InstrumentationScopeInfo instrumentationScopeFromOTelScopeInfo( MetricSnapshots snapshots) { - for (MetricSnapshot snapshot : snapshots) { + for (MetricSnapshot snapshot : snapshots) { if (snapshot.getMetadata().getPrometheusName().equals("otel_scope") && snapshot instanceof InfoSnapshot) { InfoSnapshot scopeInfo = (InfoSnapshot) snapshot; diff --git a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/OpenMetricsTextFormatWriter.java b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/OpenMetricsTextFormatWriter.java index 3d3eb862a..06850a3d8 100644 --- a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/OpenMetricsTextFormatWriter.java +++ b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/OpenMetricsTextFormatWriter.java @@ -66,7 +66,7 @@ public String getContentType() { @Override public void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); - for (MetricSnapshot snapshot : metricSnapshots) { + for (MetricSnapshot snapshot : metricSnapshots) { if (!snapshot.getDataPoints().isEmpty()) { if (snapshot instanceof CounterSnapshot) { writeCounter(writer, (CounterSnapshot) snapshot); diff --git a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusProtobufWriter.java b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusProtobufWriter.java index 87e50ed8b..7e722b056 100644 --- a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusProtobufWriter.java +++ b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusProtobufWriter.java @@ -52,7 +52,7 @@ public String getContentType() { public String toDebugString(MetricSnapshots metricSnapshots) { StringBuilder stringBuilder = new StringBuilder(); - for (MetricSnapshot snapshot : metricSnapshots) { + for (MetricSnapshot snapshot : metricSnapshots) { if (snapshot.getDataPoints().size() > 0) { stringBuilder.append(TextFormat.printer().printToString(convert(snapshot))); } @@ -62,14 +62,14 @@ public String toDebugString(MetricSnapshots metricSnapshots) { @Override public void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOException { - for (MetricSnapshot snapshot : metricSnapshots) { + for (MetricSnapshot snapshot : metricSnapshots) { if (snapshot.getDataPoints().size() > 0) { convert(snapshot).writeDelimitedTo(out); } } } - public Metrics.MetricFamily convert(MetricSnapshot snapshot) { + public Metrics.MetricFamily convert(MetricSnapshot snapshot) { Metrics.MetricFamily.Builder builder = Metrics.MetricFamily.newBuilder(); if (snapshot instanceof CounterSnapshot) { for (CounterDataPointSnapshot data : ((CounterSnapshot) snapshot).getDataPoints()) { diff --git a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusTextFormatWriter.java b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusTextFormatWriter.java index cdc02c26b..eb07abc73 100644 --- a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusTextFormatWriter.java +++ b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/PrometheusTextFormatWriter.java @@ -60,7 +60,7 @@ public void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOEx // "unknown", "gauge", "counter", "stateset", "info", "histogram", "gaugehistogram", and // "summary". OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); - for (MetricSnapshot snapshot : metricSnapshots) { + for (MetricSnapshot snapshot : metricSnapshots) { if (snapshot.getDataPoints().size() > 0) { if (snapshot instanceof CounterSnapshot) { writeCounter(writer, (CounterSnapshot) snapshot); @@ -80,7 +80,7 @@ public void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOEx } } if (writeCreatedTimestamps) { - for (MetricSnapshot snapshot : metricSnapshots) { + for (MetricSnapshot snapshot : metricSnapshots) { if (snapshot.getDataPoints().size() > 0) { if (snapshot instanceof CounterSnapshot) { writeCreated(writer, snapshot); @@ -95,8 +95,7 @@ public void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOEx writer.flush(); } - public void writeCreated(OutputStreamWriter writer, MetricSnapshot snapshot) - throws IOException { + public void writeCreated(OutputStreamWriter writer, MetricSnapshot snapshot) throws IOException { boolean metadataWritten = false; MetricMetadata metadata = snapshot.getMetadata(); for (DataPointSnapshot data : snapshot.getDataPoints()) { diff --git a/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java b/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java index cdcfd5f0b..37d2cf892 100644 --- a/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java +++ b/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java @@ -2619,8 +2619,7 @@ public void testLabelValueEscape() throws IOException { assertPrometheusText(prometheus, counter); } - private void assertOpenMetricsText(String expected, MetricSnapshot snapshot) - throws IOException { + private void assertOpenMetricsText(String expected, MetricSnapshot snapshot) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); OpenMetricsTextFormatWriter writer = new OpenMetricsTextFormatWriter(true, false); writer.write(out, MetricSnapshots.of(snapshot)); @@ -2628,14 +2627,14 @@ private void assertOpenMetricsText(String expected, MetricSnapshot snapshot) } private void assertOpenMetricsTextWithExemplarsOnAllTimeSeries( - String expected, MetricSnapshot snapshot) throws IOException { + String expected, MetricSnapshot snapshot) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); OpenMetricsTextFormatWriter writer = new OpenMetricsTextFormatWriter(true, true); writer.write(out, MetricSnapshots.of(snapshot)); assertThat(out).hasToString(expected); } - private void assertOpenMetricsTextWithoutCreated(String expected, MetricSnapshot snapshot) + private void assertOpenMetricsTextWithoutCreated(String expected, MetricSnapshot snapshot) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); OpenMetricsTextFormatWriter writer = new OpenMetricsTextFormatWriter(false, false); @@ -2643,15 +2642,14 @@ private void assertOpenMetricsTextWithoutCreated(String expected, MetricSnapshot assertThat(out).hasToString(expected); } - private void assertPrometheusText(String expected, MetricSnapshot snapshot) - throws IOException { + private void assertPrometheusText(String expected, MetricSnapshot snapshot) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrometheusTextFormatWriter writer = new PrometheusTextFormatWriter(true); writer.write(out, MetricSnapshots.of(snapshot)); assertThat(out).hasToString(expected); } - private void assertPrometheusTextWithoutCreated(String expected, MetricSnapshot snapshot) + private void assertPrometheusTextWithoutCreated(String expected, MetricSnapshot snapshot) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrometheusTextFormatWriter writer = new PrometheusTextFormatWriter(false); @@ -2659,7 +2657,7 @@ private void assertPrometheusTextWithoutCreated(String expected, MetricSnapshot< assertThat(out).hasToString(expected); } - private void assertPrometheusProtobuf(String expected, MetricSnapshot snapshot) { + private void assertPrometheusProtobuf(String expected, MetricSnapshot snapshot) { PrometheusProtobufWriter writer = new PrometheusProtobufWriter(); Metrics.MetricFamily protobufData = writer.convert(snapshot); String actual = TextFormatUtil.shortDebugString(protobufData); diff --git a/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExports.java b/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExports.java index c4418b432..ce0318912 100644 --- a/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExports.java +++ b/prometheus-metrics-instrumentation-dropwizard5/src/main/java/io/prometheus/metrics/instrumentation/dropwizard5/DropwizardExports.java @@ -70,7 +70,7 @@ private MetricMetadata getMetricMetaData(String metricName, Metric metric) { * Export counter as Prometheus Gauge. */ - MetricSnapshot fromCounter(String dropwizardName, Counter counter) { + MetricSnapshot fromCounter(String dropwizardName, Counter counter) { MetricMetadata metadata = getMetricMetaData(dropwizardName, counter); CounterSnapshot.CounterDataPointSnapshot.Builder dataPointBuilder = CounterSnapshot.CounterDataPointSnapshot.builder() @@ -84,7 +84,7 @@ MetricSnapshot fromCounter(String dropwizardName, Counter counter) { } /** Export gauge as a prometheus gauge. */ - MetricSnapshot fromGauge(String dropwizardName, Gauge gauge) { + MetricSnapshot fromGauge(String dropwizardName, Gauge gauge) { Object obj = gauge.getValue(); double value; if (obj instanceof Number) { @@ -119,7 +119,7 @@ MetricSnapshot fromGauge(String dropwizardName, Gauge gauge) { * @param count the total sample count for this snapshot. * @param factor a factor to apply to histogram values. */ - MetricSnapshot fromSnapshotAndCount( + MetricSnapshot fromSnapshotAndCount( String dropwizardName, Snapshot snapshot, long count, double factor, String helpMessage) { Quantiles quantiles = Quantiles.builder() @@ -144,7 +144,7 @@ MetricSnapshot fromSnapshotAndCount( } /** Convert histogram snapshot. */ - MetricSnapshot fromHistogram(String dropwizardName, Histogram histogram) { + MetricSnapshot fromHistogram(String dropwizardName, Histogram histogram) { return fromSnapshotAndCount( dropwizardName, histogram.getSnapshot(), @@ -154,7 +154,7 @@ MetricSnapshot fromHistogram(String dropwizardName, Histogram histogram) { } /** Export Dropwizard Timer as a histogram. Use TIME_UNIT as time unit. */ - MetricSnapshot fromTimer(String dropwizardName, Timer timer) { + MetricSnapshot fromTimer(String dropwizardName, Timer timer) { return fromSnapshotAndCount( dropwizardName, timer.getSnapshot(), @@ -164,7 +164,7 @@ MetricSnapshot fromTimer(String dropwizardName, Timer timer) { } /** Export a Meter as a prometheus COUNTER. */ - MetricSnapshot fromMeter(String dropwizardName, Meter meter) { + MetricSnapshot fromMeter(String dropwizardName, Meter meter) { MetricMetadata metadata = getMetricMetaData(dropwizardName + "_total", meter); CounterSnapshot.CounterDataPointSnapshot.Builder dataPointBuilder = CounterSnapshot.CounterDataPointSnapshot.builder().value(meter.getCount()); diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryPoolAllocationMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryPoolAllocationMetricsTest.java index 6aeacb13f..67dd6f2e6 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryPoolAllocationMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMemoryPoolAllocationMetricsTest.java @@ -50,7 +50,7 @@ public void testListenerLogic() { } private double getCountByPool(String metricName, String poolName, MetricSnapshots snapshots) { - for (MetricSnapshot snapshot : snapshots) { + for (MetricSnapshot snapshot : snapshots) { if (snapshot.getMetadata().getPrometheusName().equals(metricName)) { for (CounterSnapshot.CounterDataPointSnapshot data : ((CounterSnapshot) snapshot).getDataPoints()) { diff --git a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java index 9c9e069b6..a15465bfe 100644 --- a/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java +++ b/prometheus-metrics-instrumentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmThreadsMetricsTest.java @@ -146,7 +146,7 @@ public void testInvalidThreadIds() { private Map getCountByState(MetricSnapshots snapshots) { Map result = new HashMap<>(); - for (MetricSnapshot snapshot : snapshots) { + for (MetricSnapshot snapshot : snapshots) { if (snapshot.getMetadata().getName().equals("jvm_threads_state")) { for (GaugeSnapshot.GaugeDataPointSnapshot data : ((GaugeSnapshot) snapshot).getDataPoints()) { diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/Collector.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/Collector.java index fad461548..57b2b640f 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/Collector.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/Collector.java @@ -11,13 +11,13 @@ public interface Collector { /** Called when the Prometheus server scrapes metrics. */ - MetricSnapshot collect(); + MetricSnapshot collect(); /** * Provides Collector with the details of the request issued by Prometheus to allow multi-target * pattern implementation Override to implement request dependent logic to provide MetricSnapshot */ - default MetricSnapshot collect(PrometheusScrapeRequest scrapeRequest) { + default MetricSnapshot collect(PrometheusScrapeRequest scrapeRequest) { return collect(); } @@ -28,8 +28,8 @@ default MetricSnapshot collect(PrometheusScrapeRequest scrapeRequest) { *

Override this if there is a more efficient way than first collecting the snapshot and then * discarding it. */ - default MetricSnapshot collect(Predicate includedNames) { - MetricSnapshot result = collect(); + default MetricSnapshot collect(Predicate includedNames) { + MetricSnapshot result = collect(); if (includedNames.test(result.getMetadata().getPrometheusName())) { return result; } else { @@ -43,9 +43,9 @@ default MetricSnapshot collect(Predicate includedNames) { *

Override this if there is a more efficient way than first collecting the snapshot and then * discarding it. */ - default MetricSnapshot collect( + default MetricSnapshot collect( Predicate includedNames, PrometheusScrapeRequest scrapeRequest) { - MetricSnapshot result = collect(scrapeRequest); + MetricSnapshot result = collect(scrapeRequest); if (includedNames.test(result.getMetadata().getPrometheusName())) { return result; } else { diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MultiCollector.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MultiCollector.java index 8f44239fb..a4f52746e 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MultiCollector.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MultiCollector.java @@ -42,7 +42,7 @@ default MetricSnapshots collect( Predicate includedNames, PrometheusScrapeRequest scrapeRequest) { MetricSnapshots allSnapshots = scrapeRequest == null ? collect() : collect(scrapeRequest); MetricSnapshots.Builder result = MetricSnapshots.builder(); - for (MetricSnapshot snapshot : allSnapshots) { + for (MetricSnapshot snapshot : allSnapshots) { if (includedNames.test(snapshot.getMetadata().getPrometheusName())) { result.metricSnapshot(snapshot); } diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/PrometheusRegistry.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/PrometheusRegistry.java index 5038da894..0a2434845 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/PrometheusRegistry.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/PrometheusRegistry.java @@ -69,7 +69,7 @@ public MetricSnapshots scrape() { public MetricSnapshots scrape(PrometheusScrapeRequest scrapeRequest) { MetricSnapshots.Builder result = MetricSnapshots.builder(); for (Collector collector : collectors) { - MetricSnapshot snapshot = + MetricSnapshot snapshot = scrapeRequest == null ? collector.collect() : collector.collect(scrapeRequest); if (snapshot != null) { if (result.containsMetricName(snapshot.getMetadata().getName())) { @@ -82,7 +82,7 @@ public MetricSnapshots scrape(PrometheusScrapeRequest scrapeRequest) { for (MultiCollector collector : multiCollectors) { MetricSnapshots snapshots = scrapeRequest == null ? collector.collect() : collector.collect(scrapeRequest); - for (MetricSnapshot snapshot : snapshots) { + for (MetricSnapshot snapshot : snapshots) { if (result.containsMetricName(snapshot.getMetadata().getName())) { throw new IllegalStateException( snapshot.getMetadata().getPrometheusName() + ": duplicate metric name."); @@ -111,7 +111,7 @@ public MetricSnapshots scrape( // prometheusName == null means the name is unknown, and we have to scrape to learn the name. // prometheusName != null means we can skip the scrape if the name is excluded. if (prometheusName == null || includedNames.test(prometheusName)) { - MetricSnapshot snapshot = + MetricSnapshot snapshot = scrapeRequest == null ? collector.collect(includedNames) : collector.collect(includedNames, scrapeRequest); @@ -138,7 +138,7 @@ public MetricSnapshots scrape( scrapeRequest == null ? collector.collect(includedNames) : collector.collect(includedNames, scrapeRequest); - for (MetricSnapshot snapshot : snapshots) { + for (MetricSnapshot snapshot : snapshots) { if (snapshot != null) { result.metricSnapshot(snapshot); } diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/CounterSnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/CounterSnapshot.java index c74a68e39..373c7550e 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/CounterSnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/CounterSnapshot.java @@ -5,7 +5,7 @@ import java.util.List; /** Immutable snapshot of a Counter. */ -public class CounterSnapshot extends MetricSnapshot { +public class CounterSnapshot extends MetricSnapshot { /** * To create a new {@link CounterSnapshot}, you can either call the constructor directly or use @@ -19,9 +19,10 @@ public CounterSnapshot(MetricMetadata metadata, Collection getDataPoints() { - return dataPoints; + return (List) dataPoints; } public static class CounterDataPointSnapshot extends DataPointSnapshot { diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/GaugeSnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/GaugeSnapshot.java index 795323271..641aa166a 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/GaugeSnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/GaugeSnapshot.java @@ -5,7 +5,7 @@ import java.util.List; /** Immutable snapshot of a Gauge. */ -public final class GaugeSnapshot extends MetricSnapshot { +public final class GaugeSnapshot extends MetricSnapshot { /** * To create a new {@link GaugeSnapshot}, you can either call the constructor directly or use the @@ -18,9 +18,10 @@ public GaugeSnapshot(MetricMetadata metadata, Collection super(metadata, data); } + @SuppressWarnings("unchecked") @Override public List getDataPoints() { - return dataPoints; + return (List) dataPoints; } public static final class GaugeDataPointSnapshot extends DataPointSnapshot { diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/HistogramSnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/HistogramSnapshot.java index 6966552a7..eb6213d6b 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/HistogramSnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/HistogramSnapshot.java @@ -5,8 +5,7 @@ import java.util.List; /** Immutable snapshot of a Histogram. */ -public final class HistogramSnapshot - extends MetricSnapshot { +public final class HistogramSnapshot extends MetricSnapshot { private final boolean gaugeHistogram; public static final int CLASSIC_HISTOGRAM = Integer.MIN_VALUE; @@ -40,9 +39,10 @@ public boolean isGaugeHistogram() { return gaugeHistogram; } + @SuppressWarnings("unchecked") @Override public List getDataPoints() { - return dataPoints; + return (List) dataPoints; } public static final class HistogramDataPointSnapshot extends DistributionDataPointSnapshot { diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/InfoSnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/InfoSnapshot.java index ec8ece23c..f464c12ae 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/InfoSnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/InfoSnapshot.java @@ -5,7 +5,7 @@ import java.util.List; /** Immutable snapshot of an Info metric. */ -public final class InfoSnapshot extends MetricSnapshot { +public final class InfoSnapshot extends MetricSnapshot { /** * To create a new {@link InfoSnapshot}, you can either call the constructor directly or use the @@ -22,9 +22,10 @@ public InfoSnapshot(MetricMetadata metadata, Collection d } } + @SuppressWarnings("unchecked") @Override public List getDataPoints() { - return dataPoints; + return (List) dataPoints; } public static class InfoDataPointSnapshot extends DataPointSnapshot { diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshot.java index 5d4c15461..3e1e49a2f 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshot.java @@ -7,12 +7,13 @@ import java.util.List; /** Base class for metric snapshots. */ -public abstract class MetricSnapshot { +public abstract class MetricSnapshot { private final MetricMetadata metadata; - protected final List dataPoints; + protected final List dataPoints; - protected MetricSnapshot(MetricMetadata metadata, Collection dataPoints) { + protected MetricSnapshot( + MetricMetadata metadata, Collection dataPoints) { if (metadata == null) { throw new NullPointerException("metadata"); } @@ -20,7 +21,7 @@ protected MetricSnapshot(MetricMetadata metadata, Collection dataPoints) { throw new NullPointerException("dataPoints"); } this.metadata = metadata; - List dataCopy = new ArrayList<>(dataPoints); + List dataCopy = new ArrayList<>(dataPoints); dataCopy.sort(Comparator.comparing(DataPointSnapshot::getLabels)); this.dataPoints = Collections.unmodifiableList(dataCopy); validateLabels(this.dataPoints, metadata); @@ -30,7 +31,7 @@ public MetricMetadata getMetadata() { return metadata; } - public abstract List getDataPoints(); + public abstract List getDataPoints(); private static void validateLabels( List dataPoints, MetricMetadata metadata) { @@ -71,7 +72,7 @@ public T unit(Unit unit) { return self(); } - public abstract MetricSnapshot build(); + public abstract MetricSnapshot build(); protected MetricMetadata buildMetadata() { return new MetricMetadata(name, help, unit); diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshots.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshots.java index f56976e9e..ecee897e4 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshots.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/MetricSnapshots.java @@ -14,12 +14,12 @@ import java.util.stream.Stream; /** Immutable list of metric snapshots. */ -public class MetricSnapshots implements Iterable> { +public class MetricSnapshots implements Iterable { - private final List> snapshots; + private final List snapshots; /** See {@link #MetricSnapshots(Collection)} */ - public MetricSnapshots(MetricSnapshot... snapshots) { + public MetricSnapshots(MetricSnapshot... snapshots) { this(Arrays.asList(snapshots)); } @@ -33,8 +33,8 @@ public MetricSnapshots(MetricSnapshot... snapshots) { * Builder#containsMetricName(String)} before calling {@link * Builder#metricSnapshot(MetricSnapshot)}. */ - public MetricSnapshots(Collection> snapshots) { - List> list = new ArrayList<>(snapshots); + public MetricSnapshots(Collection snapshots) { + List list = new ArrayList<>(snapshots); list.sort(comparing(s -> s.getMetadata().getPrometheusName())); for (int i = 0; i < snapshots.size() - 1; i++) { if (list.get(i) @@ -48,12 +48,12 @@ public MetricSnapshots(Collection> snapshots) { this.snapshots = unmodifiableList(list); } - public static MetricSnapshots of(MetricSnapshot... snapshots) { + public static MetricSnapshots of(MetricSnapshot... snapshots) { return new MetricSnapshots(snapshots); } @Override - public Iterator> iterator() { + public Iterator iterator() { return snapshots.iterator(); } @@ -61,11 +61,11 @@ public int size() { return snapshots.size(); } - public MetricSnapshot get(int i) { + public MetricSnapshot get(int i) { return snapshots.get(i); } - public Stream> stream() { + public Stream stream() { return snapshots.stream(); } @@ -75,7 +75,7 @@ public static Builder builder() { public static class Builder { - private final List> snapshots = new ArrayList<>(); + private final List snapshots = new ArrayList<>(); private final Set prometheusNames = new HashSet<>(); private Builder() {} @@ -89,7 +89,7 @@ public boolean containsMetricName(String name) { } /** Add a metric snapshot. Call multiple times to add multiple metric snapshots. */ - public Builder metricSnapshot(MetricSnapshot snapshot) { + public Builder metricSnapshot(MetricSnapshot snapshot) { snapshots.add(snapshot); prometheusNames.add(snapshot.getMetadata().getPrometheusName()); return this; diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/StateSetSnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/StateSetSnapshot.java index 7c6e49d19..e49a9b27d 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/StateSetSnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/StateSetSnapshot.java @@ -9,8 +9,7 @@ import java.util.stream.Stream; /** Immutable snapshot of a StateSet metric. */ -public final class StateSetSnapshot - extends MetricSnapshot { +public final class StateSetSnapshot extends MetricSnapshot { /** * To create a new {@link StateSetSnapshot}, you can either call the constructor directly or use @@ -36,9 +35,10 @@ private void validate() { } } + @SuppressWarnings("unchecked") @Override public List getDataPoints() { - return dataPoints; + return (List) dataPoints; } public static class StateSetDataPointSnapshot extends DataPointSnapshot diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/SummarySnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/SummarySnapshot.java index 26bd0f602..ac83ef7ae 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/SummarySnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/SummarySnapshot.java @@ -5,8 +5,7 @@ import java.util.List; /** Immutable snapshot of a Summary metric. */ -public final class SummarySnapshot - extends MetricSnapshot { +public final class SummarySnapshot extends MetricSnapshot { /** * To create a new {@link SummarySnapshot}, you can either call the constructor directly or use @@ -19,9 +18,10 @@ public SummarySnapshot(MetricMetadata metadata, Collection getDataPoints() { - return dataPoints; + return (List) dataPoints; } public static final class SummaryDataPointSnapshot extends DistributionDataPointSnapshot { diff --git a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/UnknownSnapshot.java b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/UnknownSnapshot.java index 30ec564cb..120841bb5 100644 --- a/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/UnknownSnapshot.java +++ b/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/UnknownSnapshot.java @@ -5,8 +5,7 @@ import java.util.List; /** Immutable snapshot of an Unknown (Untyped) metric. */ -public final class UnknownSnapshot - extends MetricSnapshot { +public final class UnknownSnapshot extends MetricSnapshot { /** * To create a new {@link UnknownSnapshot}, you can either call the constructor directly or use @@ -20,9 +19,10 @@ public UnknownSnapshot(MetricMetadata metadata, Collection getDataPoints() { - return dataPoints; + return (List) dataPoints; } public static final class UnknownDataPointSnapshot extends DataPointSnapshot { diff --git a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/registry/PrometheusRegistryTest.java b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/registry/PrometheusRegistryTest.java index e0f22a9dc..405321d29 100644 --- a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/registry/PrometheusRegistryTest.java +++ b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/registry/PrometheusRegistryTest.java @@ -19,7 +19,7 @@ class PrometheusRegistryTest { Collector counterA1 = new Collector() { @Override - public MetricSnapshot collect() { + public MetricSnapshot collect() { return CounterSnapshot.builder().name("counter_a").build(); } @@ -32,7 +32,7 @@ public String getPrometheusName() { Collector counterA2 = new Collector() { @Override - public MetricSnapshot collect() { + public MetricSnapshot collect() { return CounterSnapshot.builder().name("counter.a").build(); } @@ -45,7 +45,7 @@ public String getPrometheusName() { Collector counterB = new Collector() { @Override - public MetricSnapshot collect() { + public MetricSnapshot collect() { return CounterSnapshot.builder().name("counter_b").build(); } @@ -58,7 +58,7 @@ public String getPrometheusName() { Collector gaugeA = new Collector() { @Override - public MetricSnapshot collect() { + public MetricSnapshot collect() { return GaugeSnapshot.builder().name("gauge_a").build(); } diff --git a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotTest.java b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotTest.java index 581ba6599..2c1c04bb6 100644 --- a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotTest.java +++ b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotTest.java @@ -40,7 +40,7 @@ public void testDuplicateLabels() { @Test public void testNoData() { - MetricSnapshot snapshot = CounterSnapshot.builder().name("test").build(); + MetricSnapshot snapshot = CounterSnapshot.builder().name("test").build(); assertThat(snapshot.getDataPoints().size()).isEqualTo(0); } diff --git a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotsTest.java b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotsTest.java index 09d63d4d9..ed2f66fec 100644 --- a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotsTest.java +++ b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/MetricSnapshotsTest.java @@ -92,7 +92,7 @@ public void testImmutable() { .dataPoint(CounterSnapshot.CounterDataPointSnapshot.builder().value(1.0).build()) .build(); MetricSnapshots snapshots = new MetricSnapshots(c2, c3, c1); - Iterator> iterator = snapshots.iterator(); + Iterator iterator = snapshots.iterator(); iterator.next(); assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(iterator::remove); } diff --git a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/SnapshotTestUtil.java b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/SnapshotTestUtil.java index a69bba499..d8e8d33e4 100644 --- a/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/SnapshotTestUtil.java +++ b/prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/SnapshotTestUtil.java @@ -5,7 +5,7 @@ class SnapshotTestUtil { public static void assertMetadata( - MetricSnapshot snapshot, String name, String help, String unit) { + MetricSnapshot snapshot, String name, String help, String unit) { assertThat(snapshot.getMetadata().getName()).isEqualTo(name); assertThat(snapshot.getMetadata().getHelp()).isEqualTo(help); if (unit != null) { diff --git a/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java b/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java index c11d69e26..5873a4977 100644 --- a/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java +++ b/prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java @@ -101,7 +101,7 @@ private MetricSnapshots convert(Enumeration sampl return result.build(); } - private MetricSnapshot convertCounter(Collector.MetricFamilySamples samples) { + private MetricSnapshot convertCounter(Collector.MetricFamilySamples samples) { CounterSnapshot.Builder counter = CounterSnapshot.builder() .name(sanitizeMetricName(samples.name)) @@ -128,7 +128,7 @@ private MetricSnapshot convertCounter(Collector.MetricFamilySamples samples) return counter.build(); } - private MetricSnapshot convertGauge(Collector.MetricFamilySamples samples) { + private MetricSnapshot convertGauge(Collector.MetricFamilySamples samples) { GaugeSnapshot.Builder gauge = GaugeSnapshot.builder() .name(sanitizeMetricName(samples.name)) @@ -148,7 +148,7 @@ private MetricSnapshot convertGauge(Collector.MetricFamilySamples samples) { return gauge.build(); } - private MetricSnapshot convertHistogram( + private MetricSnapshot convertHistogram( Collector.MetricFamilySamples samples, boolean isGaugeHistogram) { HistogramSnapshot.Builder histogram = HistogramSnapshot.builder() @@ -192,7 +192,7 @@ private MetricSnapshot convertHistogram( return histogram.build(); } - private MetricSnapshot convertSummary(Collector.MetricFamilySamples samples) { + private MetricSnapshot convertSummary(Collector.MetricFamilySamples samples) { SummarySnapshot.Builder summary = SummarySnapshot.builder() .name(sanitizeMetricName(samples.name)) @@ -242,7 +242,7 @@ private MetricSnapshot convertSummary(Collector.MetricFamilySamples samples) return summary.build(); } - private MetricSnapshot convertStateSet(Collector.MetricFamilySamples samples) { + private MetricSnapshot convertStateSet(Collector.MetricFamilySamples samples) { StateSetSnapshot.Builder stateSet = StateSetSnapshot.builder().name(sanitizeMetricName(samples.name)).help(samples.help); Map dataPoints = new HashMap<>(); @@ -271,7 +271,7 @@ private MetricSnapshot convertStateSet(Collector.MetricFamilySamples samples) return stateSet.build(); } - private MetricSnapshot convertUnknown(Collector.MetricFamilySamples samples) { + private MetricSnapshot convertUnknown(Collector.MetricFamilySamples samples) { UnknownSnapshot.Builder unknown = UnknownSnapshot.builder() .name(sanitizeMetricName(samples.name)) @@ -345,7 +345,7 @@ private Labels labelsWithout( return labels.build(); } - private MetricSnapshot convertInfo(Collector.MetricFamilySamples samples) { + private MetricSnapshot convertInfo(Collector.MetricFamilySamples samples) { InfoSnapshot.Builder info = InfoSnapshot.builder().name(sanitizeMetricName(samples.name)).help(samples.help); for (Collector.MetricFamilySamples.Sample sample : samples.samples) {