MCPcopy
hub / github.com/grafana/tempo / TestRetentionUpdatesBlocklistImmediately

Function TestRetentionUpdatesBlocklistImmediately

tempodb/retention_test.go:82–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestRetentionUpdatesBlocklistImmediately(t *testing.T) {
83 // Test that retention updates the in-memory blocklist
84 // immediately to reflect affected blocks and doesn't
85 // wait for the next polling cycle.
86
87 tempDir := t.TempDir()
88
89 r, w, c, err := New(&Config{
90 Backend: backend.Local,
91 Local: &local.Config{
92 Path: path.Join(tempDir, "traces"),
93 },
94 Block: &common.BlockConfig{
95 BloomFP: 0.01,
96 BloomShardSizeBytes: 100_000,
97 Version: encoding.DefaultEncoding().Version(),
98 },
99 WAL: &wal.Config{
100 Filepath: path.Join(tempDir, "wal"),
101 },
102 BlocklistPoll: 0,
103 }, nil, log.NewNopLogger())
104 assert.NoError(t, err)
105
106 ctx := context.Background()
107 r.EnablePolling(ctx, &mockJobSharder{}, false)
108
109 err = c.EnableCompaction(context.Background(), &CompactorConfig{
110 MaxCompactionRange: time.Hour,
111 BlockRetention: 0,
112 CompactedBlockRetention: 0,
113 }, &mockSharder{}, &mockOverrides{})
114 require.NoError(t, err)
115
116 wal := w.WAL()
117 assert.NoError(t, err)
118
119 blockID := backend.NewUUID()
120
121 meta := &backend.BlockMeta{BlockID: blockID, TenantID: testTenantID}
122 head, err := wal.NewBlock(meta, model.CurrentEncoding)
123 assert.NoError(t, err)
124
125 complete, err := w.CompleteBlock(ctx, head)
126 assert.NoError(t, err)
127 blockID = complete.BlockMeta().BlockID
128
129 // We have a block
130 rw := r.(*readerWriter)
131 rw.pollBlocklist(ctx)
132 require.Equal(t, blockID, rw.blocklist.Metas(testTenantID)[0].BlockID)
133
134 // Mark it compacted
135 r.(*readerWriter).compactorCfg.BlockRetention = 0 // Immediately delete
136 r.(*readerWriter).compactorCfg.CompactedBlockRetention = time.Hour
137 r.(*readerWriter).doRetention(ctx)
138
139 // Immediately compacted

Callers

nothing calls this directly

Calls 15

DefaultEncodingFunction · 0.92
NewUUIDFunction · 0.92
NewBlockMethod · 0.80
pollBlocklistMethod · 0.80
doRetentionMethod · 0.80
NewFunction · 0.70
JoinMethod · 0.65
VersionMethod · 0.65
EnablePollingMethod · 0.65
EnableCompactionMethod · 0.65
WALMethod · 0.65
CompleteBlockMethod · 0.65

Tested by

no test coverage detected