Variables in lambda in Kapacitor

kapacitor
#1

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
  |from()
    .database(db)
    .retentionPolicy(rp)
    .measurement(measurement)
    .groupBy('shard', 'org')

  |where(lambda: isPresent(field))

  |stateDuration(lambda: field < crit)
    .unit(1m)

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?

2 Likes
#2

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.