Extend createHead in tests to support histograms

Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
Ganesh Vernekar 2022-08-29 20:18:02 +05:30
parent f540c1dbd3
commit 8f755f8f35
No known key found for this signature in database
GPG key ID: F056451B52F1DC34

View file

@ -494,16 +494,34 @@ func createHead(tb testing.TB, w *wal.WAL, series []storage.Series, chunkDir str
head, err := NewHead(nil, nil, w, opts, nil) head, err := NewHead(nil, nil, w, opts, nil)
require.NoError(tb, err) require.NoError(tb, err)
app := head.Appender(context.Background()) ctx := context.Background()
app := head.Appender(ctx)
for _, s := range series { for _, s := range series {
ref := storage.SeriesRef(0) ref := storage.SeriesRef(0)
it := s.Iterator() it := s.Iterator()
lset := s.Labels() lset := s.Labels()
for it.Next() == chunkenc.ValFloat { typ := it.Next()
// TODO(beorn7): Also treat histograms. lastTyp := typ
t, v := it.At() for ; typ != chunkenc.ValNone; typ = it.Next() {
ref, err = app.Append(ref, lset, t, v) if lastTyp != typ {
// The behaviour of appender is undefined if samples of different types
// are appended to the same series in a single Commit().
require.NoError(tb, app.Commit())
app = head.Appender(ctx)
}
switch typ {
case chunkenc.ValFloat:
t, v := it.At()
ref, err = app.Append(ref, lset, t, v)
case chunkenc.ValHistogram:
t, h := it.AtHistogram()
ref, err = app.AppendHistogram(ref, lset, t, h)
default:
err = fmt.Errorf("unknown sample type %s", typ.String())
}
require.NoError(tb, err) require.NoError(tb, err)
lastTyp = typ
} }
require.NoError(tb, it.Err()) require.NoError(tb, it.Err())
} }