influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Unable to retrieve metrics when using set function

Open Aqualie opened this issue 3 years ago • 8 comments

Steps to reproduce: List the minimal actions needed to reproduce the behavior.

  1. Using telegraf enable the vSphere metrics input plugin and output the data to a InfluxDB database
  2. 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 -srm and copy the output here Kubernetes v1.21.6
  • InfluxDB version: Run influxd version and 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"

brave_2021-12-28_10-59-07

Aqualie avatar Dec 28 '21 16:12 Aqualie

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

brave_2021-12-28_10-34-55

rickspencer3 avatar Dec 28 '21 16:12 rickspencer3

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 

rickspencer3 avatar Dec 28 '21 17:12 rickspencer3

Relevant diff where the error is thrown: https://github.com/influxdata/flux/commit/d4499069f4af5165b7f059fbcd76590fe15fb0ce

rickspencer3 avatar Dec 28 '21 17:12 rickspencer3

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"]))

rickspencer3 avatar Dec 28 '21 17:12 rickspencer3

@nathanielc what is the expected behavior here?

rickspencer3 avatar Dec 28 '21 17:12 rickspencer3

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)

rickspencer3 avatar Dec 28 '21 17:12 rickspencer3

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.

onelson avatar Jan 25 '22 19:01 onelson

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.

activeliang avatar Apr 28 '24 14:04 activeliang