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

Method backendRequests

modules/frontend/search_sharder.go:139–178  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

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
139func (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.

Callers 2

TestBackendRequestsFunction · 0.95
RoundTripMethod · 0.95

Calls 5

backendRangeFunction · 0.85
blockMetasForSearchFunction · 0.85
backendJobsFuncFunction · 0.85
buildBackendRequestsFunction · 0.85
BlockMetasMethod · 0.65

Tested by 1

TestBackendRequestsFunction · 0.76