Skip to content

Support OR conditions for search tags and search tag values v2#6827

Merged
ie-pham merged 33 commits intografana:mainfrom
ie-pham:ortags
Apr 15, 2026
Merged

Support OR conditions for search tags and search tag values v2#6827
ie-pham merged 33 commits intografana:mainfrom
ie-pham:ortags

Conversation

@ie-pham
Copy link
Copy Markdown
Contributor

@ie-pham ie-pham commented Mar 30, 2026

What this PR does:
Adds OR support to the tag name and tag value autocomplete endpoints (search tags v2 / FetchTagNames / FetchTagValues).

Previously, the autocomplete path only handled a single flat list of AND-connected conditions extracted from the query filter. This PR replaces that with ExtractConditionGroups, which splits the query filter into multiple condition groups by expanding OR clauses — each group represents one AND-connected branch of the OR.

How condition splitting works

Given a query like { (.a="1" || .b="2") && .c="3" }, the filter expression is first flattened to remove nested binary operations. Then flatten group of operations are converted into condition groups. For the example above it produces two groups:

[.a="1", .c="3"]
[.b="2", .c="3"]

To avoid exponential blowup from queries with many OR clauses, the default maxConditionGroups = 100 but operators of tempo can configure this value. Queries that exceed the cap would result in an error.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copilot AI review requested due to automatic review settings March 30, 2026 03:27

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings March 31, 2026 03:33

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Comment thread pkg/traceql/lenient_extract.go Outdated
Comment thread pkg/traceql/lenient_extract.go Outdated
if extractedReq == nil || !extractedReq.AllConditions {
return mcp.NewToolResultError("filter-query invalid. It can only have one spanset and only &&'ed conditions like { <cond> && <cond> && ... }"), nil
conditionGroups := traceql.ExtractConditionGroups(query)
if len(conditionGroups) == 0 {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleGetAttributeValues now rejects filter-query values that parse to match-all (e.g. {} / { true }) because ExtractConditionGroups returns an empty slice for those. Previously {} was accepted. It seems worth treating match-all filters as valid (equivalent to omitting filter-query) to avoid breaking clients that send {} by default.

Suggested change
if len(conditionGroups) == 0 {
if len(conditionGroups) > 1 {

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 31, 2026 21:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

tempodb/encoding/vparquet5/block_autocomplete.go:69

  • In the OR/mingled fast-path, this function can return SearchTags/SearchTagValuesV2 after already calling openForSearch and setting up deferred metrics. That extra parquet open/IO work is then thrown away, and SearchTags/SearchTagValuesV2 will re-open/read again. Could we move the categorizeConditions-based fast-path checks (mingled/trivial conditionGroups) before openForSearch? This same pattern appears in the other vparquet versions and in FetchTagValues as well.
	pf, rr, err := b.openForSearch(ctx, opts)
	if err != nil {
		return err
	}

	// report metrics with defer to handle early exit
	defer mcb(rr.BytesRead())

Comment thread pkg/traceql/lenient_extract.go
Copilot AI review requested due to automatic review settings April 1, 2026 20:48

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings April 2, 2026 02:57
Copilot AI review requested due to automatic review settings April 15, 2026 19:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 31 out of 31 changed files in this pull request and generated no new comments.

@ie-pham ie-pham merged commit 8c5ff8e into grafana:main Apr 15, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants