Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit early on autocomplete noops #4431

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/traceql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ func (e *Engine) ExecuteTagValues(
span.SetAttributes(attribute.String("pipeline", rootExpr.Pipeline.String()))
span.SetAttributes(attribute.String("autocompleteReq", fmt.Sprint(autocompleteReq)))

// If the tag we are fetching is already filtered in the query, then this is a noop.
// I.e. we are autocompleting resource.service.name and the query was {resource.service.name="foo"}
for _, c := range autocompleteReq.Conditions {
if c.Attribute == tag && c.Op == OpEqual {
return nil
}
}

return fetcher.Fetch(ctx, autocompleteReq, cb)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/traceql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,12 @@ func TestExecuteTagValues(t *testing.T) {
{Type: "string", Value: "redis call"},
},
},
{
name: "noop", // autocompleting an attribute already filtered by the query
attribute: "name",
query: `{ name = "foo" }`,
expectedValues: []tempopb.TagValue{},
},
} {
t.Run(tc.name, func(t *testing.T) {
distinctValues := collector.NewDistinctValue[tempopb.TagValue](100_000, 0, 0, func(v tempopb.TagValue) int { return len(v.Type) + len(v.Value) })
Expand Down
Loading