Michael Klishin avatar Michael Klishin committed 9d38bf2

Make sure defhistogram, defcounter, deftimer and so on quote metric titles

Without this change, defhistogram and friends won't compile.

Currently desugared-title returns the name as a list of 3 strings,
which needs to be quoted for things to compile:

("test" "group" "ubermetric")

will be evaluated without quoting.

Comments (0)

Files changed (10)

metrics-clojure-core/src/metrics/counters.clj

   "
   [title]
   (let [[s title] (desugared-title title)]
-    `(def ~s (counter ~title))))
+    `(def ~s (counter '~title))))
 
 
 ; Read ------------------------------------------------------------------------

metrics-clojure-core/src/metrics/gauges.clj

     (if (and (empty? bs)
              (symbol? b)
              (fn? (eval b)))
-      `(def ~s (gauge-fn ~title ~b))
-      `(def ~s (gauge ~title ~@body)))))
+      `(def ~s (gauge-fn '~title ~b))
+      `(def ~s (gauge '~title ~@body)))))
 
 
 ; Read ------------------------------------------------------------------------

metrics-clojure-core/src/metrics/histograms.clj

   "
   [title & args]
   (let [[s title] (desugared-title title)]
-    `(def ~s (histogram ~title ~@args))))
+    `(def ~s (histogram '~title ~@args))))
 
 
 ; Read ------------------------------------------------------------------------

metrics-clojure-core/src/metrics/meters.clj

   "
   [title event-type]
   (let [[s title] (desugared-title title)]
-    `(def ~s (meter ~title ~event-type))))
+    `(def ~s (meter '~title ~event-type))))
 
 
 ; Read ------------------------------------------------------------------------

metrics-clojure-core/src/metrics/timers.clj

   "
   [title]
   (let [[s title] (desugared-title title)]
-    `(def ~s (timer ~title))))
+    `(def ~s (timer '~title))))
 
 
 ; Read ------------------------------------------------------------------------

metrics-clojure-core/test/metrics/test/counters.clj

   (:use [clojure.test]))
 
 
+(counters/defcounter ["test" "counters" "defcountered"])
+
+(deftest test-defcounter
+  (is (= (counters/value defcountered) 0))
+  (counters/inc! defcountered)
+  (is (= (counters/value defcountered) 1)))
+
 (deftest test-inc
   (let [c (counters/counter ["test" "counters" "test-inc"])]
     (is (= (counters/value c) 0))

metrics-clojure-core/test/metrics/test/gauges.clj

   (:require [metrics.gauges :as gauges])
   (:use [clojure.test]))
 
+(gauges/defgauge ["test" "gauges" "defgauged"]
+  1001)
+
+(deftest test-defgauge
+  (is (= (gauges/value defgauged) 1001)))
 
 (deftest test-gauge
   (let [g (gauges/gauge ["test" "gauges" "test-gauge"]

metrics-clojure-core/test/metrics/test/histograms.clj

   (:use [metrics.test.test-utils])
   (:use [clojure.test]))
 
+(histograms/defhistogram ["test" "histograms" "defhistogrammed"])
+
+(deftest test-defhistogram
+  (is (= (histograms/number-recorded defhistogrammed) 0))
+  (histograms/update! defhistogrammed 0)
+  (is (= (histograms/number-recorded defhistogrammed) 1))
+  (histograms/update! defhistogrammed 0)
+  (is (= (histograms/number-recorded defhistogrammed) 2)))
 
 (deftest test-mean
   (let [h (histograms/histogram ["test" "histograms" "test-mean"])]

metrics-clojure-core/test/metrics/test/meters.clj

   (:use [metrics.test.test-utils])
   (:use [clojure.test]))
 
+(meters/defmeter ["test" "meters" "defmetered"] "test-events")
+
+(deftest test-defmeter
+  (is (= (meters/rate-mean defmetered) 0.0))
+  (meters/mark! defmetered)
+  (is (> (meters/rate-mean defmetered) 0.0)))
 
 (deftest test-rate-mean
   (let [m (meters/meter ["test" "meters" "test-rate-mean"] "test-events")]

metrics-clojure-core/test/metrics/test/timers.clj

   (Thread/sleep 200)
   200)
 
+(timers/deftimer ["test" "timers" "deftimered"])
+
+(deftest test-deftimer
+  (is (= (timers/rate-mean deftimered) 0.0))
+  (is (= (timers/time! deftimered (sleep-100)) 100))
+  (is (> (timers/rate-mean deftimered) 0.0)))
 
 (deftest test-rate-mean
   (let [t (timers/timer ["test" "timers" "test-rate-mean"])]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.