Skip to content

Commit 151ca56

Browse files
authored
Merge pull request kubernetes#128426 from yongruilin/reset-label-allow-list
feat(metrics): Add util func to reset label allow lists
2 parents 365b457 + d2ef8a1 commit 151ca56

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ var (
3737
allowListLock sync.RWMutex
3838
)
3939

40+
// ResetLabelValueAllowLists resets the allow lists for label values.
41+
// NOTE: This should only be used in test.
42+
func ResetLabelValueAllowLists() {
43+
allowListLock.Lock()
44+
defer allowListLock.Unlock()
45+
labelValueAllowLists = map[string]*MetricLabelAllowList{}
46+
}
47+
4048
// KubeOpts is superset struct for prometheus.Opts. The prometheus Opts structure
4149
// is purposefully not embedded here because that would change struct initialization
4250
// in the manner which people are currently accustomed.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,21 @@ metric2,label2: v3`,
208208
})
209209
}
210210
}
211+
212+
func TestResetLabelValueAllowLists(t *testing.T) {
213+
labelValueAllowLists = map[string]*MetricLabelAllowList{
214+
"metric1": {
215+
labelToAllowList: map[string]sets.Set[string]{
216+
"label1": sets.New[string]("v1", "v2"),
217+
},
218+
},
219+
"metric2": {
220+
labelToAllowList: map[string]sets.Set[string]{
221+
"label2": sets.New[string]("v3"),
222+
},
223+
},
224+
}
225+
226+
ResetLabelValueAllowLists()
227+
assert.Empty(t, labelValueAllowLists)
228+
}

0 commit comments

Comments
 (0)