Skip to content

Instantly share code, notes, and snippets.

@neotyk
Created August 29, 2013 12:31
Show Gist options
  • Save neotyk/6377465 to your computer and use it in GitHub Desktop.
Save neotyk/6377465 to your computer and use it in GitHub Desktop.
(ns riemann-config-test
(:use
midje.sweet
riemann.streams
riemann.client
riemann.email
riemann.sns
[riemann.time :only [unix-time linear-time once! every!]])
(:require
riemann.streams
riemann.config
riemann.core
riemann.index
riemann.query))
(defmacro configure-core [& conf]
`(binding [*ns* (find-ns 'riemann.config)]
(eval '(do
(~'riemann.time/reset-tasks!)
(~'clear!)
(~'pubsub/sweep! (:pubsub @~'core))
(~'logging/init)
(~'instrumentation {:enabled? false})
(~'periodically-expire)
(~'streams ~@conf)
(when-let [idx# (:index @~'core)]
(~'riemann.index/clear idx#))
(~'apply!)))))
(defn stream-events [& events]
(doseq [ev events]
(riemann.core/stream! @riemann.config/core ev)))
(defn search-index [query]
(riemann.index/search (:index @riemann.config/core)
(riemann.query/ast query)))
(facts "about simple streams"
(with-state-changes [(before :facts (configure-core (update-index (index))))]
(fact "Event gets indexed"
(stream-events {:host ..h..
:service ..s..
:state "ok"
:metric 42})
(search-index "true") => [{:host ..h..
:service ..s..
:state "ok"
:metric 42}])
(fact "Only last event for [:host :service] stays in the index"
(stream-events {:host ..h..
:service ..s..
:state "ok"
:metric 42}
{:host ..h..
:service ..s..
:state "ok"
:metric 43})
(search-index "true") => [{:host ..h..
:service ..s..
:state "ok"
:metric 43}])))
@tomduckering
Copy link

Is this still something that should work? I'm really keen to test drive riemann config and quickly reached the limits of what was possible with the natively test stuff (searching indexes and what not).

I'm getting problems with it whinging about not being able to load stuff from a lib called amazonica. Something used by the cloudwatch integration. My clojure foo is weak and I can't work out how to tell it to shut up.

Any help gratefully received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment