mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Extend Registerable interface with FQName() and track collector by name.
This commit is contained in:
parent
b9ef1ce87e
commit
4d028a7903
@ -158,6 +158,11 @@ func (r *lazyMetric) ClearState() {
|
|||||||
r.createOnce = *(new(sync.Once))
|
r.createOnce = *(new(sync.Once))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FQName returns the fully-qualified metric name of the collector.
|
||||||
|
func (r *lazyMetric) FQName() string {
|
||||||
|
return r.fqName
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This code is directly lifted from the prometheus codebase. It's a convenience struct which
|
This code is directly lifted from the prometheus codebase. It's a convenience struct which
|
||||||
allows you satisfy the Collector interface automatically if you already satisfy the Metric interface.
|
allows you satisfy the Collector interface automatically if you already satisfy the Metric interface.
|
||||||
|
@ -104,6 +104,9 @@ type Registerable interface {
|
|||||||
|
|
||||||
// ClearState will clear all the states marked by Create.
|
// ClearState will clear all the states marked by Create.
|
||||||
ClearState()
|
ClearState()
|
||||||
|
|
||||||
|
// FQName returns the fully-qualified metric name of the collector.
|
||||||
|
FQName() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// KubeRegistry is an interface which implements a subset of prometheus.Registerer and
|
// KubeRegistry is an interface which implements a subset of prometheus.Registerer and
|
||||||
@ -127,7 +130,7 @@ type KubeRegistry interface {
|
|||||||
type kubeRegistry struct {
|
type kubeRegistry struct {
|
||||||
PromRegistry
|
PromRegistry
|
||||||
version semver.Version
|
version semver.Version
|
||||||
hiddenCollectors []Registerable // stores all collectors that has been hidden
|
hiddenCollectors map[string]Registerable // stores all collectors that has been hidden
|
||||||
hiddenCollectorsLock sync.RWMutex
|
hiddenCollectorsLock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +231,7 @@ func (kr *kubeRegistry) trackHiddenCollector(c Registerable) {
|
|||||||
kr.hiddenCollectorsLock.Lock()
|
kr.hiddenCollectorsLock.Lock()
|
||||||
defer kr.hiddenCollectorsLock.Unlock()
|
defer kr.hiddenCollectorsLock.Unlock()
|
||||||
|
|
||||||
kr.hiddenCollectors = append(kr.hiddenCollectors, c)
|
kr.hiddenCollectors[c.FQName()] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
// enableHiddenCollectors will re-register all of the hidden collectors.
|
// enableHiddenCollectors will re-register all of the hidden collectors.
|
||||||
@ -247,6 +250,7 @@ func newKubeRegistry(v apimachineryversion.Info) *kubeRegistry {
|
|||||||
r := &kubeRegistry{
|
r := &kubeRegistry{
|
||||||
PromRegistry: prometheus.NewRegistry(),
|
PromRegistry: prometheus.NewRegistry(),
|
||||||
version: parseVersion(v),
|
version: parseVersion(v),
|
||||||
|
hiddenCollectors: make(map[string]Registerable),
|
||||||
}
|
}
|
||||||
|
|
||||||
registriesLock.Lock()
|
registriesLock.Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user