MCPcopy
hub / github.com/grafana/tempo / ConsumeWithFinal

Method ConsumeWithFinal

tempodb/encoding/vparquet3/combiner.go:46–127  ·  view source on GitHub ↗

ConsumeWithFinal consumes the trace, but allows for performance savings when it is known that this is the last expected input trace.

(tr *Trace, final bool)

Source from the content-addressed store, hash-verified

44// ConsumeWithFinal consumes the trace, but allows for performance savings when
45// it is known that this is the last expected input trace.
46func (c *Combiner) ConsumeWithFinal(tr *Trace, final bool) (spanCount int) {
47 if tr == nil {
48 return
49 }
50
51 // First call?
52 if c.result == nil {
53 c.result = tr
54
55 // Pre-alloc map with input size. This saves having to grow the
56 // map from the small starting size.
57 n := 0
58 for _, b := range c.result.ResourceSpans {
59 for _, ils := range b.ScopeSpans {
60 n += len(ils.Spans)
61 }
62 }
63 c.spans = make(map[uint64]struct{}, n)
64
65 for _, b := range c.result.ResourceSpans {
66 for _, ils := range b.ScopeSpans {
67 for _, s := range ils.Spans {
68 c.spans[util.SpanIDAndKindToToken(s.SpanID, s.Kind)] = struct{}{}
69 }
70 }
71 }
72 return
73 }
74
75 // coalesce root level information
76 if tr.EndTimeUnixNano > c.result.EndTimeUnixNano {
77 c.result.EndTimeUnixNano = tr.EndTimeUnixNano
78 }
79 if tr.StartTimeUnixNano < c.result.StartTimeUnixNano || c.result.StartTimeUnixNano == 0 {
80 c.result.StartTimeUnixNano = tr.StartTimeUnixNano
81 }
82 if c.result.RootServiceName == "" {
83 c.result.RootServiceName = tr.RootServiceName
84 }
85 if c.result.RootSpanName == "" {
86 c.result.RootSpanName = tr.RootSpanName
87 }
88 c.result.DurationNano = c.result.EndTimeUnixNano - c.result.StartTimeUnixNano
89
90 // loop through every span and copy spans in B that don't exist to A
91 for _, b := range tr.ResourceSpans {
92 notFoundILS := b.ScopeSpans[:0]
93
94 for _, ils := range b.ScopeSpans {
95 notFoundSpans := ils.Spans[:0]
96 for _, s := range ils.Spans {
97 // if not already encountered, then keep
98 token := util.SpanIDAndKindToToken(s.SpanID, s.Kind)
99 _, ok := c.spans[token]
100 if !ok {
101 notFoundSpans = append(notFoundSpans, s)
102
103 // If last expected input, then we don't need to record

Callers 5

CompactMethod · 0.95
BenchmarkCombineFunction · 0.95
combineTracesFunction · 0.95
ConsumeMethod · 0.95
FindTraceByIDMethod · 0.95

Calls 1

SpanIDAndKindToTokenFunction · 0.92

Tested by 1

BenchmarkCombineFunction · 0.76