       (worker client queue (:interval config 30))
       {:host     (:host config (localhost))
        :r-client client
-       :queue    queue})))
+       :queue    queue
+       :config   config})))
 
 (defn- stop [telemetry]
   (log/info "<- stopping telemetry")

(ns gorillalabs.tesla.component.telemetry
  (:require [clojure.core.async :refer [<! >!! sliding-buffer chan timeout poll! close! go-loop]]
            [clojure.tools.logging :as log]

      (log/infof "Sending %d event(s) to telemetry backend..." (count events))
      (riemann/send-events client events))))

(defn- prepare-event [telemetry event]
  (let [prefix (:prefix (:config telemetry) "")]
    (-> event
      (assoc :time (now))
      (assoc :host (:host telemetry))
      (assoc :service (str prefix (:service event))))))

(defn enqueue [telemetry event]
  (>!! (:queue telemetry) (prepare-event telemetry event)))

(defn state [telemetry service state]
  (enqueue telemetry {:service service :state state}))
