Skip to content

Instantly share code, notes, and snippets.

@neotyk
Created August 29, 2013 12:31
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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}])))
@robkuz
Copy link

robkuz commented Aug 30, 2013

Hey Hubert,

could you please explain (maybe document ) what you are doing here.
My clojure isnt yet ready for all this ;-)

ciao robertj

@AshtonKem
Copy link

It looks like Hubert wrote a few helper functions to test a Riemann config.

config-core is a macro that takes a Riemann config (in the form of Clojure expressions) and loads it up. stream-events is to run some events through the current config, and search-index is to see what is inside Riemann at the moment.

The rest is Midje, a BDD framework for Clojure.

@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