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

Loki: Fix filters not being added with multiple expressions and parsers #75152

Merged
merged 2 commits into from
Sep 20, 2023

Conversation

svennergr
Copy link
Contributor

What is this feature?

When using a dashboard with adhoc filters and a loki query containing two metric queries and label filters, the ad hoc filter is only added to the last label filter. Previously we determined the last positions of parsers or label filters in the whole query, however we need to do that per sub expression.

Which issue(s) does this PR fix?:

Fixes #75101

How do we reproduce it?

  1. Create a dashboard with a sum(rate({place="luna"} | logfmt [$__auto])) / sum(rate({place="moon"} |json [$__auto])) query.
  2. Add a Loki ad hoc filter.
  3. Apply the ad hoc filter and observe that it is only added to the last subexpression of a query.

@@ -574,9 +588,19 @@ function getAllPositionsInNodeByType(query: string, node: SyntaxNode, type: numb
let pos = 0;
let child = node.childAfter(pos);
while (child) {
positions.push(...getAllPositionsInNodeByType(query, child, type));
positions.push(...getAllPositionsInNodeByType(child, type));
pos = child.to;
child = node.childAfter(pos);
}
return positions;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All those changes above are basically just chores. Let me know if I should remove them.

@github-actions
Copy link
Contributor

Backend code coverage report for PR #75152
No changes

@github-actions
Copy link
Contributor

Frontend code coverage report for PR #75152

Plugin Main PR Difference
loki 85.39% 85.42% .03%

@svennergr svennergr merged commit 480aa1c into main Sep 20, 2023
16 checks passed
@svennergr svennergr deleted the svennergr/loki-fix-adhoc branch September 20, 2023 14:54
@grafana-delivery-bot
Copy link
Contributor

The backport to v10.1.x 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-75152-to-v10.1.x origin/v10.1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 480aa1ccca03f267907c685a0f2358a9793ff677
# 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-75152-to-v10.1.x
# Create the PR body template
PR_BODY=$(gh pr view 75152 --json body --template 'Backport 480aa1ccca03f267907c685a0f2358a9793ff677 from #75152{{ "\n\n---\n\n" }}{{ index . "body" }}')
# Create the PR on GitHub
echo "${PR_BODY}" | gh pr create --title "[v10.1.x] Loki: Fix filters not being added with multiple expressions and parsers" --body-file - --label "type/bug" --label "area/frontend" --label "datasource/Loki" --label "add to changelog" --label "backport" --base v10.1.x --milestone 10.1.x --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-75152-to-v10.1.x

# Create a pull request where the `base` branch is `v10.1.x` and the `compare`/`head` branch is `backport-75152-to-v10.1.x`.

# Remove the local backport branch
git switch main
git branch -D backport-75152-to-v10.1.x

@grafana-delivery-bot grafana-delivery-bot bot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Sep 20, 2023
svennergr added a commit that referenced this pull request Sep 20, 2023
…rs (#75152)

* determine last positions per expr

* fix lint

(cherry picked from commit 480aa1c)
svennergr added a commit that referenced this pull request Sep 20, 2023
… and parsers (#75172)

Loki: Fix filters not being added with multiple expressions and parsers (#75152)

* determine last positions per expr

* fix lint

(cherry picked from commit 480aa1c)
rwwiv pushed a commit that referenced this pull request Oct 2, 2023
…rs (#75152)

* determine last positions per expr

* fix lint
@zerok zerok modified the milestones: 10.2.x, 10.2.0 Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend backport v10.1.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. datasource/Loki type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loki: Ad hoc filters not added to every query expression if label filters are used
3 participants