Skip to content

Commit

Permalink
tsdb: reset symbol table for exemplars periodically
Browse files Browse the repository at this point in the history
To avoid keeping the memory alive forever.

Signed-off-by: Bryan Boreham <[email protected]>
  • Loading branch information
bboreham committed Jul 5, 2024
1 parent 5281a6b commit 4d7532f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tsdb/head_dedupelabels.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ func (h *Head) RebuildSymbolTable(logger log.Logger) *labels.SymbolTable {

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())
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)
}
}

0 comments on commit 4d7532f

Please sign in to comment.