influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Inability to manipulate range offsets in dashboards

Open antst opened this issue 3 years ago • 5 comments

InfluxDB 2.0.2

Original task is simple I want to have on a plot some data for closen interval and data for previous interval with fixed shift/offset on the same plot (i.e shifted data will be shifted to current interval) Shift is solved but timeShift() , but selection is not solvable.

So, let assume typical query:

from(bucket: "bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "hmeasurement")
  |> filter(fn: (r) => r["_field"] == "field")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Problem is to have another query in a equivalent form of

from(bucket: "bucket")
  |> range(start: v.timeRangeStart-24h, stop: v.timeRangeStop-24h)
  |> timeShift(duration: 24h)
  |> filter(fn: (r) => r["_measurement"] == "hmeasurement")
  |> filter(fn: (r) => r["_field"] == "field")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

And in this query, particularly, line

  |> range(start: v.timeRangeStart-24h, stop: v.timeRangeStop-24h)

is not solvable. you can use custom variable for start: here, but using anything but v.timeRangeStop for the stop: (or custom variable which is defined like t=v.timeRangeStop) , leads to the error record is missing label windowPeriod. (I tried to alter t with add/subDuration)

So, unless there is something obvious I am missing, there is a clear bug or missing feature. And I don't think it is such exotic use case. (let say you want to compare this week performance to last week performance).

Maybe, I am wrong, but I presume this should work:

t0=experimental.subDuration(from: v.timeRangeStart,d: 24h)
t1=experimental.subDuration(from: v.timeRangeStop,d: 24h)

from(bucket: "bucket")
  |> range(start: t1, stop: t2)
  |> timeShift(duration: 24h)
  |> filter(fn: (r) => r["_measurement"] == "hmeasurement")
  |> filter(fn: (r) => r["_field"] == "field")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

data-wise, this query is all right. And I can successfully query in CLI:

import "experimental"

t1=experimental.subDuration(from: now(), d: 24h)
t0=experimental.subDuration(from: t1,d: 24h)

from(bucket: "bucket")
  |> range(start: t1, stop: t2)
  |> timeShift(duration: 24h)
  |> filter(fn: (r) => r["_measurement"] == "hmeasurement")
  |> filter(fn: (r) => r["_field"] == "field")
  |> aggregateWindow(every: 15m, fn: mean, createEmpty: false)
  |> yield(name: "mean")

But using the very same query in query editor in InfluxDB dashboard UI results in record is missing label windowPeriod error.

antst avatar Dec 14 '20 15:12 antst

Likewise, I also get type error @14:29-14:30: record is missing label windowPeriod with

import "experimental"

time = experimental.addDuration(
  d: 3600s,
  to: 2021-04-19T11:00:00Z
)
from(bucket: "Website Monitoring Bucket")
  |> range(start: v.timeRangeStart, stop: time)

In C2. I expect that to work. Thank you :)

Anaisdg avatar Apr 19 '21 17:04 Anaisdg

In InfluxDB 2.0.4 (Docker image) I get the same error : type error @5:29-5:30: record is missing label windowPeriod Following Flux code was used against a Mariadb 10.2.9 database

import "sql"

password = "the-super-secret-password"

sql.from(
  driverName: "mysql",
  dataSourceName: "username:${password}@tcp(mysql:3306)/mysql",
  query: "select *  from slow_log"
)

MandySimbuka avatar May 05 '21 13:05 MandySimbuka

I have same problem trying to solve missing first two points after doing derivative.

start2 = duration(v: int(v: v.timeRangeStart) - 3*int(v:5m))

from(bucket: "telegraf/two_years")
    |> range(start: start2, stop: v.timeRangeStop)
...
    |> aggregate.rate(every: 5m, groupColumns: ["_field", ...])
...

When I change last line to:

    |> aggregate.rate(every: v.windowPeriod, groupColumns: ["_field", ...])

I get a error:

error @24:30-24:31: record is missing label windowPeriod

When I change this to:

from(bucket: "telegraf/two_years")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
...
    |> aggregate.rate(every: v.windowPeriod, groupColumns: ["_field", ...])

It works, but not quite, I'm missing 1-2 beginning points on graph. It looks good when I'm zoomed out, but becomes more useless when zoomed in to 15m (samples every 5m).

helotpl avatar Jan 28 '22 09:01 helotpl

Same issue for me:

import "experimental"

from(bucket: v.bucket)
  |> range(start: v.timeRangeStart, stop: experimental.subDuration(d: 1m, from: v.timeRangeStop))
...

I get this error:

 type error @18:29-18:30: record is missing label windowPeriod

ricfio avatar Feb 08 '22 15:02 ricfio

same problem here... not sure why 2.5 years later there is no comment on this

jonofmac avatar Jul 28 '22 17:07 jonofmac

同样的问题......不知道为什么2.5年后对此没有评论

me,too sad

Aperove avatar Aug 14 '22 14:08 Aperove

I believe I am also getting the same issue. Pretty simple use-case and strange that it happens.

alexitheodore avatar Nov 09 '22 18:11 alexitheodore

Same issue here

giesmininkas avatar Nov 10 '22 20:11 giesmininkas

also here, quite important feature

mountrcg avatar Dec 18 '22 10:12 mountrcg