Merge pull request #2874 from prometheus/memleak

retrieval: fix memory leak in scrape cache
This commit is contained in:
Fabian Reinartz 2017-06-26 15:21:35 +02:00 committed by GitHub
commit 4b70318d11

View file

@ -508,6 +508,11 @@ func (c *scrapeCache) getRef(met string) (string, bool) {
} }
func (c *scrapeCache) addRef(met, ref string, lset labels.Labels) { func (c *scrapeCache) addRef(met, ref string, lset labels.Labels) {
// Clean up the label set cache before overwriting the ref for a previously seen
// metric representation. It won't be caught by the cleanup in iterDone otherwise.
if e, ok := c.refs[met]; ok {
delete(c.lsets, e.ref)
}
c.refs[met] = &refEntry{ref: ref, lastIter: c.iter} c.refs[met] = &refEntry{ref: ref, lastIter: c.iter}
// met is the raw string the metric was ingested as. The label set is not ordered // met is the raw string the metric was ingested as. The label set is not ordered
// and thus it's not suitable to uniquely identify cache entries. // and thus it's not suitable to uniquely identify cache entries.