Skip to content

Commit e0ebd44

Browse files
committed
feat(metrics): Add method to reset label allow lists
Adds a new method `ResetLabelAllowLists` to various metric types, allowing for the reset of label allow lists. This is intended specifically for use in testing scenarios.
1 parent 5826868 commit e0ebd44

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"context"
21+
"sync"
2122

2223
"github.com/blang/semver/v4"
2324
"github.com/prometheus/client_golang/prometheus"
@@ -249,6 +250,13 @@ func (v *CounterVec) Reset() {
249250
v.CounterVec.Reset()
250251
}
251252

253+
// ResetLabelAllowLists resets the label allow list for the CounterVec.
254+
// NOTE: This should only be used in test.
255+
func (v *CounterVec) ResetLabelAllowLists() {
256+
v.initializeLabelAllowListsOnce = sync.Once{}
257+
v.LabelValueAllowLists = nil
258+
}
259+
252260
// WithContext returns wrapped CounterVec with context
253261
func (v *CounterVec) WithContext(ctx context.Context) *CounterVecWithContext {
254262
return &CounterVecWithContext{

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"context"
21+
"sync"
2122

2223
"github.com/blang/semver/v4"
2324
"github.com/prometheus/client_golang/prometheus"
@@ -239,6 +240,13 @@ func (v *GaugeVec) Reset() {
239240
v.GaugeVec.Reset()
240241
}
241242

243+
// ResetLabelAllowLists resets the label allow list for the GaugeVec.
244+
// NOTE: This should only be used in test.
245+
func (v *GaugeVec) ResetLabelAllowLists() {
246+
v.initializeLabelAllowListsOnce = sync.Once{}
247+
v.LabelValueAllowLists = nil
248+
}
249+
242250
func newGaugeFunc(opts *GaugeOpts, function func() float64, v semver.Version) GaugeFunc {
243251
g := NewGauge(opts)
244252

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"context"
21+
"sync"
2122

2223
"github.com/blang/semver/v4"
2324
"github.com/prometheus/client_golang/prometheus"
@@ -202,6 +203,13 @@ func (v *HistogramVec) Reset() {
202203
v.HistogramVec.Reset()
203204
}
204205

206+
// ResetLabelAllowLists resets the label allow list for the HistogramVec.
207+
// NOTE: This should only be used in test.
208+
func (v *HistogramVec) ResetLabelAllowLists() {
209+
v.initializeLabelAllowListsOnce = sync.Once{}
210+
v.LabelValueAllowLists = nil
211+
}
212+
205213
// WithContext returns wrapped HistogramVec with context
206214
func (v *HistogramVec) WithContext(ctx context.Context) *HistogramVecWithContext {
207215
return &HistogramVecWithContext{

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"context"
21+
"sync"
2122

2223
"github.com/blang/semver/v4"
2324
"github.com/prometheus/client_golang/prometheus"
@@ -214,6 +215,13 @@ func (v *SummaryVec) Reset() {
214215
v.SummaryVec.Reset()
215216
}
216217

218+
// ResetLabelAllowLists resets the label allow list for the SummaryVec.
219+
// NOTE: This should only be used in test.
220+
func (v *SummaryVec) ResetLabelAllowLists() {
221+
v.initializeLabelAllowListsOnce = sync.Once{}
222+
v.LabelValueAllowLists = nil
223+
}
224+
217225
// WithContext returns wrapped SummaryVec with context
218226
func (v *SummaryVec) WithContext(ctx context.Context) *SummaryVecWithContext {
219227
return &SummaryVecWithContext{

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"context"
21+
"sync"
2122
"time"
2223

2324
"github.com/blang/semver/v4"
@@ -267,6 +268,13 @@ func (v *TimingHistogramVec) Reset() {
267268
v.TimingHistogramVec.Reset()
268269
}
269270

271+
// ResetLabelAllowLists resets the label allow list for the TimingHistogramVec.
272+
// NOTE: This should only be used in test.
273+
func (v *TimingHistogramVec) ResetLabelAllowLists() {
274+
v.initializeLabelAllowListsOnce = sync.Once{}
275+
v.LabelValueAllowLists = nil
276+
}
277+
270278
// WithContext returns wrapped TimingHistogramVec with context
271279
func (v *TimingHistogramVec) InterfaceWithContext(ctx context.Context) GaugeVecMetric {
272280
return &TimingHistogramVecWithContext{

0 commit comments

Comments
 (0)