StateCount unable to generate alert

#1

Do you guys see anything wrong with this, I can’t get stateCount to generate any alerts even thou it state_count exceeded 2 times. My script is using “batch”.

I wonder if it’s related to this bug: https://github.com/influxdata/kapacitor/pull/1380

    |join(current)
        .as('past', 'current')
        .tolerance(tolerence)
    |eval(lambda: (float("current.curr_change") - float("past.past_change")), lambda: float("past.past_change"), lambda: float("current.curr_change"))
        .as('difference', 'past_w2w_change', 'current_w2w_change')

joinData
    |stateCount(lambda: "difference" < 5)
    |alert()
        .crit(lambda: "state_count" > 2)
        .stateChangesOnly(5m)
        .slack()

joinData
    |influxDBOut()
        .cluster(out_cluster)
        .database(out_database)
        .measurement(out_measurement)```
#2

@Daniel_Li Can you add a |log() node to the task between the stateCount and alert nodes and share the logs?

#3

below is the log

[test_alert:log8] 2017/06/20 11:17:00 I! test_alert {"name":"analysis","tmax":"2017-06-20T11:17:00-07:00","group":"locale=us,product=example.com","tags":{"locale":"us","product":"example.com"},"points":[{"time":"2017-06-20T18:15:00Z","fields"{"current_w2w_change":-99.68664316490404,"difference":-495.4171562867215,"past_w2w_change":395.73051312181747,"state_count":1},"tags":{"locale":"us","product":"example.com"}}]}

[test_alert:log8] 2017/06/20 11:18:00 I! test_alert {"name":"analysis","tmax":"2017-06-20T11:18:00-07:00","group":"locale=us,product=example.com","tags":{"locale":"us","product":"example.com"},"points":[{"time":"2017-06-20T18:16:00Z","fields":{"current_w2w_change":-109.283196239718,"difference":-311.5158636897768,"past_w2w_change":202.23266745005876,"state_count":1},"tags":{"locale":"us","product":"example.com"}}]}

[test_alert:log8] 2017/06/20 11:19:00 I! test_alert {"name":"analysis","tmax":"2017-06-20T11:19:00-07:00","group":"locale=us,product=example.com","tags":{"locale":"us","product":"example.com"},"points":[{"time":"2017-06-20T18:17:00Z","fields":{"current_w2w_change":-108.46063454759107,"difference":-116.2749706227967,"past_w2w_change":7.814336075205638,"state_count":1},"tags":{"locale":"us","product":"example.com"}}]}
#4

I see the issue, the stateCount resets after each batch. Since you only have a single point per batch you only ever get a state_count value equal to 1. If you grab the last point of each batch it will become a stream edge and stateCount will not reset.

#6

I did something like this:

  |last('hour2hour_change')
    .as('pastHr_change')```

convert it to stream edge but it goes back to the "missing" field error again.