Flux query returns multiple values on aggregate window larger/equal then time period

Hello,

when executing a flux query with an aggregate window larger then the time window over the API on InfluxDBv2 the result contains two values. Eg:
Query:

from(bucket: “pix”)
|> range(start: -5m)
|> filter(fn: (r) => r["_measurement"] == “cpu”)
|> filter(fn: (r) => r["_field"] == “usage_user”)
|> filter(fn: (r) => r[“cpu”] == “cpu-total”)
|> filter(fn: (r) => r[“host”] == “example/.org”)
|> aggregateWindow(every: 5m, fn: mean, createEmpty: false)

Result:

,result,table,_start,_stop,_time,_value,_field,_measurement,cpu,host
,mean,0,2021-08-25T07:47:44.688052786Z,2021-08-25T07:52:44.688052786Z,2021-08-25T07:50:00Z,0.6062161745975281,usage_user,cpu,cpu-total,example/.org
,mean,0,2021-08-25T07:47:44.688052786Z,2021-08-25T07:52:44.688052786Z,2021-08-25T07:52:44.688052786Z,0.522318321504565,usage_user,cpu,cpu-total,example/.org

Setting the “every” param for aggregateWindow() to 1h returns only one value. Should not the query return only result ? If no, could this be accomplished by another function ?

Best regards,
skurtin

In Flux when windowing is performed, the window boundaries will be aligned with the “every” duration, where windows are truncated if needed to respect the range of the query. Since the query range is 5 minutes ago to now, a window boundary falls into the middle of the range:

  • First window is 7:47:44.688 to 07:50:00
  • Second window is 7:50:00 to 07:52:44.688

If you really just want one value returned you can replace the last line of your query with

|> mean()

To get a mean over the entire query range.