mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: bump github.com/prometheus/client_golang
Bumps the github-dependencies group with 1 update: [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang). Updates `github.com/prometheus/client_golang` from 1.20.4 to 1.20.5 - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.20.4...v1.20.5) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
512bba485b
commit
52fcb7b00c
30
vendor/github.com/prometheus/client_golang/prometheus/testutil/testutil.go
generated
vendored
30
vendor/github.com/prometheus/client_golang/prometheus/testutil/testutil.go
generated
vendored
@ -158,6 +158,9 @@ func GatherAndCount(g prometheus.Gatherer, metricNames ...string) (int, error) {
|
||||
// ScrapeAndCompare calls a remote exporter's endpoint which is expected to return some metrics in
|
||||
// plain text format. Then it compares it with the results that the `expected` would return.
|
||||
// If the `metricNames` is not empty it would filter the comparison only to the given metric names.
|
||||
//
|
||||
// NOTE: Be mindful of accidental discrepancies between expected and metricNames; metricNames filter
|
||||
// both expected and scraped metrics. See https://github.com/prometheus/client_golang/issues/1351.
|
||||
func ScrapeAndCompare(url string, expected io.Reader, metricNames ...string) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
@ -185,6 +188,9 @@ func ScrapeAndCompare(url string, expected io.Reader, metricNames ...string) err
|
||||
|
||||
// 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 https://github.com/prometheus/client_golang/issues/1351.
|
||||
func CollectAndCompare(c prometheus.Collector, expected io.Reader, metricNames ...string) error {
|
||||
reg := prometheus.NewPedanticRegistry()
|
||||
if err := reg.Register(c); err != nil {
|
||||
@ -197,6 +203,9 @@ func CollectAndCompare(c prometheus.Collector, expected io.Reader, metricNames .
|
||||
// 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 discrepancies between expected and metricNames; metricNames filter
|
||||
// both expected and gathered metrics. See https://github.com/prometheus/client_golang/issues/1351.
|
||||
func GatherAndCompare(g prometheus.Gatherer, expected io.Reader, metricNames ...string) error {
|
||||
return TransactionalGatherAndCompare(prometheus.ToTransactionalGatherer(g), expected, metricNames...)
|
||||
}
|
||||
@ -205,6 +214,9 @@ func GatherAndCompare(g prometheus.Gatherer, expected io.Reader, metricNames ...
|
||||
// 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 discrepancies between expected and metricNames; metricNames filter
|
||||
// both expected and gathered metrics. See https://github.com/prometheus/client_golang/issues/1351.
|
||||
func TransactionalGatherAndCompare(g prometheus.TransactionalGatherer, expected io.Reader, metricNames ...string) error {
|
||||
got, done, err := g.Gather()
|
||||
defer done()
|
||||
@ -277,15 +289,6 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str
|
||||
if metricNames != nil {
|
||||
got = filterMetrics(got, metricNames)
|
||||
expected = filterMetrics(expected, metricNames)
|
||||
if len(metricNames) > len(got) {
|
||||
var missingMetricNames []string
|
||||
for _, name := range metricNames {
|
||||
if ok := hasMetricByName(got, name); !ok {
|
||||
missingMetricNames = append(missingMetricNames, name)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("expected metric name(s) not found: %v", missingMetricNames)
|
||||
}
|
||||
}
|
||||
|
||||
return compare(got, expected)
|
||||
@ -327,12 +330,3 @@ func filterMetrics(metrics []*dto.MetricFamily, names []string) []*dto.MetricFam
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func hasMetricByName(metrics []*dto.MetricFamily, name string) bool {
|
||||
for _, mf := range metrics {
|
||||
if mf.GetName() == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user