From 82441537ff2ace901784d21d87101b44a46a5fbe Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 28 Feb 2021 15:09:28 +0200 Subject: [PATCH] lib/promscrape/discovery/kubernetes: pre-populate labelsByKey in reloadObject() --- lib/promscrape/discovery/kubernetes/api.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/promscrape/discovery/kubernetes/api.go b/lib/promscrape/discovery/kubernetes/api.go index ca77b10de..913826a3a 100644 --- a/lib/promscrape/discovery/kubernetes/api.go +++ b/lib/promscrape/discovery/kubernetes/api.go @@ -305,8 +305,13 @@ func (uw *urlWatcher) reloadObjects() string { logger.Errorf("cannot parse response from %q: %s", requestURL, err) return "" } + labelsByKey := make(map[string][]map[string]string, len(objectsByKey)) + for k, o := range objectsByKey { + labelsByKey[k] = o.getTargetLabels(uw) + } uw.mu.Lock() uw.objectsByKey = objectsByKey + uw.labelsByKey = labelsByKey uw.mu.Unlock() return metadata.ResourceVersion }