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

Fix autocomplete panic when condition has wrong type #3277

Merged
merged 3 commits into from
Jan 12, 2024

Conversation

mapno
Copy link
Member

@mapno mapno commented Jan 10, 2024

What this PR does:

It prevents a panic when a filtering query is passed to /search/tag/<tag>/values with a attribute condition (.a=b) where b is a special type (server/client, ok/error/unset) but .a is of a different type (string, int). For example, span.http.status_code=server. This would create iterators with nil predicates and panics when it called iter.Next().

Now, such conditions are ignored and iterators are not built for them.

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]

@@ -358,6 +358,8 @@ func createDistinctAttributeIterator(
}
keyIter = makeIter(keyPath, parquetquery.NewStringInPredicate([]string{cond.Attribute.Name}), selectAs("key", cond.Attribute))
valIter = makeIter(boolPath, pred, selectAs("bool", cond.Attribute))
default:
continue
Copy link
Member Author

@mapno mapno Jan 10, 2024

Choose a reason for hiding this comment

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

Another option is returning an error, but instead opted for ignoring the condition.

The reasoning is that autocomplete should be a smooth experience to the user. If the filtering query has an error, they'll get that feedback via normal search—ie. when they execute the query.

Copy link
Member

Choose a reason for hiding this comment

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

are we missing case statements for things like kind = server and status = ok?

it seems like we should support auto complete on things like:

{ name = "foo" && kind = server && status = error && span.foo = ...

Copy link
Member Author

Choose a reason for hiding this comment

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

That function builds the iterators for the generic attribute columns which don't support those special types.

Copy link
Member

Choose a reason for hiding this comment

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

thx for the clarification.

agree with your initial thought we should just ignore the bad condition over returning an error.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -358,6 +358,8 @@ func createDistinctAttributeIterator(
}
keyIter = makeIter(keyPath, parquetquery.NewStringInPredicate([]string{cond.Attribute.Name}), selectAs("key", cond.Attribute))
valIter = makeIter(boolPath, pred, selectAs("bool", cond.Attribute))
default:
continue
Copy link
Member

Choose a reason for hiding this comment

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

are we missing case statements for things like kind = server and status = ok?

it seems like we should support auto complete on things like:

{ name = "foo" && kind = server && status = error && span.foo = ...

Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
@mapno mapno merged commit b61b12a into grafana:main Jan 12, 2024
14 checks passed
@mapno mapno deleted the autocomplete-panic-bugfix branch January 12, 2024 08:43
Copy link
Contributor

Hello @mapno!
Backport pull requests need to be either:

  • Pull requests which address bugs,
  • Urgent fixes which need product approval, in order to get merged,
  • Docs changes.

Please, if the current pull request addresses a bug fix, label it with the type/bug label.
If it already has the product approval, please add the product-approved label. For docs changes, please add the type/docs label.
If the pull request modifies CI behaviour, please add the type/ci label.
If none of the above applies, please consider removing the backport label and target the next major/minor release.
Thanks!

Copy link
Contributor

The backport to release-v2.3 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-3277-to-release-v2.3 origin/release-v2.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x b61b12acd8844f37f7fee1d6ad15d1acf410755e

When the conflicts are resolved, stage and commit the changes:

git add . && git cherry-pick --continue

If you have the GitHub CLI installed:

# Push the branch to GitHub:
git push --set-upstream origin backport-3277-to-release-v2.3
# Create the PR body template
PR_BODY=$(gh pr view 3277 --json body --template 'Backport b61b12acd8844f37f7fee1d6ad15d1acf410755e from #3277{{ "\n\n---\n\n" }}{{ index . "body" }}')
# Create the PR on GitHub
echo "${PR_BODY}" | gh pr create --title "[release-v2.3] Fix autocomplete panic when condition has wrong type" --body-file - --label "type/bug" --label "area/query" --label "backport" --base release-v2.3 --milestone release-v2.3 --web

Or, if you don't have the GitHub CLI installed (we recommend you install it!):

# Push the branch to GitHub:
git push --set-upstream origin backport-3277-to-release-v2.3

# Create a pull request where the `base` branch is `release-v2.3` and the `compare`/`head` branch is `backport-3277-to-release-v2.3`.

# Remove the local backport branch
git switch main
git branch -D backport-3277-to-release-v2.3

@mapno
Copy link
Member Author

mapno commented Jan 12, 2024

The autocomplete changes weren't released in v2.3. Nothing to backport! 😅

mapno added a commit that referenced this pull request Jan 12, 2024
* Fix autocomplete panic when condition has wrong type

* Add comment

* Update CHANGELOG.md

Co-authored-by: Joe Elliott <joe.elliott@grafana.com>

---------

Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
(cherry picked from commit b61b12a)
mapno added a commit that referenced this pull request Jan 12, 2024
* Fix autocomplete panic when condition has wrong type

* Add comment

* Update CHANGELOG.md

Co-authored-by: Joe Elliott <joe.elliott@grafana.com>

---------

Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
(cherry picked from commit b61b12a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query type/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants