Skip to content

Commit

Permalink
Add missing metricNames to error
Browse files Browse the repository at this point in the history
In to see which metric names are missing, we can add them to the error
message.

Signed-off-by: leonnicolas <[email protected]>
  • Loading branch information
leonnicolas committed Jan 8, 2024
1 parent 7163ac9 commit 276aea0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion prometheus/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,20 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str
got = filterMetrics(got, metricNames)
expected = filterMetrics(expected, metricNames)
if len(metricNames) > len(got) {
return fmt.Errorf("expected metrics name not found")
h := make(map[string]struct{})
for _, mf := range got {
if mf == nil {
continue
}
h[mf.GetName()] = struct{}{}
}
var missingMetricNames []string
for _, name := range metricNames {
if _, ok := h[name]; !ok {
missingMetricNames = append(missingMetricNames, name)
}
}
return fmt.Errorf("expected metric name(s) not found: %v", missingMetricNames)
}
}

Expand Down

0 comments on commit 276aea0

Please sign in to comment.