influxdb
influxdb copied to clipboard
Unable to retrieve metrics when using set function
Steps to reproduce: List the minimal actions needed to reproduce the behavior.
- Using telegraf enable the vSphere metrics input plugin and output the data to a InfluxDB database
- Use the below query to try and retrieve the CPU metrics from(bucket: "telegraf") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "vsphere_host_cpu") |> filter(fn: (r) => r["_field"] == "usage_average") |> filter(fn: (r) => contains(value: r["vcenter"], set: ["vCenter.name"])) |> filter(fn: (r) => contains(value: r["dcname"], set: ["datacenter.Name"] )) |> filter(fn: (r) => contains(value: r["clustername"], set: ["clustername"])) |> filter(fn: (r) => contains(value: r["esxhostname"], set: ["esxi_host1","esxi_host_2"])) |> keep(columns: ["_time","_field","_value"]) |> aggregateWindow(every: 20s, fn: last, createEmpty: false) |> yield(name: "last")
Expected behavior: CPU utilization reported for all vmware esxi hosts
Actual behavior:
Error is displayed:
runtime error @7:6-7:78: filter: failed to evaluate filter function: keyword argument "set" should be of an array of type invalid, but got an array of type [string]
Environment info:
- System info: Run
uname -srmand copy the output here Kubernetes v1.21.6 - InfluxDB version: Run
influxd versionand copy the output here Image v2.1.1 - Other relevant environment details: Container runtime, disk info, etc
Logs:
runtime error @7:6-7:78: filter: failed to evaluate filter function: keyword argument "set" should be of an array of type invalid, but got an array of type [string]
This was working fine before in the earlier v2.0.4 versions. clustername only contains a single tag called "CLUSTER01"

Another clue is that adding group() results in an index out of range error:

Minimal reproducer:
Error is thrown when the tag is not present:
import "array"
import "internal/debug"
array.from(rows: [{_time: now(), label: "xxxx"}]) |> debug.opaque() |> range(start: now()) |> filter(fn: (r) => contains(value: r["anything"], set:["anything"]))
Result: _result
Error: runtime error @1:95-1:162: filter: failed to evaluate filter function: keyword argument "set" should be of an array of type invalid, but got an array of type [string]
No error when the tag is present:
array.from(rows: [{_time: now(), label: "xxxx", anything: "anything"}]) |> debug.opaque() |> range(start: now()) |> filter(fn: (r) => contains(value: r["anything"], set:["anything"]))
Result: _result
Table: keys: [_start, _stop]
_start:time _stop:time _time:time label:string anything:string
------------------------------ ------------------------------ ------------------------------ ---------------------- ----------------------
2021-12-28T16:58:46.766052601Z 2021-12-28T16:58:46.766106720Z 2021-12-28T16:58:46.766060011Z xxxx anything
Relevant diff where the error is thrown: https://github.com/influxdata/flux/commit/d4499069f4af5165b7f059fbcd76590fe15fb0ce
Another example from my own data:
from(bucket: "operating-results")
|> range(start: 0)
|> filter( fn: (r) => exists r.foo) //works when present, error when not present
|> filter(fn: (r) => contains(value: r["foo"], set: ["bar"]))
@nathanielc what is the expected behavior here?
possible workaround in the meantime:
from(bucket: "operating-results")
|> range(start: 0)
|> filter(fn: (r) => if exists r.foo then contains(value: r["foo"], set: ["bar"]) else true)
Once influxdata/flux#4424 works its way out, the exists workaround should be redundant since the filters specified in the OP will drop records where the field passed to value is missing.
I've been through the same ordeal, spending two days on it. First, connecting Influx to Grafana was bizarre, and then there were all sorts of inexplicable errors in the queries. I'm about to pull my hair out from frustration.