Merge pull request #128426 from yongruilin/reset-label-allow-list

feat(metrics): Add util func to reset label allow lists
This commit is contained in:
Kubernetes Prow Robot 2024-10-31 19:21:27 +00:00 committed by GitHub
commit 151ca569f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

@ -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.

View File

@ -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)
}