Permalink
Browse files

streams/tagged-all and tagged-any take strings now, too.

Their documentation lied! Now, (tagged-all "cat" prn) works the same as
(tagged-all ["cat"] prn).
  • Loading branch information...
1 parent fcccd80 commit 4d1f932d8f69d0e01382b81c12c05077b7f5c41e @aphyr aphyr committed Nov 10, 2012
Showing with 54 additions and 28 deletions.
  1. +9 −4 riemann.config
  2. +17 −6 src/riemann/streams.clj
  3. +28 −18 test/riemann/test/streams.clj
View
@@ -8,8 +8,13 @@
(periodically-expire 10)
-(let [client (tcp-client)
- index (default :ttl 300 (update-index (index)))]
-
- (streams index)
+(let [index (default :ttl 300 (update-index (index)))]
+ (streams
+ index
+ (tagged-any "tag"
+ (partial prn "HEYO"))
+ (where (tagged "foo")
+ (partial prn "foo")
+ (else
+ (partial prn "not foo"))))
)
View
@@ -696,22 +696,33 @@
(tagged-all \"foo\" prn)
(tagged-all [\"foo\" \"bar\"] prn)"
[tags & children]
- (fn [event]
- (when (set/subset? (set tags) (set (:tags event)))
- (call-rescue event children))))
-(def tagged "Alias for tagged-all" tagged-all)
+ (if (coll? tags)
+ (fn [event]
+ (when (set/subset? (set tags) (set (:tags event)))
+ (call-rescue event children)))
+
+ (fn [event]
+ (when (member? tags (:tags event))
+ (call-rescue event children)))))
(defn tagged-any
"Passes on events where any of tags are present.
(tagged-any \"foo\" prn)
(tagged-all [\"foo\" \"bar\"] prn)"
[tags & children]
- (let [required (set tags)]
+ (if (coll? tags)
+ (let [required (set tags)]
+ (fn [event]
+ (when (some required (:tags event))
+ (call-rescue event children))))
+
(fn [event]
- (when (some required (:tags event))
+ (when (member? tags (:tags event))
(call-rescue event children)))))
+(def tagged "Alias for tagged-all" tagged-all)
+
(defn expired
"Passes on events with :state \"expired\"."
[& children]
@@ -124,34 +124,44 @@
(s {:service "foo"})
(is (= {:service "foo"} (deref r)))))
-(deftest tagged-test
- (let [r (ref [])
- s (tagged ["kitten" "cat"] (append r))
- events [{:tags ["kitten" "cat"]}
+(deftest tagged-all-test
+ (test-stream (tagged-all ["kitten" "cat"])
+ [{:tags ["kitten" "cat"]}
{:tags ["kitten", "cat", "meow"]}
{:tags ["dog" "cat"]}
{:tags ["cat"]}
{:tags []}
- {}]]
- (doseq [e events] (s e))
- (is (= (deref r)
- [{:tags ["kitten" "cat"]}
- {:tags ["kitten", "cat", "meow"]}]))))
+ {}]
+ [{:tags ["kitten" "cat"]}
+ {:tags ["kitten", "cat", "meow"]}])
+
+ (test-stream (tagged-all "meow")
+ [{:tags ["meow" "bark"]}
+ {:tags ["meow"]}
+ {:tags ["bark"]}
+ {}]
+ [{:tags ["meow" "bark"]}
+ {:tags ["meow"]}]))
(deftest tagged-any-test
- (let [r (ref [])
- s (tagged-any ["kitten" "cat"] (append r))
- events [{:tags ["kitten" "cat"]}
+ (test-stream (tagged-any ["kitten" "cat"])
+ [{:tags ["kitten" "cat"]}
{:tags ["cat", "dog"]}
{:tags ["kitten"]}
{:tags ["dog"]}
{:tags []}
- {}]]
- (doseq [e events] (s e))
- (is (= (deref r)
- [{:tags ["kitten" "cat"]}
- {:tags ["cat", "dog"]}
- {:tags ["kitten"]}]))))
+ {}]
+ [{:tags ["kitten" "cat"]}
+ {:tags ["cat", "dog"]}
+ {:tags ["kitten"]}])
+
+ (test-stream (tagged-all "meow")
+ [{:tags ["meow" "bark"]}
+ {:tags ["meow"]}
+ {:tags ["bark"]}
+ {}]
+ [{:tags ["meow" "bark"]}
+ {:tags ["meow"]}]))
(deftest where-event-test
(let [r (ref [])

0 comments on commit 4d1f932

Please sign in to comment.