mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #85640 from RainbowMango/pr_track_collector_by_name
Track collectors by fqName
This commit is contained in:
commit
98abd32ee5
@ -41,7 +41,7 @@ func NewCounter(opts *CounterOpts) *Counter {
|
|||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
kc.setPrometheusCounter(noop)
|
kc.setPrometheusCounter(noop)
|
||||||
kc.lazyInit(kc)
|
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return kc
|
return kc
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
|
|||||||
originalLabels: labels,
|
originalLabels: labels,
|
||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
cv.lazyInit(cv)
|
cv.lazyInit(cv, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return cv
|
return cv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func NewGauge(opts *GaugeOpts) *Gauge {
|
|||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
kc.setPrometheusGauge(noop)
|
kc.setPrometheusGauge(noop)
|
||||||
kc.lazyInit(kc)
|
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return kc
|
return kc
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func NewGaugeVec(opts *GaugeOpts, labels []string) *GaugeVec {
|
|||||||
originalLabels: labels,
|
originalLabels: labels,
|
||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
cv.lazyInit(cv)
|
cv.lazyInit(cv, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return cv
|
return cv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func NewHistogram(opts *HistogramOpts) *Histogram {
|
|||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
h.setPrometheusHistogram(noopMetric{})
|
h.setPrometheusHistogram(noopMetric{})
|
||||||
h.lazyInit(h)
|
h.lazyInit(h, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ func NewHistogramVec(opts *HistogramOpts, labels []string) *HistogramVec {
|
|||||||
originalLabels: labels,
|
originalLabels: labels,
|
||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
v.lazyInit(v)
|
v.lazyInit(v, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ implements kubeCollector to get deferred registration behavior. You must call la
|
|||||||
with the kubeCollector itself as an argument.
|
with the kubeCollector itself as an argument.
|
||||||
*/
|
*/
|
||||||
type lazyMetric struct {
|
type lazyMetric struct {
|
||||||
|
fqName string
|
||||||
isDeprecated bool
|
isDeprecated bool
|
||||||
isHidden bool
|
isHidden bool
|
||||||
isCreated bool
|
isCreated bool
|
||||||
@ -81,7 +82,8 @@ func (r *lazyMetric) IsCreated() bool {
|
|||||||
// lazyInit provides the lazyMetric with a reference to the kubeCollector it is supposed
|
// lazyInit provides the lazyMetric with a reference to the kubeCollector it is supposed
|
||||||
// to allow lazy initialization for. It should be invoked in the factory function which creates new
|
// to allow lazy initialization for. It should be invoked in the factory function which creates new
|
||||||
// kubeCollector type objects.
|
// kubeCollector type objects.
|
||||||
func (r *lazyMetric) lazyInit(self kubeCollector) {
|
func (r *lazyMetric) lazyInit(self kubeCollector, fqName string) {
|
||||||
|
r.fqName = fqName
|
||||||
r.self = self
|
r.self = self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ func (r *lazyMetric) determineDeprecationStatus(version semver.Version) {
|
|||||||
r.isDeprecated = true
|
r.isDeprecated = true
|
||||||
}
|
}
|
||||||
if ShouldShowHidden() {
|
if ShouldShowHidden() {
|
||||||
klog.Warningf("Hidden metrics have been manually overridden, showing this very deprecated metric.")
|
klog.Warningf("Hidden metrics (%s) have been manually overridden, showing this very deprecated metric.", r.fqName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if shouldHide(&version, selfVersion) {
|
if shouldHide(&version, selfVersion) {
|
||||||
@ -156,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.
|
||||||
@ -245,8 +248,9 @@ func (kr *kubeRegistry) enableHiddenCollectors() {
|
|||||||
|
|
||||||
func newKubeRegistry(v apimachineryversion.Info) *kubeRegistry {
|
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()
|
||||||
|
@ -44,7 +44,7 @@ func NewSummary(opts *SummaryOpts) *Summary {
|
|||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
s.setPrometheusSummary(noopMetric{})
|
s.setPrometheusSummary(noopMetric{})
|
||||||
s.lazyInit(s)
|
s.lazyInit(s, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ func NewSummaryVec(opts *SummaryOpts, labels []string) *SummaryVec {
|
|||||||
originalLabels: labels,
|
originalLabels: labels,
|
||||||
lazyMetric: lazyMetric{},
|
lazyMetric: lazyMetric{},
|
||||||
}
|
}
|
||||||
v.lazyInit(v)
|
v.lazyInit(v, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user