Skip to content

Commit 89a8ae5

Browse files
committed
Eagerly reject null label values
Scraping generally doesn't support null label values and can throw NPEs at various points. It's easiest to debug such problems at the point null is introduced. Signed-off-by: Benjamin Peterson <[email protected]>
1 parent 785f163 commit 89a8ae5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,20 @@ public D labelValues(String... labelValues) {
112112
"Expected " + labelNames.length + " label values, but got " + labelValues.length + ".");
113113
}
114114
}
115-
return data.computeIfAbsent(Arrays.asList(labelValues), l -> newDataPoint());
115+
return data.computeIfAbsent(
116+
Arrays.asList(labelValues),
117+
l -> {
118+
for (int i = 0; i < l.size(); i++) {
119+
if (l.get(i) == null) {
120+
throw new IllegalArgumentException(
121+
"null label value for metric "
122+
+ getMetadata().getName()
123+
+ " and label "
124+
+ labelNames[i]);
125+
}
126+
}
127+
return newDataPoint();
128+
});
116129
}
117130

118131
/**

0 commit comments

Comments
 (0)