Files
Joe ElliottandGitHub 65ae24f720 BugFix: Correctly apply trace idle period in ingesters and add a max live trace period (#5346)
* Add concept of live trace max lifetime and use in local blocks

Signed-off-by: Joe Elliott <[email protected]>

* remove dead code

Signed-off-by: Joe Elliott <[email protected]>

* add live cut time to ingesters

Signed-off-by: Joe Elliott <[email protected]>

* live trace period

Signed-off-by: Joe Elliott <[email protected]>

* docs

Signed-off-by: Joe Elliott <[email protected]>

* changelog

Signed-off-by: Joe Elliott <[email protected]>

* clean up search tags e2e

Signed-off-by: Joe Elliott <[email protected]>

* more e2e patches

Signed-off-by: Joe Elliott <[email protected]>

* remove unnecessary asserts

Signed-off-by: Joe Elliott <[email protected]>

---------

Signed-off-by: Joe Elliott <[email protected]>
2025-07-02 08:45:50 -04:00

56 lines
1.1 KiB
Go

package ingester
import (
"context"
"fmt"
"time"
"github.com/grafana/tempo/pkg/model"
)
type liveTrace struct {
batches [][]byte
traceID []byte
start uint32
end uint32
decoder model.SegmentDecoder
lastAppend time.Time
createdAt time.Time
}
func newTrace(traceID []byte) *liveTrace {
return &liveTrace{
batches: make([][]byte, 0, 10), // 10 for luck
traceID: traceID,
decoder: model.MustNewSegmentDecoder(model.CurrentEncoding),
createdAt: time.Now(),
lastAppend: time.Now(),
}
}
func (t *liveTrace) Push(_ context.Context, instanceID string, trace []byte) error {
t.lastAppend = time.Now()
start, end, err := t.decoder.FastRange(trace)
if err != nil {
return fmt.Errorf("failed to get range while adding segment: %w", err)
}
t.batches = append(t.batches, trace)
if t.start == 0 || start < t.start {
t.start = start
}
if t.end == 0 || end > t.end {
t.end = end
}
return nil
}
func (t *liveTrace) Size() uint64 {
size := uint64(0)
for _, batch := range t.batches {
size += uint64(len(batch))
}
return size
}