MCPcopy Create free account
hub / github.com/cortexproject/cortex / MockStorageBlock

Function MockStorageBlock

pkg/util/testutil/block_mock.go:21–51  ·  view source on GitHub ↗
(t testing.TB, bucket objstore.Bucket, userID string, minT, maxT int64)

Source from the content-addressed store, hash-verified

19)
20
21func MockStorageBlock(t testing.TB, bucket objstore.Bucket, userID string, minT, maxT int64) tsdb.BlockMeta {
22 // Generate a block ID whose timestamp matches the maxT (for simplicity we assume it
23 // has been compacted and shipped in zero time, even if not realistic).
24 id := ulid.MustNew(uint64(maxT), rand.Reader)
25
26 meta := tsdb.BlockMeta{
27 Version: 1,
28 ULID: id,
29 MinTime: minT,
30 MaxTime: maxT,
31 Compaction: tsdb.BlockMetaCompaction{
32 Level: 1,
33 Sources: []ulid.ULID{id},
34 },
35 }
36
37 metaContent, err := json.Marshal(meta)
38 if err != nil {
39 panic("failed to marshal mocked block meta")
40 }
41
42 metaContentReader := strings.NewReader(string(metaContent))
43 metaPath := fmt.Sprintf("%s/%s/meta.json", userID, id.String())
44 require.NoError(t, bucket.Upload(context.Background(), metaPath, metaContentReader))
45
46 // Upload an empty index, just to make sure the meta.json is not the only object in the block location.
47 indexPath := fmt.Sprintf("%s/%s/index", userID, id.String())
48 require.NoError(t, bucket.Upload(context.Background(), indexPath, strings.NewReader("")))
49
50 return meta
51}
52
53func MockStorageDeletionMark(t testing.TB, bucket objstore.Bucket, userID string, meta tsdb.BlockMeta) *metadata.DeletionMark {
54 mark := metadata.DeletionMark{

Calls 3

StringMethod · 0.65
MarshalMethod · 0.45
UploadMethod · 0.45