From 276aea0bb9ada555c533cdb3b59a2fdc138c6b0a Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Mon, 8 Jan 2024 17:59:44 +0100 Subject: [PATCH] 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 --- prometheus/testutil/testutil.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/prometheus/testutil/testutil.go b/prometheus/testutil/testutil.go index 3ba78baec..b1cfdbd9d 100644 --- a/prometheus/testutil/testutil.go +++ b/prometheus/testutil/testutil.go @@ -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) } }