flux
flux copied to clipboard
Feature request: support nanosecond timestamps in range() function
I would like to have an ability to specify time range in plain int nanoseconds like this:
|> range(start: 1557339710000000000, stop: 1557253315000000000)
Trying to do so produces
{"error":"failed to create logical plan: cannot query an empty range"}
Looking for that error in code, I've found that as of now only durations and RFC3339 timestamps are supported.
Rationale: comparsion "today/yesterday/week ago"-style graphs
InfluxQL allows this:
WHERE time >= 1557339710000000000 AND time < 1557253315000000000
Even more, arithmetics on those values are allowed, for example: Grafana's millisecond timestamps can be converted to expected nanosecond format:
time >= $__from * 1000000 AND time < $__to * 1000000
Operations between timestamps and durations are also allowed (seems like Flux has problems with it #413):
time >= $__from * 1000000 - 1d AND time < $__to * 1000000 - 1d
But returned dataset is outside of dashboard's time range, so there is no way to draw them on top of each other.
Flux actually has shift()
function that would be the final step in this process, but before it can happen, all previous operations on timestamps and durations should be supported within range()
function.
@zarbis I think unix nanosecond timestamp support would definitely be a plus. In the meantime, you should be able to use the time()
function to convert them to an RFC3339 timestamp:
|> range(start: time(v: 1557339710000000000), stop: time(v: 1557253315000000000))
@sanderson unfortunately i get the exact same error with your suggestion. Tried on Flux bundled with 1.7.3 and 1.7.6. However this trick at the end of any query seems to produce timestamp:
|> set(key: "test", value: string(v: time(v: 1557339710000000000)))
@zarbis the following script works, can you try on your version? perhaps we need to ship another upgrade.
import "csv"
option now = () => (2030-01-01T00:00:00Z)
inData = "
#datatype,string,long,dateTime:RFC3339,double,string,string,string,string
#group,false,false,false,false,true,true,true,true
#default,_result,,,,,,,
,result,table,_time,_value,_field,_measurement,cpu,host
,,0,2018-05-22T19:50:26Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:53:36Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:53:46Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:53:56Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:54:06Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:54:16Z,0,usage_guest,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:26Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:36Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:46Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:56Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:54:06Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:54:16Z,0,usage_guest_nice,cpu,cpu-total,host.local
"
outData = "
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string
#group,false,false,true,true,false,false,true,true,true,true
#default,_result,,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,cpu,host
,,0,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:53:36Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:53:46Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:53:56Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:54:06Z,0,usage_guest,cpu,cpu-total,host.local
,,0,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:54:16Z,0,usage_guest,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:53:36Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:53:46Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:53:56Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:54:06Z,0,usage_guest_nice,cpu,cpu-total,host.local
,,1,2018-05-22T19:53:36Z,2030-01-01T00:00:00Z,2018-05-22T19:54:16Z,0,usage_guest_nice,cpu,cpu-total,host.local
"
t_range = (table=<-) =>
(table
//|> range(start: 2018-05-22T19:53:36Z))
|> range(start: time(v:1527018816000000000)))
csv.from(csv:inData) |> t_range()
@aanthony1243 cannot pin-point any sort of typo, but I get {"error":"failed to compile query: unsupported statement <nil>"}
.
InfluxDB 1.7.3
after removing the option now...
line, i can confirm the script posted by @aanthony1243 works in influxdb cloud commit 0945dd7
@aanthony1243 I've tried to remove option now ...
as suggested: gives unknown import path : "csv
on 1.7.3 and works fine on 1.7.6.
@zarbis I think unix nanosecond timestamp support would definitely be a plus. In the meantime, you should be able to use the
time()
function to convert them to an RFC3339 timestamp:|> range(start: time(v: 1557339710000000000), stop: time(v: 1557253315000000000))
this worked for me. Thank you
This issue has had no recent activity and will be closed soon.