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

Bug in Alert Translation with backticks #50

Open
navinpai opened this issue Sep 11, 2023 · 1 comment
Open

Bug in Alert Translation with backticks #50

navinpai opened this issue Sep 11, 2023 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@navinpai
Copy link

Had an alert in SQLite set as below:

> select data from alert_rule;
[{"refId":"A","queryType":"instant","relativeTimeRange":{"from":300,"to":0},"datasourceUid":"loki","model":{"datasource":{"type":"loki","uid":"loki"},"editorMode":"builder","expr":"{container_name=\"/app-demo\"} |= `debug`","hide":false,"intervalMs":1000,"maxDataPoints":43200,"maxLines":null,"queryType":"instant","refId":"A"}},{"refId":"B","queryType":"","relativeTimeRange":{"from":300,"to":0},"datasourceUid":"__expr__","model":{"conditions":[{"evaluator":{"params":[],"type":"gt"},"operator":{"type":"and"},"query":{"params":["B"]},"reducer":{"params":[],"type":"last"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"A","hide":false,"intervalMs":1000,"maxDataPoints":43200,"reducer":"min","refId":"B","settings":{"mode":""},"type":"reduce"}},{"refId":"C","queryType":"","relativeTimeRange":{"from":300,"to":0},"datasourceUid":"__expr__","model":{"conditions":[{"evaluator":{"params":[0],"type":"gt"},"operator":{"type":"and"},"query":{"params":["C"]},"reducer":{"params":[],"type":"last"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"B","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"C","type":"threshold"}}]

Note the `debug` in the rule

When this was migrated to postgres, it converted it as:

> select data from alert_rule;
[{"refId":"A","queryType":"instant","relativeTimeRange":{"from":300,"to":0},"datasourceUid":"loki","model":{"datasource":{"type":"loki","uid":"loki"},"editorMode":"builder","expr":"{container_name=\"/app-demo\"} |= "debug"","hide":false,"intervalMs":1000,"maxDataPoints":43200,"maxLines":null,"queryType":"instant","refId":"A"}},{"refId":"B","queryType":"","relativeTimeRange":{"from":300,"to":0},"datasourceUid":"__expr__","model":{"conditions":[{"evaluator":{"params":[],"type":"gt"},"operator":{"type":"and"},"query":{"params":["B"]},"reducer":{"params":[],"type":"last"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"A","hide":false,"intervalMs":1000,"maxDataPoints":43200,"reducer":"min","refId":"B","settings":{"mode":""},"type":"reduce"}},{"refId":"C","queryType":"","relativeTimeRange":{"from":300,"to":0},"datasourceUid":"__expr__","model":{"conditions":[{"evaluator":{"params":[0],"type":"gt"},"operator":{"type":"and"},"query":{"params":["C"]},"reducer":{"params":[],"type":"last"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"B","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"C","type":"threshold"}}]

which gives the following error in Grafana:

logger=ngalert.scheduler t=2023-09-11T05:59:10.015884274Z level=error msg="Failed to update alert rules" error="failed to get alert rules: failed to fetch alert rules: invalid character 'd' after object key:value pair"

The error seems to be how ` is converted to " without escaping it. To solve it, I had to manually update my DB to change the "debug" to \"debug\"

@wbh1 wbh1 added the help wanted Extra attention is needed label Sep 11, 2023
@asantoni
Copy link

A similar bug exists if you use quotes (") in the annotations column, which I documented in this Grafana bug comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants