Skip to content

Commit 276aea0

Browse files
committed
Add missing metricNames to error
In to see which metric names are missing, we can add them to the error message. Signed-off-by: leonnicolas <[email protected]>
1 parent 7163ac9 commit 276aea0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

prometheus/testutil/testutil.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,20 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str
255255
got = filterMetrics(got, metricNames)
256256
expected = filterMetrics(expected, metricNames)
257257
if len(metricNames) > len(got) {
258-
return fmt.Errorf("expected metrics name not found")
258+
h := make(map[string]struct{})
259+
for _, mf := range got {
260+
if mf == nil {
261+
continue
262+
}
263+
h[mf.GetName()] = struct{}{}
264+
}
265+
var missingMetricNames []string
266+
for _, name := range metricNames {
267+
if _, ok := h[name]; !ok {
268+
missingMetricNames = append(missingMetricNames, name)
269+
}
270+
}
271+
return fmt.Errorf("expected metric name(s) not found: %v", missingMetricNames)
259272
}
260273
}
261274

0 commit comments

Comments
 (0)