mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Introduce testutil package to support metrics testing.
This commit is contained in:
parent
29f23e6647
commit
159163247e
@ -26,7 +26,7 @@ import (
|
||||
var (
|
||||
defaultRegistry = metrics.NewKubeRegistry()
|
||||
// DefaultGatherer exposes the global registry gatherer
|
||||
DefaultGatherer prometheus.Gatherer = defaultRegistry
|
||||
DefaultGatherer metrics.Gatherer = defaultRegistry
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||
|
||||
"k8s.io/component-base/metrics"
|
||||
)
|
||||
|
||||
// GatherAndCompare 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.
|
||||
func GatherAndCompare(g metrics.Gatherer, expected io.Reader, metricNames ...string) error {
|
||||
return testutil.GatherAndCompare(g, expected, metricNames...)
|
||||
}
|
@ -79,3 +79,9 @@ type PromRegistry interface {
|
||||
Unregister(prometheus.Collector) bool
|
||||
Gather() ([]*dto.MetricFamily, error)
|
||||
}
|
||||
|
||||
// Gatherer is the interface for the part of a registry in charge of gathering
|
||||
// the collected metrics into a number of MetricFamilies.
|
||||
type Gatherer interface {
|
||||
prometheus.Gatherer
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user