Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
remove named parameter labels
Browse files Browse the repository at this point in the history
IMHO it makes things simpler
  • Loading branch information
schnipseljagd committed Dec 18, 2015
1 parent ed57ea4 commit 8a3e611
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 14 additions & 10 deletions src/prometheus/core.clj
Expand Up @@ -62,21 +62,25 @@

(defn increase-counter
"Increase the value of a registered counter."
[store namespace metric & {:keys [amount labels] :or {amount 1.0 labels []}}]
(-> (counter-with-labels (get-in store [:metrics namespace metric]) labels)
(.inc amount)))
([store namespace metric] (increase-counter store namespace metric [] 1.0))
([store namespace metric labels] (increase-counter store namespace metric labels 1.0))
([store namespace metric labels amount]
(-> (counter-with-labels (get-in store [:metrics namespace metric]) labels)
(.inc amount))))

(defn set-gauge
"Set the value of a registered gauge."
[store namespace metric value & {:keys [labels] :or {labels []}}]
(-> (gauge-with-labels (get-in store [:metrics namespace metric]) labels)
(.set value)))
([store namespace metric value] (set-gauge store namespace metric value []))
([store namespace metric value labels]
(-> (gauge-with-labels (get-in store [:metrics namespace metric]) labels)
(.set value))))

(defn track-observation
"Track the value of an observation for a registered histogram."
[store namespace metric value & {:keys [labels] :or {labels []}}]
(-> (histogram-with-labels (get-in store [:metrics namespace metric]) labels)
(.observe value)))
([store namespace metric value] (track-observation store namespace metric value []))
([store namespace metric value labels]
(-> (histogram-with-labels (get-in store [:metrics namespace metric]) labels)
(.observe value))))

(defn init-defaults
"Initialize the metrics system with defaults."
Expand All @@ -99,7 +103,7 @@
method-label (string/upper-case (name request-method))
labels [method-label (str response-status) status-class response-path]]
(track-observation metrics-store app-name "http_request_latency_seconds" request-time labels)
(increase-counter metrics-store app-name "http_requests_total")))
(increase-counter metrics-store app-name "http_requests_total" labels)))

(defn instrument-handler
"Ring middleware to record request metrics"
Expand Down
6 changes: 3 additions & 3 deletions test/prometheus/core_test.clj
Expand Up @@ -29,11 +29,11 @@
store {:registry registry}]
(testing "adds a custom counter"
(let [store (prometheus/register-counter store "test" "my_custom_counter" "some counter" ["foo"])]
(prometheus/increase-counter store "test" "my_custom_counter" :labels ["bar"])
(prometheus/increase-counter store "test" "my_custom_counter" ["bar"])
(is (.contains (:body (prometheus/dump-metrics registry)) "test_my_custom_counter"))))
(testing "adds a custom gauge"
(let [store (prometheus/register-gauge store "test" "my_custom_gauge" "some gauge" ["foo"])]
(prometheus/set-gauge store "test" "my_custom_gauge" 101 :labels ["bar"])
(prometheus/set-gauge store "test" "my_custom_gauge" 101 ["bar"])
(is (.contains (:body (prometheus/dump-metrics (:registry store)))
"test_my_custom_gauge{foo=\"bar\",} 101.0"))))
(testing "adds a custom histogram"
Expand All @@ -44,7 +44,7 @@
"some histogram"
["foo"]
[10 90 100])]
(prometheus/track-observation store "test" "my_custom_histogram" 87 :labels ["bar"])
(prometheus/track-observation store "test" "my_custom_histogram" 87 ["bar"])
(is (.contains (:body (prometheus/dump-metrics registry))
"test_my_custom_histogram_bucket{foo=\"bar\",le=\"90.0\",} 1.0"))
(is (.contains (:body (prometheus/dump-metrics registry))
Expand Down

0 comments on commit 8a3e611

Please sign in to comment.