Skip to content

Commit 36081ff

Browse files
authored
Merge pull request kubernetes#128321 from yongruilin/reset-label-allow-list
feat(metrics): Add method to reset label allow lists
2 parents 961344d + e0ebd44 commit 36081ff

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"
@@ -273,6 +274,13 @@ func (v *CounterVec) Reset() {
273274
v.CounterVec.Reset()
274275
}
275276

277+
// ResetLabelAllowLists resets the label allow list for the CounterVec.
278+
// NOTE: This should only be used in test.
279+
func (v *CounterVec) ResetLabelAllowLists() {
280+
v.initializeLabelAllowListsOnce = sync.Once{}
281+
v.LabelValueAllowLists = nil
282+
}
283+
276284
// WithContext returns wrapped CounterVec with context
277285
func (v *CounterVec) WithContext(ctx context.Context) *CounterVecWithContext {
278286
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"
@@ -241,6 +242,13 @@ func (v *HistogramVec) Reset() {
241242
v.HistogramVec.Reset()
242243
}
243244

245+
// ResetLabelAllowLists resets the label allow list for the HistogramVec.
246+
// NOTE: This should only be used in test.
247+
func (v *HistogramVec) ResetLabelAllowLists() {
248+
v.initializeLabelAllowListsOnce = sync.Once{}
249+
v.LabelValueAllowLists = nil
250+
}
251+
244252
// WithContext returns wrapped HistogramVec with context
245253
func (v *HistogramVec) WithContext(ctx context.Context) *HistogramVecWithContext {
246254
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)