mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
feat(metrics): Add util func to reset label allow lists
Adds a utility function `ResetLabelValueAllowLists` to reset the allow lists for label values. This facilitates testing by allowing tests to clear the global state between runs and avoid unintended side effects.
This commit is contained in:
parent
f087575f21
commit
d2ef8a1808
@ -37,6 +37,14 @@ var (
|
||||
allowListLock sync.RWMutex
|
||||
)
|
||||
|
||||
// ResetLabelValueAllowLists resets the allow lists for label values.
|
||||
// NOTE: This should only be used in test.
|
||||
func ResetLabelValueAllowLists() {
|
||||
allowListLock.Lock()
|
||||
defer allowListLock.Unlock()
|
||||
labelValueAllowLists = map[string]*MetricLabelAllowList{}
|
||||
}
|
||||
|
||||
// KubeOpts is superset struct for prometheus.Opts. The prometheus Opts structure
|
||||
// is purposefully not embedded here because that would change struct initialization
|
||||
// in the manner which people are currently accustomed.
|
||||
|
@ -208,3 +208,21 @@ metric2,label2: v3`,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResetLabelValueAllowLists(t *testing.T) {
|
||||
labelValueAllowLists = map[string]*MetricLabelAllowList{
|
||||
"metric1": {
|
||||
labelToAllowList: map[string]sets.Set[string]{
|
||||
"label1": sets.New[string]("v1", "v2"),
|
||||
},
|
||||
},
|
||||
"metric2": {
|
||||
labelToAllowList: map[string]sets.Set[string]{
|
||||
"label2": sets.New[string]("v3"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ResetLabelValueAllowLists()
|
||||
assert.Empty(t, labelValueAllowLists)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user