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

unable to query alerts api for more than 2 tags. / params #1884

Open
streaming-pete opened this issue Oct 9, 2023 · 1 comment
Open

unable to query alerts api for more than 2 tags. / params #1884

streaming-pete opened this issue Oct 9, 2023 · 1 comment

Comments

@streaming-pete
Copy link

Issue Summary
When trying to filter results via the API (or UI) using tags, we are unable to use more than 2 tags.

Environment

  • OS: Linux

  • API version: 9.0.1

  • Deployment: Local / K8s

  • For self-hosted, WSGI environment: nginx / pycharm

  • Database: Postgres & Mongo

  • Server config:
    Auth enabled? Yes for Prod, No for Dev
    Customer views? No

  • web UI version: n/a

  • CLI version: n/a

To Reproduce
Steps to reproduce the behavior:
create 3 alerts with unique tags. eg
alerta send -r test4 -e test4 -S test4 -t test4 -T dc=tag1 -E Production -s major
alerta send -r test3 -e test3 -S test3 -t test3 -T dc=tag2 -E Production -s major
alerta send -r test2 -e test2 -S test2 -t test2 -T dc=tag3 -E Production -s major

query api with following params

/alerts?q=tags%3A"dc%3Dtag1"+tags%3A"dc%3Dtag2"+tags%3A"dc%3Dtag3"

response will only be for tag1 + tag2.

code generates: "('dc=tag1'=ANY("tags") OR 'dc=tag2'=ANY("tags"))"

Expected behavior
all tags in search returned

"('dc=tag1'=ANY("tags") OR 'dc=tag2'=ANY("tags") OR OR 'dc=tag3'=ANY("tags"))"

Screenshots

Additional context
This was a customer request from our ops dept using alerta.

I have done some debugging and testing against mongo and postgres, in debug mode I can trace the params correctly getting to the QueryParser class in queryparser.py and then hitting the query_expr infixNotation() that seems to only handle a left / right or clause. (Optional(OR).setParseAction(lambda: 'OR'), 2, opAssoc.LEFT, SearchOr), this in turn returns an sql query of:

"('dc=tag1'=ANY("tags") OR 'dc=tag2'=ANY("tags"))"

so it looks like the parser for handling multiple query params is locked at 2 even though 3 params were passed into the function.

Appreciate any feedback or guidance on what we could do here to open this up to more parameters for searching.

Thanks
Pete

@streaming-pete
Copy link
Author

streaming-pete commented Oct 9, 2023

Interestingly, I can get up to 4 working by wrapping 2 sets of OR's in brackets via the UI. (I have moved to the tag called channel here which are in my prod system i have lots alerts for)

(tags:"channel=channel010" tags:"channel=channel004") (tags:"channel=channel001" tags:"channel=channel018") = 4 valid alerts

and this seems to continue by wrapping that 4 queries in brackets also works for fulfilling the first OR in the query, this will probably continue forever and is becoming a little unintuitive for the user.

((tags:"channel=channel010" tags:"channel=channel004") (tags:"channel=channel001" tags:"channel=channel018")) (tags:"channel=channel022")` = 5 valid alerts

and a full 11 example..
(((tags:"channel=channel010" tags:"channel=channel023") (tags:"channel=channel018" tags:"channel=channel001")) ((tags:"channel=channel053" tags:"channel=channel049") (tags:"channel=channel062" tags:"channel=channel004"))) (((tags:"channel=channel022" tags:"channel=channel022") (tags:"channel=channel019" tags:"channel=channel005")))

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

No branches or pull requests

1 participant