mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
tsdb: reset symbol table for exemplars periodically
To avoid keeping the memory alive forever. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
5281a6bc1b
commit
4d7532f60b
|
@ -62,6 +62,34 @@ func (h *Head) RebuildSymbolTable(logger log.Logger) *labels.SymbolTable {
|
||||||
|
|
||||||
h.series.locks[i].Unlock()
|
h.series.locks[i].Unlock()
|
||||||
}
|
}
|
||||||
|
type withReset interface{ ResetSymbolTable(*labels.SymbolTable) }
|
||||||
|
if e, ok := h.exemplars.(withReset); ok {
|
||||||
|
e.ResetSymbolTable(st)
|
||||||
|
}
|
||||||
level.Info(logger).Log("msg", "RebuildSymbolTable finished", "size", st.Len())
|
level.Info(logger).Log("msg", "RebuildSymbolTable finished", "size", st.Len())
|
||||||
return st
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ce *CircularExemplarStorage) ResetSymbolTable(st *labels.SymbolTable) {
|
||||||
|
builder := labels.NewScratchBuilderWithSymbolTable(st, 0)
|
||||||
|
rebuildLabels := func(lbls labels.Labels) labels.Labels {
|
||||||
|
builder.Reset()
|
||||||
|
lbls.Range(func(l labels.Label) {
|
||||||
|
builder.Add(l.Name, l.Value)
|
||||||
|
})
|
||||||
|
return builder.Labels()
|
||||||
|
}
|
||||||
|
|
||||||
|
ce.lock.RLock()
|
||||||
|
defer ce.lock.RUnlock()
|
||||||
|
|
||||||
|
for _, v := range ce.index {
|
||||||
|
v.seriesLabels = rebuildLabels(v.seriesLabels)
|
||||||
|
}
|
||||||
|
for i := range ce.exemplars {
|
||||||
|
if ce.exemplars[i].ref == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ce.exemplars[i].exemplar.Labels = rebuildLabels(ce.exemplars[i].exemplar.Labels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue