             [gorillalabs.tesla.component.configuration :as config]
             [mount.core :as mnt]
             [riemann.client :as riemann])
-  (:import (java.net InetAddress)))
+  (:import (java.net InetAddress))
+  (:refer-clojure :exclude [flush]))
 
 (defn- now []
   (/ (System/currentTimeMillis) 1000))

(defn- stop [telemetry]
  (log/info "<- stopping telemetry")
  (close! (:killswitch telemetry))
  (when-let [client (:r-client telemetry)]
    (flush-queue client (:queue telemetry))
    (riemann/close! client)))

(mnt/defstate telemetry


(defn- start []
  (log/info "-> starting telemetry")
  (let [config      (config/config config/configuration [:telemetry])
        riemann-cfg (:riemann config)
        queue       (chan (sliding-buffer (:queue-size config 1000)))
        killswitch  (chan)
        client      (when (:host riemann-cfg) (riemann/tcp-client riemann-cfg))]
    (worker killswitch client queue (:interval config 30))
    {:host       (:host config (localhost))
     :r-client   client
