@@ -21,24 +21,24 @@ import (
21
21
"github.com/prometheus/client_golang/prometheus"
22
22
)
23
23
24
- // kubeCounter is our internal representation for our wrapping struct around prometheus
25
- // counters. kubeCounter implements both KubeCollector and KubeCounter .
26
- type kubeCounter struct {
27
- KubeCounter
24
+ // Counter is our internal representation for our wrapping struct around prometheus
25
+ // counters. Counter implements both KubeCollector and CounterMetric .
26
+ type Counter struct {
27
+ CounterMetric
28
28
* CounterOpts
29
29
lazyMetric
30
30
selfCollector
31
31
}
32
32
33
- // NewCounter returns an object which satisfies the KubeCollector and KubeCounter interfaces.
33
+ // NewCounter returns an object which satisfies the KubeCollector and CounterMetric interfaces.
34
34
// However, the object returned will not measure anything unless the collector is first
35
35
// registered, since the metric is lazily instantiated.
36
- func NewCounter (opts * CounterOpts ) * kubeCounter {
36
+ func NewCounter (opts * CounterOpts ) * Counter {
37
37
// todo: handle defaulting better
38
38
if opts .StabilityLevel == "" {
39
39
opts .StabilityLevel = ALPHA
40
40
}
41
- kc := & kubeCounter {
41
+ kc := & Counter {
42
42
CounterOpts : opts ,
43
43
lazyMetric : lazyMetric {},
44
44
}
@@ -47,46 +47,46 @@ func NewCounter(opts *CounterOpts) *kubeCounter {
47
47
return kc
48
48
}
49
49
50
- // setPrometheusCounter sets the underlying KubeCounter object, i.e. the thing that does the measurement.
51
- func (c * kubeCounter ) setPrometheusCounter (counter prometheus.Counter ) {
52
- c .KubeCounter = counter
50
+ // setPrometheusCounter sets the underlying CounterMetric object, i.e. the thing that does the measurement.
51
+ func (c * Counter ) setPrometheusCounter (counter prometheus.Counter ) {
52
+ c .CounterMetric = counter
53
53
c .initSelfCollection (counter )
54
54
}
55
55
56
56
// DeprecatedVersion returns a pointer to the Version or nil
57
- func (c * kubeCounter ) DeprecatedVersion () * semver.Version {
57
+ func (c * Counter ) DeprecatedVersion () * semver.Version {
58
58
return c .CounterOpts .DeprecatedVersion
59
59
}
60
60
61
61
// initializeMetric invocation creates the actual underlying Counter. Until this method is called
62
62
// the underlying counter is a no-op.
63
- func (c * kubeCounter ) initializeMetric () {
63
+ func (c * Counter ) initializeMetric () {
64
64
c .CounterOpts .annotateStabilityLevel ()
65
65
// this actually creates the underlying prometheus counter.
66
66
c .setPrometheusCounter (prometheus .NewCounter (c .CounterOpts .toPromCounterOpts ()))
67
67
}
68
68
69
69
// initializeDeprecatedMetric invocation creates the actual (but deprecated) Counter. Until this method
70
70
// is called the underlying counter is a no-op.
71
- func (c * kubeCounter ) initializeDeprecatedMetric () {
71
+ func (c * Counter ) initializeDeprecatedMetric () {
72
72
c .CounterOpts .markDeprecated ()
73
73
c .initializeMetric ()
74
74
}
75
75
76
- // kubeCounterVec is the internal representation of our wrapping struct around prometheus
77
- // counterVecs. kubeCounterVec implements both KubeCollector and KubeCounterVec .
78
- type kubeCounterVec struct {
76
+ // CounterVec is the internal representation of our wrapping struct around prometheus
77
+ // counterVecs. CounterVec implements both KubeCollector and CounterVecMetric .
78
+ type CounterVec struct {
79
79
* prometheus.CounterVec
80
80
* CounterOpts
81
81
lazyMetric
82
82
originalLabels []string
83
83
}
84
84
85
- // NewCounterVec returns an object which satisfies the KubeCollector and KubeCounterVec interfaces.
85
+ // NewCounterVec returns an object which satisfies the KubeCollector and CounterVecMetric interfaces.
86
86
// However, the object returned will not measure anything unless the collector is first
87
87
// registered, since the metric is lazily instantiated.
88
- func NewCounterVec (opts * CounterOpts , labels []string ) * kubeCounterVec {
89
- cv := & kubeCounterVec {
88
+ func NewCounterVec (opts * CounterOpts , labels []string ) * CounterVec {
89
+ cv := & CounterVec {
90
90
CounterVec : noopCounterVec ,
91
91
CounterOpts : opts ,
92
92
originalLabels : labels ,
@@ -97,19 +97,19 @@ func NewCounterVec(opts *CounterOpts, labels []string) *kubeCounterVec {
97
97
}
98
98
99
99
// DeprecatedVersion returns a pointer to the Version or nil
100
- func (v * kubeCounterVec ) DeprecatedVersion () * semver.Version {
100
+ func (v * CounterVec ) DeprecatedVersion () * semver.Version {
101
101
return v .CounterOpts .DeprecatedVersion
102
102
}
103
103
104
104
// initializeMetric invocation creates the actual underlying CounterVec. Until this method is called
105
105
// the underlying counterVec is a no-op.
106
- func (v * kubeCounterVec ) initializeMetric () {
106
+ func (v * CounterVec ) initializeMetric () {
107
107
v .CounterVec = prometheus .NewCounterVec (v .CounterOpts .toPromCounterOpts (), v .originalLabels )
108
108
}
109
109
110
110
// initializeDeprecatedMetric invocation creates the actual (but deprecated) CounterVec. Until this method is called
111
111
// the underlying counterVec is a no-op.
112
- func (v * kubeCounterVec ) initializeDeprecatedMetric () {
112
+ func (v * CounterVec ) initializeDeprecatedMetric () {
113
113
v .CounterOpts .markDeprecated ()
114
114
v .initializeMetric ()
115
115
}
@@ -121,17 +121,23 @@ func (v *kubeCounterVec) initializeDeprecatedMetric() {
121
121
// for perpetuity (i.e. throughout application lifecycle).
122
122
//
123
123
// For reference: https://github.com/prometheus/client_golang/blob/v0.9.2/prometheus/counter.go#L179-L197
124
- //
125
- // This method returns a no-op metric if the metric is not actually created/registered, avoiding that
126
- // memory leak.
127
- func (v * kubeCounterVec ) WithLabelValues (lvs ... string ) KubeCounter {
124
+
125
+ // WithLabelValues returns the Counter for the given slice of label
126
+ // values (same order as the VariableLabels in Desc). If that combination of
127
+ // label values is accessed for the first time, a new Counter is created IFF the counterVec
128
+ // has been registered to a metrics registry.
129
+ func (v * CounterVec ) WithLabelValues (lvs ... string ) CounterMetric {
128
130
if ! v .IsCreated () {
129
131
return noop // return no-op counter
130
132
}
131
133
return v .CounterVec .WithLabelValues (lvs ... )
132
134
}
133
135
134
- func (v * kubeCounterVec ) With (labels prometheus.Labels ) KubeCounter {
136
+ // With returns the Counter for the given Labels map (the label names
137
+ // must match those of the VariableLabels in Desc). If that label map is
138
+ // accessed for the first time, a new Counter is created IFF the counterVec has
139
+ // been registered to a metrics registry.
140
+ func (v * CounterVec ) With (labels prometheus.Labels ) CounterMetric {
135
141
if ! v .IsCreated () {
136
142
return noop // return no-op counter
137
143
}
0 commit comments