lib/promscrape/discovery/kubernetes: do not pre-allocate memory for ScrapeWork objects

There is high chance that ScrapeWork objects won't be generated because of relabeling
This commit is contained in:
Aliaksandr Valialkin 2022-04-20 16:40:17 +03:00
parent 90db923662
commit e9f08b1e6a
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 3 additions and 2 deletions

View File

@ -28,7 +28,7 @@ func TestInternStringConcurrent(t *testing.T) {
resultCh <- testInternString(t)
}()
}
timer := time.NewTimer(5*time.Second)
timer := time.NewTimer(5 * time.Second)
for i := 0; i < concurrency; i++ {
select {
case err := <-resultCh:

View File

@ -135,7 +135,8 @@ func (aw *apiWatcher) removeScrapeWorks(uw *urlWatcher, key string) {
}
func getScrapeWorkObjectsForLabels(swcFunc ScrapeWorkConstructorFunc, labelss []map[string]string) []interface{} {
swos := make([]interface{}, 0, len(labelss))
// Do not pre-allocate swos, since it is likely the swos will be empty because of relabeling
var swos []interface{}
for _, labels := range labelss {
swo := swcFunc(labels)
// The reflect check is needed because of https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1