MCPcopy
hub / github.com/prometheus/client_golang / CollectAndCompare

Function CollectAndCompare

prometheus/testutil/testutil.go:196–202  ·  view source on GitHub ↗

CollectAndCompare collects the metrics identified by `metricNames` and compares them in the Prometheus text exposition format to the data read from expected. NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter both expected and collected metrics. See ht

(c prometheus.Collector, expected io.Reader, metricNames ...string)

Source from the content-addressed store, hash-verified

194// NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter
195// both expected and collected metrics. See https://github.com/prometheus/client_golang/issues/1351.
196func CollectAndCompare(c prometheus.Collector, expected io.Reader, metricNames ...string) error {
197 reg := prometheus.NewPedanticRegistry()
198 if err := reg.Register(c); err != nil {
199 return fmt.Errorf("registering collector failed: %w", err)
200 }
201 return GatherAndCompare(reg, expected, metricNames...)
202}
203
204// GatherAndCompare gathers all metrics from the provided Gatherer and compares
205// it to an expected output read from the provided Reader in the Prometheus text

Callers 6

TestCollectAndCompareFunction · 0.85
TestNoMetricFilterFunction · 0.85
TestMetricNotFoundFunction · 0.85

Calls 3

NewPedanticRegistryFunction · 0.92
GatherAndCompareFunction · 0.85
RegisterMethod · 0.65

Tested by 6

TestCollectAndCompareFunction · 0.68
TestNoMetricFilterFunction · 0.68
TestMetricNotFoundFunction · 0.68