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)
| 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. |
| 196 | func 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 |