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

Method AddMetadata

pkg/traceql/combine.go:150–178  ·  view source on GitHub ↗

AddMetadata adds the new metadata to the map. if it already exists use CombineSearchResults to combine the two

(meta *tempopb.TraceSearchMetadata)

Source from the content-addressed store, hash-verified

148// AddMetadata adds the new metadata to the map. if it already exists
149// use CombineSearchResults to combine the two
150func (c *mostRecentCombiner) AddMetadata(meta *tempopb.TraceSearchMetadata) bool {
151 if existing, ok := c.trs[meta.TraceID]; ok {
152 combineSearchResults(existing, meta)
153 return true
154 }
155
156 if c.Count() == c.keepMostRecent && c.keepMostRecent > 0 {
157 // if this is older than the oldest element, bail
158 if c.OldestTimestampNanos() > meta.StartTimeUnixNano {
159 return false
160 }
161
162 // otherwise remove the oldest element and we'll add the new one below
163 oldest := c.trsSorted[c.Count()-1]
164 delete(c.trs, oldest.TraceID)
165 c.trsSorted = c.trsSorted[:len(c.trsSorted)-1]
166 }
167
168 // insert new in the right spot
169 c.trs[meta.TraceID] = meta
170 idx, _ := slices.BinarySearchFunc(c.trsSorted, meta, func(a, b *tempopb.TraceSearchMetadata) int {
171 if a.StartTimeUnixNano > b.StartTimeUnixNano {
172 return -1
173 }
174 return 1
175 })
176 c.trsSorted = slices.Insert(c.trsSorted, idx, meta)
177 return true
178}
179
180func (c *mostRecentCombiner) Count() int {
181 return len(c.trs)

Callers 1

addSpansetMethod · 0.95

Calls 4

CountMethod · 0.95
OldestTimestampNanosMethod · 0.95
combineSearchResultsFunction · 0.85
InsertMethod · 0.80

Tested by

no test coverage detected