RedactBlock rewrites a block excluding the given trace IDs. If none of the trace IDs are in the block, no rewrite is performed.
(ctx context.Context, meta *backend.BlockMeta, tenantID string, traceIDs []common.ID)
| 619 | // RedactBlock rewrites a block excluding the given trace IDs. If none of the trace IDs |
| 620 | // are in the block, no rewrite is performed. |
| 621 | func (rw *readerWriter) RedactBlock(ctx context.Context, meta *backend.BlockMeta, tenantID string, traceIDs []common.ID) (rewrote bool, found int, newMeta *backend.BlockMeta, err error) { |
| 622 | block, err := encoding.OpenBlock(meta, rw.r) |
| 623 | if err != nil { |
| 624 | return false, 0, nil, fmt.Errorf("error opening block for redaction, blockID: %s: %w", meta.BlockID.String(), err) |
| 625 | } |
| 626 | |
| 627 | searchOpts := common.DefaultSearchOptions() |
| 628 | if rw.cfg != nil && rw.cfg.Search != nil { |
| 629 | rw.cfg.Search.ApplyToOptions(&searchOpts) |
| 630 | } |
| 631 | |
| 632 | var idsToDrop []common.ID |
| 633 | for _, traceID := range traceIDs { |
| 634 | result, err := block.FindTraceByID(ctx, traceID, searchOpts) |
| 635 | if err != nil { |
| 636 | return false, 0, nil, fmt.Errorf("error finding trace in block, blockID: %s: %w", meta.BlockID.String(), err) |
| 637 | } |
| 638 | if result != nil && result.Trace != nil { |
| 639 | idsToDrop = append(idsToDrop, traceID) |
| 640 | } |
| 641 | } |
| 642 | if len(idsToDrop) == 0 { |
| 643 | return false, 0, nil, nil |
| 644 | } |
| 645 | |
| 646 | enc, err := encoding.FromVersion(meta.Version) |
| 647 | if err != nil { |
| 648 | return false, 0, nil, fmt.Errorf("error getting encoding for version %s: %w", meta.Version, err) |
| 649 | } |
| 650 | |
| 651 | opts := common.CompactionOptions{ |
| 652 | BlockConfig: common.BlockConfig{ |
| 653 | BloomFP: common.DefaultBloomFP, |
| 654 | BloomShardSizeBytes: common.DefaultBloomShardSizeBytes, |
| 655 | Version: meta.Version, |
| 656 | RowGroupSizeBytes: 100_000_000, |
| 657 | DedicatedColumns: meta.DedicatedColumns, |
| 658 | }, |
| 659 | OutputBlocks: 1, |
| 660 | MaxBytesPerTrace: 0, |
| 661 | DropObject: func(id common.ID) bool { |
| 662 | for _, tid := range idsToDrop { |
| 663 | if bytes.Equal(id, tid) { |
| 664 | level.Debug(rw.logger).Log("msg", "redact dropping trace", "traceID", hex.EncodeToString(id)) |
| 665 | return true |
| 666 | } |
| 667 | } |
| 668 | return false |
| 669 | }, |
| 670 | BytesWritten: func(_, _ int) {}, |
| 671 | ObjectsCombined: func(_, _ int) {}, |
| 672 | ObjectsWritten: func(_, _ int) {}, |
| 673 | SpansDiscarded: func(_, _, _ string, _ int) {}, |
| 674 | DisconnectedTrace: func() {}, |
| 675 | RootlessTrace: func() {}, |
| 676 | DedupedSpans: func(_, _ int) {}, |
| 677 | } |
| 678 |
nothing calls this directly
no test coverage detected