I have an issue with a last selector in a type stream task, using Kapacitor version 1.3.1. It appears as though the first datapoint is discarded. My data in this example is basically just a field ac sent from a sensor gateway indicating whether it’s connected to the main or not. This is the task:
stream
|from()
.measurement(measurement)
.where(where_filter)
.groupBy(groups)
|window()
.period(window)
.every(window)
|last(field)
|eval(status)
.as('status_message')
.keep()
|alert()
.id('Alarm on Gateway {{index .Tags "mac" }} sensor {{index .Tags "node" }}')
.crit(crit)
.log('/tmp/testlog.log')
using the following vars:
crit lambda "last" == 0
field string ac
measurement string sensor_data
where_filter lambda "node" == 'sys' AND "cmdclass" == 'alarm' AND "action" == 'stat'
window duration 10s
the relevant part of the DOT is:
from1 [avg_exec_time_ns="0s" errors="0" working_cardinality="0" ];
from1 -> window2 [processed="2"];
window2 [avg_exec_time_ns="0s" errors="0" working_cardinality="1" ];
window2 -> last3 [processed="1"];
From some trial and error I found that the first datapoint is the one that is not processed. When I replicate this using batch mode instead everything appears to work fine (snipped for brevity):
batch
|query('SELECT last(ac) FROM ' + dbrp + ' WHERE ' + where_filter)
.period(1m)
.every(1m)
.groupBy(time(10s))
query1 [avg_exec_time_ns="4.087748ms" batches_queried="2" errors="0" points_queried="2"
working_cardinality="0" ];
query1 -> eval2 [processed="2"];
I would have thought the stream and the batch tasks would be equivalent. Might this be a bug or is there some issue with my script? I’m fairly new to kapacitor