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

@ -135,7 +135,8 @@ func (aw *apiWatcher) removeScrapeWorks(uw *urlWatcher, key string) {
} }
func getScrapeWorkObjectsForLabels(swcFunc ScrapeWorkConstructorFunc, labelss []map[string]string) []interface{} { 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 { for _, labels := range labelss {
swo := swcFunc(labels) swo := swcFunc(labels)
// The reflect check is needed because of https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1 // The reflect check is needed because of https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1