fr-ser / grafana-sqlite-datasource

Grafana Plugin to enable SQLite as a Datasource
Apache License 2.0
126 stars 17 forks source link

feat: Support timeFilter query macro #138

Closed toluschr closed 3 months ago

toluschr commented 5 months ago

Grafana is really unresponsive when using this plugin for large datasets. Implementing the __timeFilter macro results in a significant speedup.

In addition to this, future candidates could be $__timeFrom() and $__timeFrom().

fr-ser commented 5 months ago

I'll take a look later. But for me to better understand: The macro is a helper that formats a query. The performance issue you describe should be solvable without the macro as well, right?

toluschr commented 5 months ago

I'll take a look later. But for me to better understand: The macro is a helper that formats a query. The performance issue you describe should be solvable without the macro as well, right?

It is essentially a shorthand form for:

(timestamp BETWEEN ${__from:date:seconds} AND ${__to:date:seconds})

I wasn't aware that these two variables exist, so I queried everything from the database and filtered afterwards. But I believe the macro could be useful regardless.

SeanCGriffin commented 4 months ago

Just discovered this PR; I am using SQLite as a backend and this macro would be very helpful.

fr-ser commented 3 months ago

@SeanCGriffin could you elaborate how this macro would be helpful for you?

As far as I understand the macro simply "transforms"

$__timeFilter(timestamp)

into

(timestamp BETWEEN ${__from:date:seconds} AND ${__to:date:seconds})

I am not sure yet if adding this macro would be that helpful. After all the macro would be something custom that people need to find in this repos documentation, whereas the variable approach is standard and documented at Grafana's side for all plugins.

fr-ser commented 3 months ago

I will close the PR for now in order to gain some more understanding of the underlying problem.

Let's open an issue if you want to continue on this and we can re-open the PR any time.