AddMetadata adds the new metadata to the map. if it already exists use CombineSearchResults to combine the two
(meta *tempopb.TraceSearchMetadata)
| 148 | // AddMetadata adds the new metadata to the map. if it already exists |
| 149 | // use CombineSearchResults to combine the two |
| 150 | func (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 | |
| 180 | func (c *mostRecentCombiner) Count() int { |
| 181 | return len(c.trs) |
no test coverage detected