Jérémie B
Jérémie B

Reputation: 11032

Matching the absence of events

I have a simple stream of status of objects :

define stream statusStream (id string, success bool);

I want to query all of objects which are "failed" (success=false) since 5 minutes : all event of statusStream (, false) where there are no event (same id, true) within 5 minutes.

What is the simplest siddhi query for this kind of job ?

Currently I have :

define stream statusStream (id string, success bool);

from statusStream[ success == false ]#window.time(5 minutes)
insert expired events into expiredStatusStream;

from every status = statusStream[ success == false ]
  -> ackStatus = statusStream[ success == true and id == status.id]
    or expiredStatus = expiredStatusStream[ id == status.id ]
select status.id, ackStatus.id as ackId
into filteredStatusStream;

from filteredStatusStream[ ackStatus.id is null ]
insert into failedStatusStream;

Upvotes: 0

Views: 93

Answers (1)

Dilini
Dilini

Reputation: 787

In case you are getting 'success == false' messages to indicate failure, then try below execution plan:

@Import('statusStream:1.0.0')
define stream statusStream (id string, success bool);

@Export('alertStream:1.0.0')
define stream alertStream (alert string);

from statusStream
select id, success, time:timestampInMilliseconds() as ts
insert into statusStreamWithTS;

from every e1=statusStreamWithTS[success==false], statusStreamWithTS[success==false]*, e2=statusStreamWithTS[success==false AND (e2.ts - e1.ts) >= 500000]
select 'some message' as alert
insert into alertStream;

Here, an alert will be generated if we continue to get 'success==false' messages for 5 mins.

Upvotes: 1

Related Questions