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

Method ExecuteSearch

pkg/traceql/engine.go:51–180  ·  view source on GitHub ↗

ExecuteSearch executes a search query. Options control AST optimization and hint behavior.

(ctx context.Context, searchReq *tempopb.SearchRequest, fetcher SpansetFetcher, opts ...CompileOption)

Source from the content-addressed store, hash-verified

49
50// ExecuteSearch executes a search query. Options control AST optimization and hint behavior.
51func (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

Callers 15

traceQLRunnerFunction · 0.95
advancedTraceQLRunnerFunction · 0.95
groupTraceQLRunnerFunction · 0.95
traceQLStructuralFunction · 0.95
nestedSetFunction · 0.95
traceQLExistenceFunction · 0.95
traceQLDurationFunction · 0.95

Calls 15

addSpansetMethod · 0.95
IsCompleteForMethod · 0.95
MetadataMethod · 0.95
applyCompileOptionsFunction · 0.85
CompileFunction · 0.85
simulateLatencyFunction · 0.85
unixSecToNanoFunction · 0.85
NewStaticIntFunction · 0.85
NewMetadataCombinerFunction · 0.85
GetDurationMethod · 0.80

Tested by 15

traceQLRunnerFunction · 0.76
advancedTraceQLRunnerFunction · 0.76
groupTraceQLRunnerFunction · 0.76
traceQLStructuralFunction · 0.76
nestedSetFunction · 0.76
traceQLExistenceFunction · 0.76
traceQLDurationFunction · 0.76