flux
flux copied to clipboard
Add ability to specify absolute time range in v1.tagKeys, v1.tagValues
I would like to be able to use an absolute time range when calling the v1.tagKeys and v1.tagValues functions.
Something like this:
import "influxdata/influxdb/v1"
v1.tagKeys(bucket: "telegraf", start: 2019-01-01, stop: 2019-06-01)
I still want to be able to use the function as it works currently:
import "influxdata/influxdb/v1"
v1.tagKeys(bucket: "telegraf", start: -1d)
I was going to update the functions in the stdlib, but ran into an issue. I don't know how to make these functions accept both a time or a duration as an argument:
tagKeys = (bucket, predicate=(r) => true, start=-30d, stop=0d) =>
from(bucket: bucket)
|> range(start: start, stop: stop)
|> filter(fn: predicate)
|> keys()
|> keep(columns: ["_value"])
tagKeys(bucket: "telegraf", start: 2019-01-01, stop: 2019-06-01)
failed to compile query: type error 9:1-9:47: duration != time
@chnn Your change looks correct but that we are running into a limitation of the current Flux type system. The plan is to treat duration literals as polymorphic, meaning they can be either a time or a duration. See https://github.com/influxdata/flux/issues/1073 Until that is done this will not work as expected.
the real issue here is the default arguments. by setting the defaults as durations, our type system can't handle if you then call the function with times.
Any news on this?
Following workaround is working for me, but it is not very sexy:
from(bucket: "<YOUR_BUCKET>")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) =>
r._measurement == "<YOUR_MEASUREMENT>"
)
|> keyValues(keyColumns: ["host"])
|> group()
|> keep(columns: ["host"])
|> distinct(column: "host")
host = is the field I want in my Grafana template variable
I hope this helps someone. :-)
This issue has had no recent activity and will be closed soon.