I couldn't figure out how to achieve this, hope I haven't missed something obvious 😅
What happened:
I want to use the "auto" interval option in Grafana so that the interval adjusts itself, but I also want the user to be able to to override it by selecting an interval.
What you expected to happen:
The auto interval should be be compatible with the Clickhouse interval format.
How to reproduce it (as minimally and precisely as possible):
Configure an "interval" variable and pass it to any query, e.g.
select toStartOfInterval(time, interval ${interval}), count(*) from metric group by 1
Since the interval format in Grafana isn't compatible with Clickhouse this fails (e.g. Grafana passes in 1m):
default :) select toStartOfInterval(time, interval 1m), count(*) from metric group by 1
Syntax error: failed at position 43 (')'):
It was fairly simple to work around this using a Clickhouse function:
create or replace function _grafana_interval_to_clickhouse_interval as (grafana_interval) ->
-- grafana uses the following format for intervals: 1s, 1m, 1h, 1d
-- clickhouse uses 1 second, 1 minute, 1 hour, 1 day
concat(
substring(grafana_interval, 1, length(grafana_interval) - 1),
' ',
multiIf(
right(grafana_interval, 1) = 's', 'second',
right(grafana_interval, 1) = 'm', 'minute',
right(grafana_interval, 1) = 'h', 'hour',
right(grafana_interval, 1) = 'd', 'day',
'unknown interval'));
But it would be great if the plugin had a macro for this so you could write something like:
select toStartOfInterval(time, interval ${__fromGrafanaInterval(interval)}), count(*) from metric group by 1
Environment:
- Grafana version: 9.4.2
- Plugin version: 3.3.0
I couldn't figure out how to achieve this, hope I haven't missed something obvious 😅
What happened:
I want to use the "auto" interval option in Grafana so that the interval adjusts itself, but I also want the user to be able to to override it by selecting an interval.
What you expected to happen:
The auto interval should be be compatible with the Clickhouse interval format.
How to reproduce it (as minimally and precisely as possible):
Configure an "interval" variable and pass it to any query, e.g.
Since the interval format in Grafana isn't compatible with Clickhouse this fails (e.g. Grafana passes in
1m):It was fairly simple to work around this using a Clickhouse function:
But it would be great if the plugin had a macro for this so you could write something like:
Environment: