Skip to content

Commit fd0900c

Browse files
committed
nullaway
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 29c2ba2 commit fd0900c

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.List;
1010
import java.util.Set;
1111
import java.util.concurrent.CopyOnWriteArraySet;
12+
import javax.annotation.Nullable;
1213

1314
/**
1415
* Info metric. Example:
@@ -144,7 +145,7 @@ public Builder name(String name) {
144145

145146
/** Throws an {@link UnsupportedOperationException} because Info metrics cannot have a unit. */
146147
@Override
147-
public Builder unit(Unit unit) {
148+
public Builder unit(@Nullable Unit unit) {
148149
if (unit != null) {
149150
throw new UnsupportedOperationException("Info metrics cannot have a unit.");
150151
}

prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/MetricWithFixedMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public B name(String name) {
6969
return self();
7070
}
7171

72-
public B unit(Unit unit) {
72+
public B unit(@Nullable Unit unit) {
7373
this.unit = unit;
7474
return self();
7575
}

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/DistributionDataPointSnapshot.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.prometheus.metrics.model.snapshots;
22

3-
import javax.annotation.Nullable;
4-
53
/**
64
* Common base class for histogram and summary data. Histograms and Summaries represent
75
* distributions, like a latency distribution or a distribution of request sizes in Bytes.
@@ -75,7 +73,7 @@ public T sum(double sum) {
7573
return self();
7674
}
7775

78-
public T exemplars(@Nullable Exemplars exemplars) {
76+
public T exemplars(Exemplars exemplars) {
7977
this.exemplars = exemplars;
8078
return self();
8179
}

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/HistogramSnapshot.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.Collection;
55
import java.util.List;
6-
import javax.annotation.Nullable;
76

87
/** Immutable snapshot of a Histogram. */
98
public final class HistogramSnapshot extends MetricSnapshot {
@@ -399,7 +398,7 @@ protected Builder self() {
399398
return this;
400399
}
401400

402-
public Builder classicHistogramBuckets(@Nullable ClassicHistogramBuckets classicBuckets) {
401+
public Builder classicHistogramBuckets(ClassicHistogramBuckets classicBuckets) {
403402
this.classicHistogramBuckets = classicBuckets;
404403
return this;
405404
}
@@ -420,13 +419,13 @@ public Builder nativeZeroThreshold(double zeroThreshold) {
420419
}
421420

422421
public Builder nativeBucketsForPositiveValues(
423-
@Nullable NativeHistogramBuckets bucketsForPositiveValues) {
422+
NativeHistogramBuckets bucketsForPositiveValues) {
424423
this.nativeBucketsForPositiveValues = bucketsForPositiveValues;
425424
return this;
426425
}
427426

428427
public Builder nativeBucketsForNegativeValues(
429-
@Nullable NativeHistogramBuckets bucketsForNegativeValues) {
428+
NativeHistogramBuckets bucketsForNegativeValues) {
430429
this.nativeBucketsForNegativeValues = bucketsForNegativeValues;
431430
return this;
432431
}

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/InfoSnapshot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Collection;
55
import java.util.List;
6+
import javax.annotation.Nullable;
67

78
/** Immutable snapshot of an Info metric. */
89
public final class InfoSnapshot extends MetricSnapshot {
@@ -85,7 +86,7 @@ public Builder dataPoint(InfoDataPointSnapshot dataPoint) {
8586
}
8687

8788
@Override
88-
public Builder unit(Unit unit) {
89+
public Builder unit(@Nullable Unit unit) {
8990
throw new IllegalArgumentException("Info metric cannot have a unit.");
9091
}
9192

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/StateSetSnapshot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Iterator;
88
import java.util.List;
99
import java.util.stream.Stream;
10+
import javax.annotation.Nullable;
1011

1112
/** Immutable snapshot of a StateSet metric. */
1213
public final class StateSetSnapshot extends MetricSnapshot {
@@ -212,7 +213,7 @@ public Builder dataPoint(StateSetDataPointSnapshot dataPoint) {
212213
}
213214

214215
@Override
215-
public Builder unit(Unit unit) {
216+
public Builder unit(@Nullable Unit unit) {
216217
throw new IllegalArgumentException("StateSet metric cannot have a unit.");
217218
}
218219

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/SummarySnapshot.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.Collection;
55
import java.util.List;
6-
import javax.annotation.Nullable;
76

87
/** Immutable snapshot of a Summary metric. */
98
public final class SummarySnapshot extends MetricSnapshot {
@@ -103,7 +102,7 @@ protected Builder self() {
103102
return this;
104103
}
105104

106-
public Builder quantiles(@Nullable Quantiles quantiles) {
105+
public Builder quantiles(Quantiles quantiles) {
107106
this.quantiles = quantiles;
108107
return this;
109108
}

prometheus-metrics-simpleclient-bridge/src/main/java/io/prometheus/metrics/simpleclient/bridge/SimpleclientCollector.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ private MetricSnapshot convertCounter(Collector.MetricFamilySamples samples) {
118118
if (sample.name.endsWith("_created")) {
119119
dataPoint.createdTimestampMillis((long) Unit.secondsToMillis(sample.value));
120120
} else {
121-
dataPoint.value(sample.value).exemplar(convertExemplar(sample.exemplar));
121+
if (sample.exemplar != null) {
122+
dataPoint.value(sample.value).exemplar(convertExemplar(sample.exemplar));
123+
}
122124
if (sample.timestampMs != null) {
123125
dataPoint.scrapeTimestampMillis(sample.timestampMs);
124126
}
@@ -140,8 +142,10 @@ private MetricSnapshot convertGauge(Collector.MetricFamilySamples samples) {
140142
GaugeSnapshot.GaugeDataPointSnapshot.Builder dataPoint =
141143
GaugeSnapshot.GaugeDataPointSnapshot.builder()
142144
.value(sample.value)
143-
.labels(Labels.of(sample.labelNames, sample.labelValues))
144-
.exemplar(convertExemplar(sample.exemplar));
145+
.labels(Labels.of(sample.labelNames, sample.labelValues));
146+
if (sample.exemplar != null) {
147+
dataPoint.exemplar(convertExemplar(sample.exemplar));
148+
}
145149
if (sample.timestampMs != null) {
146150
dataPoint.scrapeTimestampMillis(sample.timestampMs);
147151
}
@@ -281,8 +285,10 @@ private MetricSnapshot convertUnknown(Collector.MetricFamilySamples samples) {
281285
UnknownSnapshot.UnknownDataPointSnapshot.Builder dataPoint =
282286
UnknownSnapshot.UnknownDataPointSnapshot.builder()
283287
.value(sample.value)
284-
.labels(Labels.of(sample.labelNames, sample.labelValues))
285-
.exemplar(convertExemplar(sample.exemplar));
288+
.labels(Labels.of(sample.labelNames, sample.labelValues));
289+
if (sample.exemplar != null) {
290+
dataPoint.exemplar(convertExemplar(sample.exemplar));
291+
}
286292
if (sample.timestampMs != null) {
287293
dataPoint.scrapeTimestampMillis(sample.timestampMs);
288294
}
@@ -358,11 +364,7 @@ private MetricSnapshot convertInfo(Collector.MetricFamilySamples samples) {
358364
return info.build();
359365
}
360366

361-
@Nullable
362-
private Exemplar convertExemplar(@Nullable io.prometheus.client.exemplars.Exemplar exemplar) {
363-
if (exemplar == null) {
364-
return null;
365-
}
367+
private Exemplar convertExemplar(io.prometheus.client.exemplars.Exemplar exemplar) {
366368
Exemplar.Builder result = Exemplar.builder().value(exemplar.getValue());
367369
if (exemplar.getTimestampMs() != null) {
368370
result.timestampMillis(exemplar.getTimestampMs());

0 commit comments

Comments
 (0)