@@ -158,6 +158,9 @@ func GatherAndCount(g prometheus.Gatherer, metricNames ...string) (int, error) {
158
158
// ScrapeAndCompare calls a remote exporter's endpoint which is expected to return some metrics in
159
159
// plain text format. Then it compares it with the results that the `expected` would return.
160
160
// If the `metricNames` is not empty it would filter the comparison only to the given metric names.
161
+ //
162
+ // NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter
163
+ // both expected and scraped metrics. See https://github.com/prometheus/client_golang/issues/1351.
161
164
func ScrapeAndCompare (url string , expected io.Reader , metricNames ... string ) error {
162
165
resp , err := http .Get (url )
163
166
if err != nil {
@@ -185,6 +188,9 @@ func ScrapeAndCompare(url string, expected io.Reader, metricNames ...string) err
185
188
186
189
// CollectAndCompare collects the metrics identified by `metricNames` and compares them in the Prometheus text
187
190
// exposition format to the data read from expected.
191
+ //
192
+ // NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter
193
+ // both expected and collected metrics. See https://github.com/prometheus/client_golang/issues/1351.
188
194
func CollectAndCompare (c prometheus.Collector , expected io.Reader , metricNames ... string ) error {
189
195
reg := prometheus .NewPedanticRegistry ()
190
196
if err := reg .Register (c ); err != nil {
@@ -197,6 +203,9 @@ func CollectAndCompare(c prometheus.Collector, expected io.Reader, metricNames .
197
203
// it to an expected output read from the provided Reader in the Prometheus text
198
204
// exposition format. If any metricNames are provided, only metrics with those
199
205
// names are compared.
206
+ //
207
+ // NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter
208
+ // both expected and gathered metrics. See https://github.com/prometheus/client_golang/issues/1351.
200
209
func GatherAndCompare (g prometheus.Gatherer , expected io.Reader , metricNames ... string ) error {
201
210
return TransactionalGatherAndCompare (prometheus .ToTransactionalGatherer (g ), expected , metricNames ... )
202
211
}
@@ -205,6 +214,9 @@ func GatherAndCompare(g prometheus.Gatherer, expected io.Reader, metricNames ...
205
214
// it to an expected output read from the provided Reader in the Prometheus text
206
215
// exposition format. If any metricNames are provided, only metrics with those
207
216
// names are compared.
217
+ //
218
+ // NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter
219
+ // both expected and gathered metrics. See https://github.com/prometheus/client_golang/issues/1351.
208
220
func TransactionalGatherAndCompare (g prometheus.TransactionalGatherer , expected io.Reader , metricNames ... string ) error {
209
221
got , done , err := g .Gather ()
210
222
defer done ()
0 commit comments