ingesterRequest returns a new start and end time range for the backend as well as an http request that covers the ingesters. If nil is returned for the http.Request then there is no ingesters query. since this function modifies searchReq.Start and End we are taking a value instead of a pointer to pr
(tenantID string, parent pipeline.Request, searchReq tempopb.SearchRequest, reqCh chan pipeline.Request)
| 182 | // since this function modifies searchReq.Start and End we are taking a value instead of a pointer to prevent it from |
| 183 | // unexpectedly changing the passed searchReq. |
| 184 | func (s *asyncSearchSharder) ingesterRequests(tenantID string, parent pipeline.Request, searchReq tempopb.SearchRequest, reqCh chan pipeline.Request) (*combiner.SearchJobResponse, error) { |
| 185 | resp := &combiner.SearchJobResponse{} |
| 186 | resp.Shards = make([]shardtracker.Shard, 0, s.cfg.MostRecentShards+1) // +1 for the ingester shard |
| 187 | |
| 188 | // request without start or end, search only in ingester |
| 189 | if searchReq.Start == 0 || searchReq.End == 0 { |
| 190 | // one shard that covers all time |
| 191 | resp.TotalJobs = 1 |
| 192 | resp.Shards = append(resp.Shards, shardtracker.Shard{ |
| 193 | TotalJobs: 1, |
| 194 | CompletedThroughSeconds: 1, |
| 195 | }) |
| 196 | |
| 197 | return resp, buildIngesterRequest(tenantID, parent, &searchReq, reqCh) |
| 198 | } |
| 199 | |
| 200 | ingesterUntil := uint32(time.Now().Add(-s.cfg.QueryBackendAfter).Unix()) |
| 201 | |
| 202 | // if there's no overlap between the query and ingester range just return nil |
| 203 | if searchReq.End < ingesterUntil { |
| 204 | return resp, nil |
| 205 | } |
| 206 | |
| 207 | ingesterStart := searchReq.Start |
| 208 | ingesterEnd := searchReq.End |
| 209 | |
| 210 | // adjust ingesterStart if necessary |
| 211 | if ingesterStart < ingesterUntil { |
| 212 | ingesterStart = ingesterUntil |
| 213 | } |
| 214 | |
| 215 | // if ingester start == ingester end then we don't need to query it |
| 216 | if ingesterStart == ingesterEnd { |
| 217 | return resp, nil |
| 218 | } |
| 219 | |
| 220 | searchReq.Start = ingesterStart |
| 221 | searchReq.End = ingesterEnd |
| 222 | |
| 223 | // Split the start and end range into sub requests for each range. |
| 224 | duration := searchReq.End - searchReq.Start |
| 225 | interval := duration / uint32(s.cfg.IngesterShards) |
| 226 | intervalMinimum := uint32(60) |
| 227 | |
| 228 | if interval < intervalMinimum { |
| 229 | interval = intervalMinimum |
| 230 | } |
| 231 | |
| 232 | for i := 0; i < s.cfg.IngesterShards; i++ { |
| 233 | var ( |
| 234 | subReq = searchReq |
| 235 | shardStart = ingesterStart + uint32(i)*interval |
| 236 | shardEnd = shardStart + interval |
| 237 | ) |
| 238 | |
| 239 | // stop if we've gone past the end of the range |
| 240 | if shardStart >= ingesterEnd { |
| 241 | break |