Skip to content

Commit

Permalink
calculating hash on TSDB Series() request as well
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Tanaka <pedro.tanaka@legal.one>
  • Loading branch information
Pedro Tanaka committed Sep 20, 2022
1 parent 56e329a commit 3488b5b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/store/tsdb.go
Expand Up @@ -197,6 +197,7 @@ func (s *TSDBStore) Series(r *storepb.SeriesRequest, srv storepb.Store_SeriesSer
Raw: &storepb.Chunk{
Type: storepb.Chunk_Encoding(chk.Chunk.Encoding() - 1), // Proto chunk encoding is one off to TSDB one.
Data: chk.Chunk.Bytes(),
Hash: hashChunk(chk.Chunk.Bytes(), r.CalculateChunkChecksums),
},
}
frameBytesLeft -= c.Size()
Expand Down
56 changes: 56 additions & 0 deletions pkg/store/tsdb_test.go
Expand Up @@ -6,6 +6,7 @@ package store
import (
"context"
"fmt"
"github.com/cespare/xxhash"
"io"
"math"
"math/rand"
Expand Down Expand Up @@ -61,6 +62,61 @@ func TestTSDBStore_Info(t *testing.T) {
testutil.Equals(t, int64(math.MaxInt64), resp.MaxTime)
}

func TestTSDBStore_Series_ChunkChecksum(t *testing.T) {
defer testutil.TolerantVerifyLeak(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

db, err := e2eutil.NewTSDB()
defer func() { testutil.Ok(t, db.Close()) }()
testutil.Ok(t, err)

tsdbStore := NewTSDBStore(nil, db, component.Rule, labels.FromStrings("region", "eu-west"))

appender := db.Appender(context.Background())

for i := 1; i <= 3; i++ {
_, err = appender.Append(0, labels.FromStrings("a", "1"), int64(i), float64(i))
testutil.Ok(t, err)
}
err = appender.Commit()
testutil.Ok(t, err)

srv := newStoreSeriesServer(ctx)

req := &storepb.SeriesRequest{
MinTime: 1,
MaxTime: 3,
Matchers: []storepb.LabelMatcher{
{Type: storepb.LabelMatcher_EQ, Name: "a", Value: "1"},
},
}
err = tsdbStore.Series(req, srv)
testutil.Ok(t, err)

for _, chk := range srv.SeriesSet[0].Chunks {
testutil.Equals(t, uint64(0), chk.Raw.Hash)
}

req = &storepb.SeriesRequest{
MinTime: 1,
MaxTime: 3,
Matchers: []storepb.LabelMatcher{
{Type: storepb.LabelMatcher_EQ, Name: "a", Value: "1"},
},
CalculateChunkChecksums: true,
}

err = tsdbStore.Series(req, srv)
testutil.Ok(t, err)

for _, chk := range srv.SeriesSet[1].Chunks {
want := xxhash.Sum64(chk.Raw.Data)
testutil.Equals(t, want, chk.Raw.Hash)
}
}

func TestTSDBStore_Series(t *testing.T) {
defer testutil.TolerantVerifyLeak(t)

Expand Down

0 comments on commit 3488b5b

Please sign in to comment.