TransactionalGatherAndCompare gathers all metrics from the provided Gatherer and compares it to an expected output read from the provided Reader in the Prometheus text exposition format. If any metricNames are provided, only metrics with those names are compared. NOTE: Be mindful of accidental disc
(g prometheus.TransactionalGatherer, expected io.Reader, metricNames ...string)
| 220 | // NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter |
| 221 | // both expected and gathered metrics. See https://github.com/prometheus/client_golang/issues/1351. |
| 222 | func TransactionalGatherAndCompare(g prometheus.TransactionalGatherer, expected io.Reader, metricNames ...string) error { |
| 223 | got, done, err := g.Gather() |
| 224 | defer done() |
| 225 | if err != nil { |
| 226 | return fmt.Errorf("gathering metrics failed: %w", err) |
| 227 | } |
| 228 | |
| 229 | wanted, err := convertReaderToMetricFamily(expected) |
| 230 | if err != nil { |
| 231 | return err |
| 232 | } |
| 233 | |
| 234 | return compareMetricFamilies(got, wanted, metricNames...) |
| 235 | } |
| 236 | |
| 237 | // CollectAndFormat collects the metrics identified by `metricNames` and returns them in the given format. |
| 238 | func CollectAndFormat(c prometheus.Collector, format expfmt.FormatType, metricNames ...string) ([]byte, error) { |
no test coverage detected