Skip to content

Commit b9ef1ce

Browse files
committed
lazyInit accepts fqName when init.
1 parent 91aa8df commit b9ef1ce

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

staging/src/k8s.io/component-base/metrics/counter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewCounter(opts *CounterOpts) *Counter {
4141
lazyMetric: lazyMetric{},
4242
}
4343
kc.setPrometheusCounter(noop)
44-
kc.lazyInit(kc)
44+
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
4545
return kc
4646
}
4747

@@ -92,7 +92,7 @@ func NewCounterVec(opts *CounterOpts, labels []string) *CounterVec {
9292
originalLabels: labels,
9393
lazyMetric: lazyMetric{},
9494
}
95-
cv.lazyInit(cv)
95+
cv.lazyInit(cv, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
9696
return cv
9797
}
9898

staging/src/k8s.io/component-base/metrics/gauge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewGauge(opts *GaugeOpts) *Gauge {
4343
lazyMetric: lazyMetric{},
4444
}
4545
kc.setPrometheusGauge(noop)
46-
kc.lazyInit(kc)
46+
kc.lazyInit(kc, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
4747
return kc
4848
}
4949

@@ -94,7 +94,7 @@ func NewGaugeVec(opts *GaugeOpts, labels []string) *GaugeVec {
9494
originalLabels: labels,
9595
lazyMetric: lazyMetric{},
9696
}
97-
cv.lazyInit(cv)
97+
cv.lazyInit(cv, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
9898
return cv
9999
}
100100

staging/src/k8s.io/component-base/metrics/histogram.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewHistogram(opts *HistogramOpts) *Histogram {
5353
lazyMetric: lazyMetric{},
5454
}
5555
h.setPrometheusHistogram(noopMetric{})
56-
h.lazyInit(h)
56+
h.lazyInit(h, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
5757
return h
5858
}
5959

@@ -104,7 +104,7 @@ func NewHistogramVec(opts *HistogramOpts, labels []string) *HistogramVec {
104104
originalLabels: labels,
105105
lazyMetric: lazyMetric{},
106106
}
107-
v.lazyInit(v)
107+
v.lazyInit(v, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
108108
return v
109109
}
110110

staging/src/k8s.io/component-base/metrics/metric.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ implements kubeCollector to get deferred registration behavior. You must call la
6363
with the kubeCollector itself as an argument.
6464
*/
6565
type lazyMetric struct {
66+
fqName string
6667
isDeprecated bool
6768
isHidden bool
6869
isCreated bool
@@ -81,7 +82,8 @@ func (r *lazyMetric) IsCreated() bool {
8182
// lazyInit provides the lazyMetric with a reference to the kubeCollector it is supposed
8283
// to allow lazy initialization for. It should be invoked in the factory function which creates new
8384
// kubeCollector type objects.
84-
func (r *lazyMetric) lazyInit(self kubeCollector) {
85+
func (r *lazyMetric) lazyInit(self kubeCollector, fqName string) {
86+
r.fqName = fqName
8587
r.self = self
8688
}
8789

@@ -98,7 +100,7 @@ func (r *lazyMetric) determineDeprecationStatus(version semver.Version) {
98100
r.isDeprecated = true
99101
}
100102
if ShouldShowHidden() {
101-
klog.Warningf("Hidden metrics have been manually overridden, showing this very deprecated metric.")
103+
klog.Warningf("Hidden metrics (%s) have been manually overridden, showing this very deprecated metric.", r.fqName)
102104
return
103105
}
104106
if shouldHide(&version, selfVersion) {

staging/src/k8s.io/component-base/metrics/summary.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func NewSummary(opts *SummaryOpts) *Summary {
4444
lazyMetric: lazyMetric{},
4545
}
4646
s.setPrometheusSummary(noopMetric{})
47-
s.lazyInit(s)
47+
s.lazyInit(s, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
4848
return s
4949
}
5050

@@ -98,7 +98,7 @@ func NewSummaryVec(opts *SummaryOpts, labels []string) *SummaryVec {
9898
originalLabels: labels,
9999
lazyMetric: lazyMetric{},
100100
}
101-
v.lazyInit(v)
101+
v.lazyInit(v, BuildFQName(opts.Namespace, opts.Subsystem, opts.Name))
102102
return v
103103
}
104104

0 commit comments

Comments
 (0)