mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Add CustomCollectAndCompare to testutils which especially for custom collector
Add GetRawDesc() to Desc.
This commit is contained in:
parent
695c3061dd
commit
1b01a5eb9b
@ -18,6 +18,7 @@ package metrics
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/blang/semver"
|
"github.com/blang/semver"
|
||||||
@ -156,3 +157,16 @@ func (d *Desc) initializeDeprecatedDesc() {
|
|||||||
d.markDeprecated()
|
d.markDeprecated()
|
||||||
d.initialize()
|
d.initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRawDesc will returns a new *Desc with original parameters provided to NewDesc().
|
||||||
|
//
|
||||||
|
// It will be useful in testing scenario that the same Desc be registered to different registry.
|
||||||
|
// 1. Desc `D` is registered to registry 'A' in TestA (Note: `D` maybe created)
|
||||||
|
// 2. Desc `D` is registered to registry 'B' in TestB (Note: since 'D' has been created once, thus will be ignored by registry 'B')
|
||||||
|
func (d *Desc) GetRawDesc() *Desc {
|
||||||
|
// remove stability from help if any
|
||||||
|
stabilityStr := fmt.Sprintf("[%v] ", d.stabilityLevel)
|
||||||
|
rawHelp := strings.Replace(d.help, stabilityStr, "", -1)
|
||||||
|
|
||||||
|
return NewDesc(d.fqName, rawHelp, d.variableLabels, d.constLabels, d.stabilityLevel, d.deprecatedVersion)
|
||||||
|
}
|
||||||
|
@ -38,3 +38,13 @@ func CollectAndCompare(c metrics.Collector, expected io.Reader, metricNames ...s
|
|||||||
func GatherAndCompare(g metrics.Gatherer, expected io.Reader, metricNames ...string) error {
|
func GatherAndCompare(g metrics.Gatherer, expected io.Reader, metricNames ...string) error {
|
||||||
return testutil.GatherAndCompare(g, expected, metricNames...)
|
return testutil.GatherAndCompare(g, expected, metricNames...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CustomCollectAndCompare registers the provided StableCollector with a newly created
|
||||||
|
// registry. It then does the same as GatherAndCompare, gathering the
|
||||||
|
// metrics from the pedantic Registry.
|
||||||
|
func CustomCollectAndCompare(c metrics.StableCollector, expected io.Reader, metricNames ...string) error {
|
||||||
|
registry := metrics.NewKubeRegistry()
|
||||||
|
registry.CustomMustRegister(c)
|
||||||
|
|
||||||
|
return GatherAndCompare(registry, expected, metricNames...)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user