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

Function testCompleteBlockHonorsStartStopTimes

tempodb/tempodb_test.go:652–698  ·  tempodb/tempodb_test.go::testCompleteBlockHonorsStartStopTimes
(t *testing.T, targetBlockVersion string)

Source from the content-addressed store, hash-verified

650}
651
652func testCompleteBlockHonorsStartStopTimes(t *testing.T, targetBlockVersion string) {
653 tempDir := t.TempDir()
654
655 _, w, _, err := New(&Config{
656 Backend: backend.Local,
657 Local: &local.Config{
658 Path: path.Join(tempDir, "traces"),
659 },
660 Block: &common.BlockConfig{
661 BloomFP: .01,
662 BloomShardSizeBytes: 100_000,
663 Version: targetBlockVersion,
664 },
665 WAL: &wal.Config{
666 IngestionSlack: time.Minute,
667 Filepath: path.Join(tempDir, "wal"),
668 },
669 BlocklistPoll: 0,
670 }, nil, log.NewNopLogger())
671 require.NoError(t, err)
672
673 dec := model.MustNewSegmentDecoder(model.CurrentEncoding)
674
675 wal := w.WAL()
676
677 now := time.Now()
678 oneHourAgo := now.Add(-1 * time.Hour).Unix()
679 oneHour := now.Add(time.Hour).Unix()
680
681 meta := &backend.BlockMeta{BlockID: backend.NewUUID(), TenantID: testTenantID}
682 block, err := wal.NewBlock(meta, model.CurrentEncoding)
683 require.NoError(t, err, "unexpected error creating block")
684
685 // Write a trace from 1 hour ago.
686 // The wal slack time will adjust it to 1 minute ago
687 id := test.ValidTraceID(nil)
688 req := test.MakeTrace(10, id)
689 writeTraceToWal(t, block, dec, id, req, uint32(oneHourAgo), uint32(oneHour))
690
691 complete, err := w.CompleteBlock(context.Background(), block)
692 require.NoError(t, err, "unexpected error completing block")
693
694 // Verify the block time was constrained to the slack time.
695 // Accept a couple seconds of slack time to ensure test reliability.
696 require.Less(t, complete.BlockMeta().StartTime.Sub(now).Seconds(), 2.0)
697 require.Less(t, complete.BlockMeta().EndTime.Sub(now).Seconds(), 2.0)
698}
699
700func writeTraceToWal(t require.TestingT, b common.WALBlock, dec model.SegmentDecoder, id common.ID, tr *tempopb.Trace, start, end uint32) {
701 b1, err := dec.PrepareForWrite(tr, 0, 0)

Callers 1

Calls 14

MustNewSegmentDecoderFunction · 0.92
NewUUIDFunction · 0.92
ValidTraceIDFunction · 0.92
MakeTraceFunction · 0.92
NewBlockMethod · 0.80
NewFunction · 0.70
writeTraceToWalFunction · 0.70
JoinMethod · 0.65
WALMethod · 0.65
NowMethod · 0.65
AddMethod · 0.65
CompleteBlockMethod · 0.65

Tested by

no test coverage detected