lazyInit accepts fqName when init.

This commit is contained in:
RainbowMango 2019-11-18 10:20:29 +08:00
parent 91aa8dfec8
commit b9ef1ce87e
5 changed files with 12 additions and 10 deletions

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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
} }

View File

@ -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) {

View File

@ -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
} }