Ailed to evaluate filter function: keyword argument "set" should be of an array of type invalid, but got an array of type [string]

I’m using Grafana with InfluxDB 2.0 on MacOS. Both on localhost

I’m trying a simple query to filter multiple value by creating a variable, and using the variable to filter the query:

from(bucket: "bucket_name")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "process_time")
  |> filter(fn: (r) => contains(value: r["api"], set: {$api:json}))
  |> filter(fn: (r) => r["_field"] == "latency")
  |> group(columns: ["api"])
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

I’m getting the following error:

invalid: runtime error @3:6-3:60: filter: failed to evaluate filter function: keyword argument “set” should be of an array of type invalid, but got an array of type [string]

However, the query runs as expected when hardcoding the filter values:

from(bucket: "bucket_name")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "process_time")
  |> filter(fn: (r) => r["api"] == "api_1" or r["api"] == "api_2")
  |> filter(fn: (r) => r["_field"] == "latency")
  |> group(columns: ["api"])
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

I am getting the same error, utilizing set, to establish a list of filters. What was noticed, however, is that the error also occurs within Influx. So I do not think that it is a Grafana issue.

Hello,

I confirm you this problem is also possible in grafana.
I have exactly the same issue.

I have a variable called “family” and with this simple query, I have the same message.
from(bucket: “connected_pressure_raw_data”)

|> range(start: -2d)
|> filter(fn: (r) => r["_measurement"] == “monitoring”
and r._field == “Version”
and r.company == “X”
and contains(value: r[“family”], set: ${family:json}))

And I have the last grafana version.
Does someone have an idea about what’s the problem ?

Did this ever get sorted Ive just hit the same issue

I have some panels on the same dashboard where it works in some cases then what I add to another metric I get the error

I had a similar problem, and I solved it by changing the filtering order. A bit stupid of me

This was returning me an invalid type because the service tag was not available everywhere

  from(bucket: "traefik")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) => contains(value: r.service, set: ${service:json}))
  |> filter(fn: (r) => r._measurement == "traefik.service.requests.total")
  |> filter(fn: (r) => r.method == "POST" or r.method == "GET")

So by filtering first the measurement, it’s working

  from(bucket: "traefik")
  |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "traefik.service.requests.total")
  |> filter(fn: (r) => contains(value: r.service, set: ${service:json}))
  |> filter(fn: (r) => r.method == "POST" or r.method == "GET")

Hope this can help you

This is probably because not all records have that field. If you use contains, you need to first check that the field exists.

|> filter(fn: (r) => exists r.test and contains(value: r.test, set: ${test:json}) )

I was replacing these regex filters with contains and was faced this issue.

|> filter(fn: (r) => r["test"] =~ /^${test:regex}$/)

This topic was automatically closed after 365 days. New replies are no longer allowed.