grafana / clickhouse-datasource

Grafana Plugin for ClickHouse
Apache License 2.0
127 stars 58 forks source link

timeInterval doesn't work for month granularity #911

Closed mzealey closed 1 month ago

mzealey commented 1 month ago

I'm using $__timeInterval and want to get a monthly summary (changeable to daily etc via drop-down variable). However because it's using a simple seconds since epoch calculation it comes out with grouping on 16/17 of month at present.

A $__timeIntervalStartOf type macro would be really useful that uses the toStartOfInterval function to produce the expected/correct result in this case.

SpencerTorres commented 1 month ago

I want to avoid adding too many macros like this, especially when ClickHouse has functions built in for these types of time operations.

Can you show me an example of a query you would write with the macro vs without the macro? You should be able to use the other macros/variables to accomplish this, such as $__fromTime and $__toTime. This will give you a DateTime value that you can plug into the ClickHouse functions.

Thanks for the suggestion!

mzealey commented 1 month ago

This sounds reasonable, however it is a real pain (if even possible) to convert the interval from grafana (either seconds or 1M format) into "interval 1 month". So perhaps a $__intervalSql type variable that does this?

SpencerTorres commented 1 month ago

Good point, we actually have an issue open for this (#528)

We can close this issue in favor of that one since it's already been triaged as a feature request