StateDuration: Error exhausting result iterator; Err: failed to evaluate map function: unsupported binary expression invalid >= int

I have this query and everytime it runs it is failing with this error failed to evaluate map function: unsupported binary expression invalid >= int From the context of the error it doesn’t like the value of my state_duration. I plugged my query into the explorer to make sure state_duration is coming back as a int and it is. The result in the table was -1. I can’t seem to understand what is wrong with my query. Any help would be great :slight_smile:

import "influxdata/influxdb/monitor"
import "experimental"
import "influxdata/influxdb/v1"
option task = {name: "node-status-notready-task", every: 1m, offset: 10s}
check = {
	_check_id: "",
	_check_name: "Node-notready-task",
	_type: "custom",
	tags: {owner: "team-sre"},
	every: 2m,
}
warn = (r) => r.state_duration >= 5 and r.state_duration <= 14
crit = (r) =>
	(r.state_duration >= 15)
messageFn = (r) =>
	("Threshold: ${r._check_name} is: ${r._level}  
env:${r.env} | ns: ${r.namespace} | pod:${r.pod} | node:${r.nodename}
This indicates that node:${r.nodename} has not been ready for ${string(v: r.state_duration)}. 
This should be investigated and documented here http://docs.internal/operations/specifications/runbooks/node-status-notready/:
")
data = from(bucket: "infra")
	|> range(start: duration(v: int(v: task.every) * (-1)))
	|> filter(fn: (r) =>
		(r._measurement == "kube_node_status_condition"))
	|> filter(fn: (r) =>
		(r.condition != "Ready"))
	|> stateDuration(fn: (r) =>
		(r._status =~ /true|unknown/), unit: 1m, column: "state_duration")
data
	|> v1.fieldsAsCols()
	|> monitor.check(data: check, messageFn: messageFn, crit: crit, warn: warn)

I took a look at your query and call to v1.fieldsAsCols() removes the state_duration column. So if you add a call to experimental.group(mode: "extend", columns: ["state_duration"]) , then it will be added to the group key, and v1.fieldsAsCols() won’t drop it.

data
    |> experimental.group(mode: "extend", columns: ["state_duration"])
    |> v1.fieldsAsCols()