Doncarleone512
Doncarleone512

Reputation: 402

Grafana timestamp macro to use with QuestDB

Grafana $__timeFilter(timestamp) macro generates nanosecond precision (for some reason, only on the alert queries, still trying to work out why). QuestDB accepts either epoch microseconds or ISO timestamps strings up to microsecond precision e.g. 1656490564000000 or 2022-06-29T08:16:23.123456Z.

How can I make Grafana to generate filter compatible with QuestDB?

Upvotes: 0

Views: 396

Answers (2)

Javier Ramirez
Javier Ramirez

Reputation: 4032

(edited) The behaviour you describe sounds weird, as according to the Grafana docs the timeFilter should be consistent. I checked in any case and I am observing the same behaviour.

At QuestDB you can use the to_timestamp function to parse a timestamp with nanoseconds precision, but internally the timestamp is still with microsecond resolution, so you'd need to use the solution suggested by Andrey and skip using the built-in grafana filter here

Upvotes: 0

Andrei Pechkurov
Andrei Pechkurov

Reputation: 903

Try replacing $__timeFilter(timestamp) with the following filter:

timestamp BETWEEN cast($__unixEpochFrom()*1000000L as timestamp) and cast($__unixEpochTo()*1000000L as timestamp)

Upvotes: 2

Related Questions