Skip to content

Commit

Permalink
Merge pull request riemann#185 from bmhatfield/run-of-same
Browse files Browse the repository at this point in the history
Run of same
  • Loading branch information
aphyr committed Mar 29, 2013
2 parents 5300b9d + 76f0fef commit e5ddb47
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/riemann/streams.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,24 @@ OA
(condp ~pred (valuefn# ~event-sym)
~@condp-clauses)))))

(defn runs
"Usable to perform flap detection, runs examines a moving-event-window of
n events and determines if :field is the same across all them. If it is,
runs passes on the *first* event of the window. In practice, this can be
used nested within a (changed-state ...) to reduce 'flappiness' for
state changes.
(runs 3 :state prn) ; Print events where there are 3-in-a-row of a state."
[len-run field & children]
(moving-event-window
len-run
(smap
(fn [events]
(if (apply = (map field events))
(last events)))
(apply sdo children))))


(defn project*
"Like project, but takes predicate *functions* instead of where expressions."
[predicates & children]
Expand Down

0 comments on commit e5ddb47

Please sign in to comment.