Variables in lambda in Kapacitor


Clearly variables can be used on the right side of a comparison, but I’ve had trouble getting them to work or finding examples of them being used on the left side.

var db = 'system'
var rp = 'default'
var measurement = 'cpu'
var field = 'usage'
var crit = 3

var data = stream
    .groupBy('shard', 'org')

  |where(lambda: isPresent(field))

  |stateDuration(lambda: field < crit)

In this example, field being the problematic variable. Should it be able to work that way? Variables in TICKscripts in general have been tricky, is there any documentation about what you can use where?


Frankly I didn’t even realize this was possible at all. I thought only strings could be used as variables but that you couldn’t dereference them into fields.