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

Function TestInvalidFilesAndFoldersAreHandled

tempodb/wal/wal_test.go:310–354  ·  tempodb/wal/wal_test.go::TestInvalidFilesAndFoldersAreHandled
(t *testing.T)

Source from the content-addressed store, hash-verified

308}
309
310func TestInvalidFilesAndFoldersAreHandled(t *testing.T) {
311 tempDir := t.TempDir()
312 wal, err := New(&Config{
313 Filepath: tempDir,
314 Version: encoding.DefaultEncoding().Version(),
315 })
316 require.NoError(t, err, "unexpected error creating temp wal")
317
318 writeableEncodings := encoding.AllEncodingsForWrites()
319
320 // create all valid blocks
321 for _, e := range writeableEncodings {
322 meta := backend.NewBlockMeta("fake", uuid.New(), e.Version())
323 block, err := wal.NewBlock(meta, model.CurrentEncoding)
324 require.NoError(t, err)
325
326 id := make([]byte, 16)
327 _, err = crand.Read(id)
328 require.NoError(t, err)
329 tr := test.MakeTrace(10, id)
330 b1, err := model.MustNewSegmentDecoder(model.CurrentEncoding).PrepareForWrite(tr, 0, 0)
331 require.NoError(t, err)
332 b2, err := model.MustNewSegmentDecoder(model.CurrentEncoding).ToObject([][]byte{b1})
333 require.NoError(t, err)
334 err = block.Append(id, b2, 0, 0, true)
335 require.NoError(t, err)
336 err = block.Flush()
337 require.NoError(t, err)
338 }
339
340 // create unparseable filename
341 err = os.WriteFile(filepath.Join(tempDir, "fe0b83eb-a86b-4b6c-9a74-dc272cd5700e:tenant:vParquet5:notanencoding"), []byte{}, 0o600)
342 require.NoError(t, err)
343
344 // create unparseable block
345 require.NoError(t, os.MkdirAll(filepath.Join(tempDir, "fe0b83eb-a86b-4b6c-9a74-dc272cd5700e+tenant+vOther"), 0o700))
346
347 blocks, err := wal.RescanBlocks(0, log.NewNopLogger())
348 require.NoError(t, err, "unexpected error getting blocks")
349 require.Len(t, blocks, len(writeableEncodings)) // valid blocks created above
350
351 // unparseable files/folder should have been ignored
352 require.FileExists(t, filepath.Join(tempDir, "fe0b83eb-a86b-4b6c-9a74-dc272cd5700e:tenant:vParquet5:notanencoding"))
353 require.DirExists(t, filepath.Join(tempDir, "fe0b83eb-a86b-4b6c-9a74-dc272cd5700e+tenant+vOther"))
354}
355
356func runWALTest(t testing.TB, encoding string, runner func([][]byte, []*tempopb.Trace, common.WALBlock)) {
357 runWALTestWithAppendMode(t, encoding, false, runner)

Callers

nothing calls this directly

Calls 15

DefaultEncodingFunction · 0.92
AllEncodingsForWritesFunction · 0.92
NewBlockMetaFunction · 0.92
MakeTraceFunction · 0.92
MustNewSegmentDecoderFunction · 0.92
NewBlockMethod · 0.80
RescanBlocksMethod · 0.80
NewFunction · 0.70
VersionMethod · 0.65
ReadMethod · 0.65
PrepareForWriteMethod · 0.65
ToObjectMethod · 0.65

Tested by

no test coverage detected