How to use stateDuration?

We upgraded kapacitor to 1.3.0~beta2, and tried to use stateDuration to alert when the event last more than 3 minutes.
when expression evaluated as false, the stat duration value was -1, and when evaluated true, it changed to 0, but didnot increase anymore, just stay as 0
Is this the right node to use? and how should i use it? thanks.

var response_data = stream
|from()
.database(‘test’)
.measurement(measurement)
.groupBy(‘domain’,‘monitor_name’)
|window()
.period(1m)
.every(1m)
.align()

response_data
|stateDuration(lambda: int(“result_status”) != 1 )
.unit(1m)
.as(‘resultstatus_events_duration’)
|httpOut(‘resultstatus_events_duration’)
|alert()
.crit(lambda: “resultstatus_events_duration” > 3 )
.alerta()
.message(‘http result error’ + string(arp))
.event(’ {{ index .Tags “domain” }} http result error’)
.resource(resource)

Also interested in using this but haven’t had time to try it yet. Looking at the PR it is named “stateCount” and from there I found the documentation.

Ah, there’s also stateDuration.

Hey @wwshi looking through the documentation, it seems that for each consecutive point for which the expression evaluates as true, the state duration will be incremented by the duration between points. This means that if the value only ever evaluates toggles between true and false all that we’ll see is 0 and -1 for the associated durations. To get actual numeric values we’ll have to have multi points where lambda: int("result_status") != 1 evaluates to true in succession.