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

Function TestCompactionIteratesThroughTenants

tempodb/compactor_test.go:507–563  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

505}
506
507func TestCompactionIteratesThroughTenants(t *testing.T) {
508 tempDir := t.TempDir()
509
510 r, w, c, err := New(&Config{
511 Backend: backend.Local,
512 Pool: &pool.Config{
513 MaxWorkers: 10,
514 QueueDepth: 100,
515 },
516 Local: &local.Config{
517 Path: path.Join(tempDir, "traces"),
518 },
519 Block: &common.BlockConfig{
520 BloomFP: .01,
521 BloomShardSizeBytes: 100_000,
522 Version: encoding.DefaultEncoding().Version(),
523 },
524 WAL: &wal.Config{
525 Filepath: path.Join(tempDir, "wal"),
526 },
527 BlocklistPoll: 0,
528 }, nil, log.NewNopLogger())
529 assert.NoError(t, err)
530
531 ctx := context.Background()
532 err = c.EnableCompaction(ctx, &CompactorConfig{
533 MaxCompactionRange: 24 * time.Hour,
534 MaxCompactionObjects: 1000,
535 MaxBlockBytes: 1024 * 1024 * 1024,
536 BlockRetention: 0,
537 CompactedBlockRetention: 0,
538 }, &mockSharder{}, &mockOverrides{})
539 require.NoError(t, err)
540
541 r.EnablePolling(ctx, &mockJobSharder{}, true)
542
543 // Cut blocks for multiple tenants
544 cutTestBlocks(t, w, testTenantID, 2, 2)
545 cutTestBlocks(t, w, testTenantID2, 2, 2)
546
547 rw := r.(*readerWriter)
548 rw.pollBlocklist(ctx)
549
550 assert.Equal(t, 2, len(rw.blocklist.Metas(testTenantID)))
551 assert.Equal(t, 2, len(rw.blocklist.Metas(testTenantID2)))
552
553 // Verify that tenant 2 compacted, tenant 1 is not
554 // Compaction starts at index 1 for simplicity
555 rw.compactOneTenant(ctx)
556 assert.Equal(t, 2, len(rw.blocklist.Metas(testTenantID)))
557 assert.Equal(t, 1, len(rw.blocklist.Metas(testTenantID2)))
558
559 // Verify both tenants compacted after second run
560 rw.compactOneTenant(ctx)
561 assert.Equal(t, 1, len(rw.blocklist.Metas(testTenantID)))
562 assert.Equal(t, 1, len(rw.blocklist.Metas(testTenantID2)))
563}
564

Callers

nothing calls this directly

Calls 11

DefaultEncodingFunction · 0.92
pollBlocklistMethod · 0.80
compactOneTenantMethod · 0.80
NewFunction · 0.70
cutTestBlocksFunction · 0.70
JoinMethod · 0.65
VersionMethod · 0.65
EnableCompactionMethod · 0.65
EnablePollingMethod · 0.65
EqualMethod · 0.45
MetasMethod · 0.45

Tested by

no test coverage detected