backendRequest builds backend requests to search backend blocks. backendRequest takes ownership of reqCh and closes it. it returns 3 int values: totalBlocks, totalBlockBytes, and estimated jobs
(ctx context.Context, tenantID string, parent pipeline.Request, searchReq *tempopb.SearchRequest, resp *combiner.SearchJobResponse, reqCh chan<- pipeline.Request, errFn func(error))
| 137 | // backendRequest builds backend requests to search backend blocks. backendRequest takes ownership of reqCh and closes it. |
| 138 | // it returns 3 int values: totalBlocks, totalBlockBytes, and estimated jobs |
| 139 | func (s *asyncSearchSharder) backendRequests(ctx context.Context, tenantID string, parent pipeline.Request, searchReq *tempopb.SearchRequest, resp *combiner.SearchJobResponse, reqCh chan<- pipeline.Request, errFn func(error)) { |
| 140 | // request without start or end, search only in ingester |
| 141 | if searchReq.Start == 0 || searchReq.End == 0 { |
| 142 | close(reqCh) |
| 143 | return |
| 144 | } |
| 145 | |
| 146 | // calculate duration (start and end) to search the backend blocks |
| 147 | start, end := backendRange(searchReq.Start, searchReq.End, s.cfg.QueryBackendAfter) |
| 148 | |
| 149 | // no need to search backend |
| 150 | if start == end { |
| 151 | close(reqCh) |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | startT := time.Unix(int64(start), 0) |
| 156 | endT := time.Unix(int64(end), 0) |
| 157 | |
| 158 | blocks := blockMetasForSearch(s.reader.BlockMetas(tenantID), startT, endT, acceptAllBlocks) |
| 159 | |
| 160 | // calculate metrics to return to the caller |
| 161 | resp.TotalBlocks = len(blocks) |
| 162 | |
| 163 | firstShardIdx := len(resp.Shards) |
| 164 | blockIter := backendJobsFunc(blocks, s.cfg.TargetBytesPerRequest, s.cfg.MostRecentShards, searchReq.End) |
| 165 | blockIter(func(jobs int, sz uint64, completedThroughTime uint32) { |
| 166 | resp.TotalJobs += jobs |
| 167 | resp.TotalBytes += sz |
| 168 | |
| 169 | resp.Shards = append(resp.Shards, shardtracker.Shard{ |
| 170 | TotalJobs: uint32(jobs), |
| 171 | CompletedThroughSeconds: completedThroughTime, |
| 172 | }) |
| 173 | }, nil) |
| 174 | |
| 175 | go func() { |
| 176 | buildBackendRequests(ctx, tenantID, parent, searchReq, firstShardIdx, blockIter, reqCh, errFn) |
| 177 | }() |
| 178 | } |
| 179 | |
| 180 | // ingesterRequest returns a new start and end time range for the backend as well as an http request |
| 181 | // that covers the ingesters. If nil is returned for the http.Request then there is no ingesters query. |