(t *testing.T, from, to string)
| 579 | } |
| 580 | |
| 581 | func testCompleteBlock(t *testing.T, from, to string) { |
| 582 | _, w, _, _ := testConfig(t, time.Minute, func(c *Config) { |
| 583 | c.Block.Version = from // temporarily set config to from while we create the wal, so it makes blocks in the "from" format |
| 584 | }) |
| 585 | |
| 586 | wal := w.WAL() |
| 587 | rw := w.(*readerWriter) |
| 588 | rw.cfg.Block.Version = to // now set it back so we cut blocks in the "to" format |
| 589 | |
| 590 | meta := &backend.BlockMeta{ |
| 591 | Version: from, |
| 592 | BlockID: backend.UUID(uuid.New()), |
| 593 | TenantID: testTenantID, |
| 594 | DedicatedColumns: test.MakeDedicatedColumns(), |
| 595 | } |
| 596 | block, err := wal.NewBlock(meta, model.CurrentEncoding) |
| 597 | require.NoError(t, err, "unexpected error creating block") |
| 598 | require.Equal(t, block.BlockMeta().Version, from) |
| 599 | |
| 600 | dec := model.MustNewSegmentDecoder(model.CurrentEncoding) |
| 601 | |
| 602 | numMsgs := 100 |
| 603 | reqs := make([]*tempopb.Trace, 0, numMsgs) |
| 604 | ids := make([][]byte, 0, numMsgs) |
| 605 | for i := 0; i < numMsgs; i++ { |
| 606 | var ( |
| 607 | id = test.ValidTraceID(nil) |
| 608 | req = test.MakeTrace(rand.Int()%10, id) |
| 609 | ) |
| 610 | |
| 611 | // Populate data using the same dedicated columns as configured on the block above. |
| 612 | test.AddRandomDedicatedAttributes(req) |
| 613 | |
| 614 | writeTraceToWal(t, block, dec, id, req, 0, 0) |
| 615 | reqs = append(reqs, req) |
| 616 | ids = append(ids, id) |
| 617 | } |
| 618 | require.NoError(t, block.Flush()) |
| 619 | |
| 620 | complete, err := w.CompleteBlock(context.Background(), block) |
| 621 | require.NoError(t, err, "unexpected error completing block") |
| 622 | require.Equal(t, complete.BlockMeta().Version, to) |
| 623 | |
| 624 | for i, id := range ids { |
| 625 | found, err := complete.FindTraceByID(context.TODO(), id, common.DefaultSearchOptions()) |
| 626 | require.NoError(t, err) |
| 627 | require.NotNil(t, found) |
| 628 | |
| 629 | // Sort expected and actual before comparing. |
| 630 | trace.SortTraceAndAttributes(reqs[i]) |
| 631 | trace.SortTraceAndAttributes(found.Trace) |
| 632 | |
| 633 | // After sorting, the completed block should round-trip the trace exactly. |
| 634 | require.True(t, proto.Equal(found.Trace, reqs[i])) |
| 635 | |
| 636 | // Check metrics for certain encodings. |
| 637 | if to == vparquet4.VersionString || to == vparquet5.VersionString { |
| 638 | require.Greater(t, found.Metrics.InspectedBytes, uint64(100000)) |
no test coverage detected