Skip to content

Commit 04a1a01

Browse files
MikeSpreitzerk8s-publishing-bot
authored andcommitted
More revisions after review
Kubernetes-commit: d23254b7ea1bef8982aeef5039803b6987f4c144
1 parent a12867e commit 04a1a01

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

metrics/gauge.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ func (v *GaugeVec) initializeDeprecatedMetric() {
141141
}
142142

143143
func (v *GaugeVec) WithLabelValuesChecked(lvs ...string) (GaugeMetric, error) {
144-
if v.IsHidden() {
145-
return noop, nil
146-
}
147144
if !v.IsCreated() {
145+
if v.IsHidden() {
146+
return noop, nil
147+
}
148148
return noop, errNotRegistered // return no-op gauge
149149
}
150150
if v.LabelValueAllowLists != nil {
@@ -178,10 +178,10 @@ func (v *GaugeVec) WithLabelValues(lvs ...string) GaugeMetric {
178178
}
179179

180180
func (v *GaugeVec) WithChecked(labels map[string]string) (GaugeMetric, error) {
181-
if v.IsHidden() {
182-
return noop, nil
183-
}
184181
if !v.IsCreated() {
182+
if v.IsHidden() {
183+
return noop, nil
184+
}
185185
return noop, errNotRegistered // return no-op gauge
186186
}
187187
if v.LabelValueAllowLists != nil {

metrics/timing_histogram.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ import (
2424
promext "k8s.io/component-base/metrics/prometheusextension"
2525
)
2626

27-
// TimingHistogram is our internal representation for our wrapping struct around timing
28-
// histograms. It implements both kubeCollector and GaugeMetric
29-
type TimingHistogram struct {
27+
// PrometheusTimingHistogram is the abstraction of the underlying histogram
28+
// that we want to promote from the wrapper.
29+
type PrometheusTimingHistogram interface {
3030
GaugeMetric
31+
}
32+
33+
// TimingHistogram is our internal representation for our wrapping struct around
34+
// timing histograms. It implements both kubeCollector and GaugeMetric
35+
type TimingHistogram struct {
36+
PrometheusTimingHistogram
3137
*TimingHistogramOpts
3238
nowFunc func() time.Time
3339
lazyMetric
@@ -60,7 +66,7 @@ func NewTestableTimingHistogram(nowFunc func() time.Time, opts *TimingHistogramO
6066

6167
// setPrometheusHistogram sets the underlying KubeGauge object, i.e. the thing that does the measurement.
6268
func (h *TimingHistogram) setPrometheusHistogram(histogram promext.TimingHistogram) {
63-
h.GaugeMetric = histogram
69+
h.PrometheusTimingHistogram = histogram
6470
h.initSelfCollection(histogram)
6571
}
6672

@@ -90,7 +96,7 @@ func (h *TimingHistogram) initializeDeprecatedMetric() {
9096

9197
// WithContext allows the normal TimingHistogram metric to pass in context. The context is no-op now.
9298
func (h *TimingHistogram) WithContext(ctx context.Context) GaugeMetric {
93-
return h.GaugeMetric
99+
return h.PrometheusTimingHistogram
94100
}
95101

96102
// TimingHistogramVec is the internal representation of our wrapping struct around prometheus
@@ -151,20 +157,20 @@ func (v *TimingHistogramVec) initializeDeprecatedMetric() {
151157
v.initializeMetric()
152158
}
153159

154-
// WithLabelValuesChecked, if called on a hidden vector,
155-
// will return a noop gauge and a nil error.
156-
// If called before this vector has been registered in
160+
// WithLabelValuesChecked, if called before this vector has been registered in
157161
// at least one registry, will return a noop gauge and
158162
// an error that passes ErrIsNotRegistered.
163+
// If called on a hidden vector,
164+
// will return a noop gauge and a nil error.
159165
// If called with a syntactic problem in the labels, will
160166
// return a noop gauge and an error about the labels.
161167
// If none of the above apply, this method will return
162168
// the appropriate vector member and a nil error.
163169
func (v *TimingHistogramVec) WithLabelValuesChecked(lvs ...string) (GaugeMetric, error) {
164-
if v.IsHidden() {
165-
return noop, nil
166-
}
167170
if !v.IsCreated() {
171+
if v.IsHidden() {
172+
return noop, nil
173+
}
168174
return noop, errNotRegistered
169175
}
170176
if v.LabelValueAllowLists != nil {
@@ -187,20 +193,20 @@ func (v *TimingHistogramVec) WithLabelValues(lvs ...string) GaugeMetric {
187193
panic(err)
188194
}
189195

190-
// WithChecked, if called on a hidden vector,
191-
// will return a noop gauge and a nil error.
192-
// If called before this vector has been registered in
196+
// WithChecked, if called before this vector has been registered in
193197
// at least one registry, will return a noop gauge and
194198
// an error that passes ErrIsNotRegistered.
199+
// If called on a hidden vector,
200+
// will return a noop gauge and a nil error.
195201
// If called with a syntactic problem in the labels, will
196202
// return a noop gauge and an error about the labels.
197203
// If none of the above apply, this method will return
198204
// the appropriate vector member and a nil error.
199205
func (v *TimingHistogramVec) WithChecked(labels map[string]string) (GaugeMetric, error) {
200-
if v.IsHidden() {
201-
return noop, nil
202-
}
203206
if !v.IsCreated() {
207+
if v.IsHidden() {
208+
return noop, nil
209+
}
204210
return noop, errNotRegistered
205211
}
206212
if v.LabelValueAllowLists != nil {

metrics/timing_histogram_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func TestTimingHistogram(t *testing.T) {
102102
}()
103103
m1 := <-metricChan
104104
gm1, ok := m1.(GaugeMetric)
105-
if !ok || gm1 != c.GaugeMetric {
106-
t.Error("Unexpected metric", m1, c.GaugeMetric)
105+
if !ok || gm1 != c.PrometheusTimingHistogram {
106+
t.Error("Unexpected metric", m1, c.PrometheusTimingHistogram)
107107
}
108108
m2, ok := <-metricChan
109109
if ok {

metrics/wrappers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ type GaugeVecMetric interface {
8080
// In contrast, the Vec behavior in this package is that member extraction before registration
8181
// returns a permanent noop object.
8282

83-
// WithLabelValuesChecked, if called on a hidden vector,
84-
// will return a noop gauge and a nil error.
85-
// If called before this vector has been registered in
83+
// WithLabelValuesChecked, if called before this vector has been registered in
8684
// at least one registry, will return a noop gauge and
8785
// an error that passes ErrIsNotRegistered.
86+
// If called on a hidden vector,
87+
// will return a noop gauge and a nil error.
8888
// If called with a syntactic problem in the labels, will
8989
// return a noop gauge and an error about the labels.
9090
// If none of the above apply, this method will return
@@ -98,11 +98,11 @@ type GaugeVecMetric interface {
9898
// all other errors cause a panic.
9999
WithLabelValues(labelValues ...string) GaugeMetric
100100

101-
// WithChecked, if called on a hidden vector,
102-
// will return a noop gauge and a nil error.
103-
// If called before this vector has been registered in
101+
// WithChecked, if called before this vector has been registered in
104102
// at least one registry, will return a noop gauge and
105103
// an error that passes ErrIsNotRegistered.
104+
// If called on a hidden vector,
105+
// will return a noop gauge and a nil error.
106106
// If called with a syntactic problem in the labels, will
107107
// return a noop gauge and an error about the labels.
108108
// If none of the above apply, this method will return

0 commit comments

Comments
 (0)