flux icon indicating copy to clipboard operation
flux copied to clipboard

Add ability to specify absolute time range in v1.tagKeys, v1.tagValues

Open chnn opened this issue 6 years ago • 4 comments

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 avatar Mar 20 '19 17:03 chnn

@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.

nathanielc avatar Mar 20 '19 19:03 nathanielc

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.

aanthony1243 avatar Apr 26 '19 20:04 aanthony1243

Any news on this?

R-Studio avatar Jan 20 '21 08:01 R-Studio

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. :-)

R-Studio avatar Jan 20 '21 14:01 R-Studio

This issue has had no recent activity and will be closed soon.

github-actions[bot] avatar Aug 29 '24 01:08 github-actions[bot]