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

Function TransactionalGatherAndCompare

prometheus/testutil/testutil.go:222–235  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
222func 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.
238func CollectAndFormat(c prometheus.Collector, format expfmt.FormatType, metricNames ...string) ([]byte, error) {

Callers 1

GatherAndCompareFunction · 0.85

Calls 3

compareMetricFamiliesFunction · 0.85
GatherMethod · 0.65

Tested by

no test coverage detected