Skip to content

Commit

Permalink
tsdb: reset symbol table for exemplars
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan Boreham <[email protected]>
  • Loading branch information
bboreham committed May 28, 2024
1 parent 23106ff commit a2f6371
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tsdb/exemplar.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,27 @@ func (ce *CircularExemplarStorage) IterateExemplars(f func(seriesLabels labels.L
}
return nil
}

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] == nil {
continue
}
ce.exemplars[i].exemplar.Labels = rebuildLabels(ce.exemplars[i].exemplar.Labels)
}
}
4 changes: 4 additions & 0 deletions tsdb/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -2509,5 +2509,9 @@ func (h *Head) RebuildSymbolTable() *labels.SymbolTable {

h.series.locks[i].Unlock()
}

if e, ok := h.exemplars.(interface{ ResetSymbolTable(*labels.SymbolTable) }); ok {
e.ResetSymbolTable(st)
}
return st
}

0 comments on commit a2f6371

Please sign in to comment.