ExecuteSearch executes a search query. Options control AST optimization and hint behavior.
(ctx context.Context, searchReq *tempopb.SearchRequest, fetcher SpansetFetcher, opts ...CompileOption)
| 49 | |
| 50 | // ExecuteSearch executes a search query. Options control AST optimization and hint behavior. |
| 51 | func (e *Engine) ExecuteSearch(ctx context.Context, searchReq *tempopb.SearchRequest, fetcher SpansetFetcher, opts ...CompileOption) (*tempopb.SearchResponse, error) { |
| 52 | ctx, span := tracer.Start(ctx, "traceql.Engine.ExecuteSearch") |
| 53 | defer span.End() |
| 54 | |
| 55 | cfg := applyCompileOptions(opts...) |
| 56 | rootExpr, _, _, _, fetchSpansRequest, err := Compile(searchReq.Query, opts...) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | |
| 61 | // Check for performance testing hints |
| 62 | if returnIn, ok := rootExpr.Hints.GetDuration(HintDebugReturnIn, cfg.allowUnsafeHints); ok { |
| 63 | var stdDev time.Duration |
| 64 | if stdDevDuration, ok := rootExpr.Hints.GetDuration(HintDebugStdDev, cfg.allowUnsafeHints); ok { |
| 65 | stdDev = stdDevDuration |
| 66 | } |
| 67 | simulateLatency(returnIn, stdDev) |
| 68 | |
| 69 | var probability float64 |
| 70 | if p, ok := rootExpr.Hints.GetFloat(HintDebugDataFactor, cfg.allowUnsafeHints); ok { |
| 71 | probability = p |
| 72 | } |
| 73 | return generateFakeSearchResponse(probability), nil |
| 74 | } |
| 75 | |
| 76 | var mostRecent, ok bool |
| 77 | if mostRecent, ok = rootExpr.Hints.GetBool(HintMostRecent, cfg.allowUnsafeHints); !ok { |
| 78 | mostRecent = false |
| 79 | } |
| 80 | |
| 81 | if rootExpr.IsNoop() { |
| 82 | return &tempopb.SearchResponse{ |
| 83 | Traces: nil, |
| 84 | Metrics: &tempopb.SearchMetrics{}, |
| 85 | }, nil |
| 86 | } |
| 87 | |
| 88 | fetchSpansRequest.StartTimeUnixNanos = unixSecToNano(searchReq.Start) |
| 89 | fetchSpansRequest.EndTimeUnixNanos = unixSecToNano(searchReq.End) |
| 90 | |
| 91 | span.SetAttributes(attribute.String("pipeline", rootExpr.Pipeline.String())) |
| 92 | span.SetAttributes(attribute.String("fetchSpansRequest", fmt.Sprint(fetchSpansRequest))) |
| 93 | |
| 94 | // calculate search meta conditions. |
| 95 | meta := SearchMetaConditionsWithout(fetchSpansRequest.Conditions, fetchSpansRequest.AllConditions) |
| 96 | fetchSpansRequest.SecondPassConditions = append(fetchSpansRequest.SecondPassConditions, meta...) |
| 97 | |
| 98 | spansetsEvaluated := 0 |
| 99 | // set up the expression evaluation as a filter to reduce data pulled |
| 100 | fetchSpansRequest.SecondPass = func(inSS *Spanset) ([]*Spanset, error) { |
| 101 | if inSS == nil || len(inSS.Spans) == 0 { |
| 102 | return nil, nil |
| 103 | } |
| 104 | |
| 105 | evalSS, err := rootExpr.Pipeline.evaluate([]*Spanset{inSS}) |
| 106 | if err != nil { |
| 107 | span.RecordError(err, trace.WithAttributes(attribute.String("msg", "pipeline.evaluate"))) |
| 108 | return nil, err |