clickhouse-datasource icon indicating copy to clipboard operation
clickhouse-datasource copied to clipboard

grafana's $__to and $__from are not supported in alerts

Open vbichov opened this issue 7 months ago • 1 comments

What happened:

I tried using grafana's $__from and $__to variables

in alert condition but got the following exception when testing alert condition:

request handler response error {error querying the database: code: 62, message: Syntax error: failed at position 861 ('$') (line 27, col 68): ${__from} / 1000))) and t < toStartOfMinute(toDateTime(toInt32(${__to} / 1000)))
    -- where t + interval 1 hour > (toDateTime(toInt32(${__from} / 1000))) and . Expected one of: ALL, DISTINCT, token, Comma, ClosingRoundBracket, CAST operator, NOT, INTERVAL, CASE, DATE, TIMESTAMP, tuple, collection of literals, array, number, literal, NULL, NULL, Bool, TRUE, FALSE, string literal, asterisk, qualified asterisk, compound identifier, list of elements, identifier, COLUMNS matcher, COLUMNS, qualified COLUMNS matcher, substitution, MySQL-style global variable  A <nil> [] [] 0xc003e27170}"

What you expected to happen:

alert evaluation should have been successful

How to reproduce it (as minimally and precisely as possible):

  1. run grafana 10.3.3 with legacy alerting enabled

  2. create a graph pannel with query that uses $__from an $__to in it:

select $__timeInterval(date_created) as t, count() from your_table
where date_created < toDateTime(${__to} / 1000) and date_created > toDateTime(${__from} / 1000)
group by t
order by t
  1. make sure the graph works

  2. go to legacy alerts page - try to press Test rule

Screenshots

Environment:

  • Grafana version: 10.3.3
  • Plugin version: 4.2.0
  • OS Grafana is installed on: linux
  • User OS & Browser: chrome
  • Others:

vbichov avatar Jul 02 '24 10:07 vbichov