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

Method Search

modules/livestore/instance_search.go:193–297  ·  view source on GitHub ↗
(ctx context.Context, req *tempopb.SearchRequest)

Source from the content-addressed store, hash-verified

191}
192
193func (i *instance) Search(ctx context.Context, req *tempopb.SearchRequest) (*tempopb.SearchResponse, error) {
194 ctx, span := tracer.Start(ctx, "instance.Search")
195 defer span.End()
196
197 maxResults := int(req.Limit)
198 // if limit is not set, use a safe default
199 if maxResults == 0 {
200 maxResults = 20
201 }
202
203 span.AddEvent("SearchRequest", oteltrace.WithAttributes(attribute.String("request", req.String())))
204
205 mostRecent := false
206 if len(req.Query) > 0 {
207 rootExpr, err := traceql.ParseNoOptimizations(req.Query)
208 if err != nil {
209 return nil, fmt.Errorf("error parsing query: %w", err)
210 }
211
212 ok := false
213 if mostRecent, ok = rootExpr.Hints.GetBool(traceql.HintMostRecent, false); !ok {
214 mostRecent = false
215 }
216 }
217
218 var (
219 resultsMtx = sync.Mutex{}
220 combiner = traceql.NewMetadataCombiner(maxResults, mostRecent)
221 metrics = &tempopb.SearchMetrics{}
222 opts = common.DefaultSearchOptions()
223 )
224
225 search := func(ctx context.Context, blockMeta *backend.BlockMeta, b block) error {
226 var resp *tempopb.SearchResponse
227 var err error
228
229 // if the combiner is complete for the block's end time, we can skip searching it
230 if combiner.IsCompleteFor(uint32(blockMeta.EndTime.Unix())) {
231 return errComplete
232 }
233
234 if api.IsTraceQLQuery(req) {
235 f := traceql.NewSpansetFetcherWrapperBoth(
236 func(ctx context.Context, req traceql.FetchSpansRequest) (traceql.FetchSpansResponse, error) {
237 return b.Fetch(ctx, req, opts)
238 },
239 func(ctx context.Context, req traceql.FetchSpansRequest) (traceql.FetchSpansOnlyResponse, error) {
240 return b.FetchSpans(ctx, req, opts)
241 },
242 )
243 // note: we are creating new engine for each wal block,
244 // and engine.ExecuteSearch is parsing the query for each block
245 var searchOpts []traceql.CompileOption
246 if i.overrides.UnsafeQueryHints(i.tenantID) {
247 searchOpts = append(searchOpts, traceql.WithUnsafeHints(true))
248 }
249 for _, name := range req.SkipASTTransformations {
250 searchOpts = append(searchOpts, traceql.WithSkipOptimization(name))

Callers

nothing calls this directly

Calls 15

iterateBlocksMethod · 0.95
ParseNoOptimizationsFunction · 0.92
NewMetadataCombinerFunction · 0.92
DefaultSearchOptionsFunction · 0.92
IsTraceQLQueryFunction · 0.92
WithUnsafeHintsFunction · 0.92
WithSkipOptimizationFunction · 0.92
NewEngineFunction · 0.92
GetBoolMethod · 0.80
ExecuteSearchMethod · 0.80
StartMethod · 0.65

Tested by

no test coverage detected