From 33cf9ff1b5aad89a97e412944eb4a54cd2f060ba Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 3 Dec 2024 15:32:28 +0100 Subject: [PATCH 1/2] Correctly pass start/end times --- modules/blockbuilder/partition_writer.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/blockbuilder/partition_writer.go b/modules/blockbuilder/partition_writer.go index 349180c5af6..5711de55ac8 100644 --- a/modules/blockbuilder/partition_writer.go +++ b/modules/blockbuilder/partition_writer.go @@ -3,7 +3,9 @@ package blockbuilder import ( "context" "fmt" + "math" "sync" + "time" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -67,7 +69,20 @@ func (p *writer) pushBytes(tenant string, req *tempopb.PushBytesRequest) error { return fmt.Errorf("failed to unmarshal trace: %w", err) } - if err := i.AppendTrace(req.Ids[j], tr, 0, 0); err != nil { + start, end := uint64(math.MaxUint64), uint64(0) + for _, rs := range tr.ResourceSpans { + for _, ss := range rs.ScopeSpans { + for _, span := range ss.Spans { + start = min(start, span.StartTimeUnixNano) + end = max(end, span.EndTimeUnixNano) + } + } + } + + startSeconds := uint32(start / uint64(time.Second)) + endSeconds := uint32(end / uint64(time.Second)) + + if err := i.AppendTrace(req.Ids[j], tr, startSeconds, endSeconds); err != nil { return err } } From 9dc55bb2a884512878cec4de9b1027b1bcd7cc4e Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 3 Dec 2024 15:34:37 +0100 Subject: [PATCH 2/2] Different code, same result --- modules/blockbuilder/partition_writer.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/blockbuilder/partition_writer.go b/modules/blockbuilder/partition_writer.go index 5711de55ac8..998b575fe26 100644 --- a/modules/blockbuilder/partition_writer.go +++ b/modules/blockbuilder/partition_writer.go @@ -3,7 +3,6 @@ package blockbuilder import ( "context" "fmt" - "math" "sync" "time" @@ -69,12 +68,16 @@ func (p *writer) pushBytes(tenant string, req *tempopb.PushBytesRequest) error { return fmt.Errorf("failed to unmarshal trace: %w", err) } - start, end := uint64(math.MaxUint64), uint64(0) - for _, rs := range tr.ResourceSpans { - for _, ss := range rs.ScopeSpans { - for _, span := range ss.Spans { - start = min(start, span.StartTimeUnixNano) - end = max(end, span.EndTimeUnixNano) + var start, end uint64 + for _, b := range tr.ResourceSpans { + for _, ss := range b.ScopeSpans { + for _, s := range ss.Spans { + if start == 0 || s.StartTimeUnixNano < start { + start = s.StartTimeUnixNano + } + if s.EndTimeUnixNano > end { + end = s.EndTimeUnixNano + } } } }