Skip to content

Commit

Permalink
store: add acceptance tests for label methods to bucket store
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann committed Aug 27, 2023
1 parent 50e9144 commit 817bc3c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 13 deletions.
12 changes: 0 additions & 12 deletions pkg/store/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"
"time"

"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/timestamp"
"github.com/prometheus/prometheus/storage"
Expand Down Expand Up @@ -49,17 +48,6 @@ func testLabelAPIs(t *testing.T, startStore func(extLset labels.Labels, append f
labelNameCalls []labelNameCallCase
labelValuesCalls []labelValuesCallCase
}{
{
desc: "no label in tsdb, empty results",
labelNameCalls: []labelNameCallCase{
{start: timestamp.FromTime(minTime), end: timestamp.FromTime(maxTime)},
},
labelValuesCalls: []labelValuesCallCase{
{start: timestamp.FromTime(minTime), end: timestamp.FromTime(maxTime), expectErr: errors.New("rpc error: code = InvalidArgument desc = label name parameter cannot be empty")},
{start: timestamp.FromTime(minTime), end: timestamp.FromTime(maxTime), label: "foo"},
{start: timestamp.FromTime(minTime), end: timestamp.FromTime(maxTime), label: "region", expectedValues: []string{"eu-west"}}, // External labels should be visible.
},
},
{
desc: "{foo=foovalue1} 1",
appendFn: func(app storage.Appender) {
Expand Down
76 changes: 75 additions & 1 deletion pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,6 @@ func appendTestData(t testing.TB, app storage.Appender, series int) {
func createBlockFromHead(t testing.TB, dir string, head *tsdb.Head) ulid.ULID {
compactor, err := tsdb.NewLeveledCompactor(context.Background(), nil, log.NewNopLogger(), []int64{1000000}, nil, nil)
testutil.Ok(t, err)

testutil.Ok(t, os.MkdirAll(dir, 0777))

// Add +1 millisecond to block maxt because block intervals are half-open: [b.MinTime, b.MaxTime).
Expand Down Expand Up @@ -3342,3 +3341,78 @@ func TestBucketIndexReader_decodeCachedPostingsErrors(t *testing.T) {
testutil.NotOk(t, err)
})
}

func TestBucketStore_LabelAPIs(t *testing.T) {
t.Cleanup(func() { custom.TolerantVerifyLeak(t) })

testLabelAPIs(t, func(extLset labels.Labels, appendFn func(app storage.Appender)) storepb.StoreServer {
tmpDir := t.TempDir()
bktDir := filepath.Join(tmpDir, "bkt")
auxDir := filepath.Join(tmpDir, "aux")
metaDir := filepath.Join(tmpDir, "meta")

testutil.Ok(t, os.MkdirAll(filepath.Join(tmpDir, "meta"), os.ModePerm))
testutil.Ok(t, os.MkdirAll(filepath.Join(tmpDir, "aux"), os.ModePerm))

bkt, err := filesystem.NewBucket(bktDir)
testutil.Ok(t, err)
t.Cleanup(func() { _ = bkt.Close() })

headOpts := tsdb.DefaultHeadOptions()
headOpts.ChunkDirRoot = tmpDir
headOpts.ChunkRange = 1000
h, err := tsdb.NewHead(nil, nil, nil, nil, headOpts, nil)
testutil.Ok(t, err)
defer func() {
testutil.Ok(t, h.Close())
}()
logger := log.NewNopLogger()

appendFn(h.Appender(context.Background()))

id := createBlockFromHead(t, auxDir, h)

auxBlockDir := filepath.Join(auxDir, id.String())
_, err = metadata.InjectThanos(log.NewNopLogger(), auxBlockDir, metadata.Thanos{
Labels: extLset.Map(),
Downsample: metadata.ThanosDownsample{Resolution: 0},
Source: metadata.TestSource,
}, nil)
testutil.Ok(t, err)

testutil.Ok(t, block.Upload(context.Background(), logger, bkt, auxBlockDir, metadata.NoneFunc))
testutil.Ok(t, block.Upload(context.Background(), logger, bkt, auxBlockDir, metadata.NoneFunc))

chunkPool, err := NewDefaultChunkBytesPool(2e5)
testutil.Ok(t, err)

metaFetcher, err := block.NewMetaFetcher(logger, 20, objstore.WithNoopInstr(bkt), metaDir, nil, []block.MetadataFilter{
block.NewTimePartitionMetaFilter(allowAllFilterConf.MinTime, allowAllFilterConf.MaxTime),
})
testutil.Ok(t, err)

bucketStore, err := NewBucketStore(
objstore.WithNoopInstr(bkt),
metaFetcher,
"",
NewChunksLimiterFactory(10e6),
NewSeriesLimiterFactory(10e6),
NewBytesLimiterFactory(10e6),
NewGapBasedPartitioner(PartitionerMaxGapSize),
20,
true,
DefaultPostingOffsetInMemorySampling,
false,
false,
1*time.Minute,
WithChunkPool(chunkPool),
WithFilterConfig(allowAllFilterConf),
)
testutil.Ok(t, err)
t.Cleanup(func() { _ = bucketStore.Close() })

testutil.Ok(t, bucketStore.SyncBlocks(context.Background()))

return bucketStore
})
}

0 comments on commit 817bc3c

Please sign in to comment.