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

Function traceQLRunner

tempodb/tempodb_search_test.go:90–164  ·  view source on GitHub ↗
(t *testing.T, _ *tempopb.Trace, wantMeta *tempopb.TraceSearchMetadata, searchesThatMatch, searchesThatDontMatch []*tempopb.SearchRequest, meta *backend.BlockMeta, r Reader, _ common.BackendBlock)

Source from the content-addressed store, hash-verified

88}
89
90func traceQLRunner(t *testing.T, _ *tempopb.Trace, wantMeta *tempopb.TraceSearchMetadata, searchesThatMatch, searchesThatDontMatch []*tempopb.SearchRequest, meta *backend.BlockMeta, r Reader, _ common.BackendBlock) {
91 ctx := context.Background()
92 e := traceql.NewEngine()
93
94 quotedAttributesThatMatch := []*tempopb.SearchRequest{
95 {Query: fmt.Sprintf("{ .%q = %q }", attributeWithTerminalChars, "foobaz")},
96 {Query: fmt.Sprintf("{ .%q = %q }", attributeWithTerminalChars, "foobar")},
97 {Query: `{ ."res-dedicated.02" = "res-2a" }`},
98 {Query: `{ resource."k8s.namespace.name" = "k8sNamespace" }`},
99 }
100 optimizedSearchesThatMatch := []*tempopb.SearchRequest{
101 {Query: `{ resource.service.name = "MyService" || resource.service.name = "does-not-exist" }`},
102 {Query: `{ resource.service.name = "does-not-exist" || resource.service.name = "RootService" }`},
103 {Query: `{ resource.res-dedicated.01 = "res-1a" || resource.res-dedicated.01 = "res-1b" }`},
104 {Query: `{ resource.res-dedicated.01 != "res-2a" && resource.res-dedicated.01 != "res-2b" }`},
105 {Query: `{ resource.res-dedicated.01 =~ "does-not-exist" || resource.res-dedicated.01 =~ "res-1.*" }`},
106 {Query: `{ resource.res-dedicated.01 !~ "res-2.*" && resource.res-dedicated.01 !~ "res-3.*" }`},
107 {Query: `{ span.foo="Bar" || span.foo="does-not-exist" }`},
108 {Query: `{ span.foo!="does-not-exist-1" && span.foo!="does-not-exist-2" }`},
109 {Query: `{ span.span-dedicated.01 = "span-1a" || span.span-dedicated.01 = "span-1b" }`},
110 {Query: `{ span.span-dedicated.01 != "span-2a" && span.span-dedicated.01 != "span-2b" }`},
111 {Query: `{ span.span-dedicated.01 =~ "does-not-exist" || span.span-dedicated.01 =~ "span-1.*" }`},
112 {Query: `{ span.span-dedicated.01 !~ "span-2.*" && span.span-dedicated.01 !~ "span-3.*" }`},
113 }
114 parentID := util.SpanIDToHexString([]byte{4, 5, 6})
115 parentIDQuery := &tempopb.SearchRequest{
116 Query: fmt.Sprintf("{ span:parentID = %q }", parentID),
117 }
118
119 searchesThatMatch = append(searchesThatMatch, quotedAttributesThatMatch...)
120 searchesThatMatch = append(searchesThatMatch, parentIDQuery)
121 searchesThatMatch = append(searchesThatMatch, optimizedSearchesThatMatch...)
122 for _, req := range searchesThatMatch {
123 fetcher := traceql.NewSpansetFetcherWrapper(func(ctx context.Context, req traceql.FetchSpansRequest) (traceql.FetchSpansResponse, error) {
124 return r.Fetch(ctx, meta, req, common.DefaultSearchOptions())
125 })
126
127 res, err := e.ExecuteSearch(ctx, req, fetcher)
128 if errors.Is(err, util.ErrUnsupported) {
129 continue
130 }
131
132 require.NoError(t, err, "search request: %+v", req)
133 actual := actualForExpectedMeta(wantMeta, res)
134 require.NotNil(t, actual, "search request: %v", req)
135 actual.SpanSet = nil // todo: add the matching spansets to wantmeta
136 actual.SpanSets = nil
137 actual.ServiceStats = nil
138 require.Equal(t, wantMeta, actual, "search request: %v", req)
139 }
140
141 quotedAttributesThatDontMatch := []*tempopb.SearchRequest{
142 {Query: fmt.Sprintf("{ .%q = %q }", attributeWithTerminalChars, "value mismatch")},
143 {Query: `{ ."unknow".attribute = "res-2a" }`},
144 {Query: `{ resource."resource attribute" = "unknown" }`},
145 }
146 optimizedSearchesThatDontMatch := []*tempopb.SearchRequest{
147 {Query: `{ resource.service.name = "does-not-exist-1" || resource.service.name = "does-not-exist-2" }`},

Callers

nothing calls this directly

Calls 8

ExecuteSearchMethod · 0.95
NewEngineFunction · 0.92
SpanIDToHexStringFunction · 0.92
NewSpansetFetcherWrapperFunction · 0.92
DefaultSearchOptionsFunction · 0.92
actualForExpectedMetaFunction · 0.85
FetchMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected