Update package tsdb/index tests for new labels.Labels type

Note in one cases we needed an extra copy of labels in case they change.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2022-03-09 22:18:37 +00:00
parent d3d96ec887
commit a5bdff414b

View File

@ -68,14 +68,14 @@ func (m mockIndex) AddSeries(ref storage.SeriesRef, l labels.Labels, chunks ...c
if _, ok := m.series[ref]; ok {
return errors.Errorf("series with reference %d already added", ref)
}
for _, lbl := range l {
l.Range(func(lbl labels.Label) {
m.symbols[lbl.Name] = struct{}{}
m.symbols[lbl.Value] = struct{}{}
if _, ok := m.postings[lbl]; !ok {
m.postings[lbl] = []storage.SeriesRef{}
}
m.postings[lbl] = append(m.postings[lbl], ref)
}
})
m.postings[allPostingsKey] = append(m.postings[allPostingsKey], ref)
s := series{l: l}
@ -129,7 +129,7 @@ func (m mockIndex) Series(ref storage.SeriesRef, builder *labels.ScratchBuilder,
if !ok {
return errors.New("not found")
}
*lset = append((*lset)[:0], s.l...)
lset.CopyFrom(s.l)
*chks = append((*chks)[:0], s.chunks...)
return nil
@ -322,7 +322,7 @@ func TestPostingsMany(t *testing.T) {
var metas []chunks.Meta
for it.Next() {
require.NoError(t, ir.Series(it.At(), &builder, &lbls, &metas))
got = append(got, lbls.Get("i"))
got = append(got, lbls.Copy().Get("i"))
}
require.NoError(t, it.Err())
exp := []string{}
@ -346,10 +346,10 @@ func TestPersistence_index_e2e(t *testing.T) {
symbols := map[string]struct{}{}
for _, lset := range lbls {
for _, l := range lset {
lset.Range(func(l labels.Label) {
symbols[l.Name] = struct{}{}
symbols[l.Value] = struct{}{}
}
})
}
var input indexWriterSeriesSlice
@ -397,14 +397,14 @@ func TestPersistence_index_e2e(t *testing.T) {
require.NoError(t, err)
require.NoError(t, mi.AddSeries(storage.SeriesRef(i), s.labels, s.chunks...))
for _, l := range s.labels {
s.labels.Range(func(l labels.Label) {
valset, ok := values[l.Name]
if !ok {
valset = map[string]struct{}{}
values[l.Name] = valset
}
valset[l.Value] = struct{}{}
}
})
postings.Add(storage.SeriesRef(i), s.labels)
}