diff --git a/tsdb/exemplar.go b/tsdb/exemplar.go index 3dd784c62..78b907e01 100644 --- a/tsdb/exemplar.go +++ b/tsdb/exemplar.go @@ -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) + } +} diff --git a/tsdb/head.go b/tsdb/head.go index 7f62d0731..5491201e2 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -2481,5 +2481,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 }