(b *testing.B, encoding string, flushCount int, appendTrace bool, runner func([][]byte, []*tempopb.Trace, common.WALBlock))
| 505 | } |
| 506 | |
| 507 | func runWALBenchmarkWithAppendMode(b *testing.B, encoding string, flushCount int, appendTrace bool, runner func([][]byte, []*tempopb.Trace, common.WALBlock)) { |
| 508 | wal, err := New(&Config{ |
| 509 | Filepath: b.TempDir(), |
| 510 | Version: encoding, |
| 511 | }) |
| 512 | require.NoError(b, err, "unexpected error creating temp wal") |
| 513 | |
| 514 | blockID := uuid.New() |
| 515 | |
| 516 | meta := backend.NewBlockMeta("fake", blockID, encoding) |
| 517 | block, err := wal.NewBlock(meta, model.CurrentEncoding) |
| 518 | require.NoError(b, err, "unexpected error creating block") |
| 519 | |
| 520 | dec := model.MustNewSegmentDecoder(model.CurrentEncoding) |
| 521 | |
| 522 | objects := 250 |
| 523 | traces := make([]*tempopb.Trace, 0, objects) |
| 524 | objs := make([][]byte, 0, objects) |
| 525 | ids := make([][]byte, 0, objects) |
| 526 | for i := 0; i < objects; i++ { |
| 527 | id := make([]byte, 16) |
| 528 | _, err = crand.Read(id) |
| 529 | require.NoError(b, err) |
| 530 | obj := test.MakeTrace(rand.Int()%10+1, id) |
| 531 | |
| 532 | trace.SortTrace(obj) |
| 533 | |
| 534 | ids = append(ids, id) |
| 535 | traces = append(traces, obj) |
| 536 | |
| 537 | b1, err := dec.PrepareForWrite(obj, 0, 0) |
| 538 | require.NoError(b, err) |
| 539 | |
| 540 | b2, err := dec.ToObject([][]byte{b1}) |
| 541 | require.NoError(b, err) |
| 542 | |
| 543 | objs = append(objs, b2) |
| 544 | } |
| 545 | |
| 546 | b.ResetTimer() |
| 547 | |
| 548 | for flush := 0; flush < flushCount; flush++ { |
| 549 | |
| 550 | for i := range traces { |
| 551 | if appendTrace { |
| 552 | require.NoError(b, block.AppendTrace(ids[i], traces[i], 0, 0, true)) |
| 553 | } else { |
| 554 | require.NoError(b, block.Append(ids[i], objs[i], 0, 0, true)) |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | err = block.Flush() |
| 559 | require.NoError(b, err) |
| 560 | } |
| 561 | |
| 562 | if runner != nil { |
| 563 | runner(ids, traces, block) |
| 564 | } |
no test coverage detected