Skip to content

Commit

Permalink
Merge 13fc1db into 8110df5
Browse files Browse the repository at this point in the history
  • Loading branch information
theanirudhvyas committed Sep 30, 2019
2 parents 8110df5 + 13fc1db commit 7aa5a44
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. This change

## Unreleased Changes

## 2.12.5 - 2019-09-30
- Rename report-time to report-histogram while still keeping the old API

## 2.12.4 - 2019-08-22
- Fix increment/decrement count by supporting both number and map

Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject tech.gojek/ziggurat "2.12.3"
(defproject tech.gojek/ziggurat "2.12.5"
:description "A stream processing framework to build stateless applications on kafka"
:url "https://github.com/gojektech/ziggurat"
:license {:name "Apache License, Version 2.0"
Expand Down
14 changes: 8 additions & 6 deletions src/ziggurat/metrics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@
(doseq [ns nss]
(increment-count ns metric additional-tags)))

(defn report-time
([metric-namespaces time-val]
(report-time metric-namespaces time-val nil))
([metric-namespaces time-val additional-tags]
(defn report-histogram
([metric-namespaces val]
(report-histogram metric-namespaces val nil))
([metric-namespaces val additional-tags]
(let [metric-namespace (get-metric-namespaces metric-namespaces)
histogram ^Histogram (mk-histogram metric-namespace "all" (remove-topic-tag-for-old-namespace additional-tags metric-namespaces))]
(.update histogram (int time-val)))))
(.update histogram (get-int val)))))

(def report-time report-histogram) ;; for backward compatibility

(defn multi-ns-report-time [nss time-val additional-tags]
(doseq [ns nss]
(report-time ns time-val additional-tags)))
(report-histogram ns time-val additional-tags)))

(defn start-statsd-reporter [statsd-config env]
(let [{:keys [enabled host port]} statsd-config]
Expand Down
4 changes: 2 additions & 2 deletions test/ziggurat/kafka_delay_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
(testing "calculates and reports the timestamp delay"
(let [expected-additional-tags {:topic_name "expected-topic-entity-name"}]
(with-redefs [get-current-time-in-millis (constantly current-time)
metrics/report-time (fn [metric-namespaces delay additional-tags]
metrics/report-histogram (fn [metric-namespaces delay additional-tags]
(is (= delay expected-delay))
(is (= metric-namespaces expected-namespaces))
(is (= additional-tags expected-additional-tags)))]
(calculate-and-report-kafka-delay expected-namespaces record-timestamp expected-additional-tags))))
(testing "calculates and reports the timestamp delay when additional tags is empty or nil"
(let [expected-additional-tags nil]
(with-redefs [get-current-time-in-millis (constantly current-time)
metrics/report-time (fn [metric-namespaces delay additional-tags]
metrics/report-histogram (fn [metric-namespaces delay additional-tags]
(is (= delay expected-delay))
(is (= metric-namespaces expected-namespaces))
(is (= additional-tags expected-additional-tags)))]
Expand Down
40 changes: 20 additions & 20 deletions test/ziggurat/mapper_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
(let [successfully-processed? (atom false)
successfully-reported-time? (atom false)
expected-metric "success"]
(with-redefs [metrics/increment-count (fn [metric-namespaces metric additional-tags]
(when (and (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [default-namespace]))
(= metric expected-metric)
(= additional-tags expected-additional-tags))
(reset! successfully-processed? true)))
metrics/report-time (fn [metric-namespaces _ _]
(when (or (= metric-namespaces expected-report-time-namespaces)
(= metric-namespaces [report-time-namespace]))
(reset! successfully-reported-time? true)))]
(with-redefs [metrics/increment-count (fn [metric-namespaces metric additional-tags]
(when (and (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [default-namespace]))
(= metric expected-metric)
(= additional-tags expected-additional-tags))
(reset! successfully-processed? true)))
metrics/report-histogram (fn [metric-namespaces _ _]
(when (or (= metric-namespaces expected-report-time-namespaces)
(= metric-namespaces [report-time-namespace]))
(reset! successfully-reported-time? true)))]
((mapper-func (constantly :success) expected-topic-entity-name []) message)
(is @successfully-processed?)
(is @successfully-reported-time?))))
Expand Down Expand Up @@ -106,12 +106,12 @@
(let [reported-execution-time? (atom false)
execution-time-namesapce "handler-fn-execution-time"
expected-metric-namespaces [service-name "default" execution-time-namesapce]]
(with-redefs [metrics/report-time (fn [metric-namespaces _ _]
(is (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [execution-time-namesapce])))
(when (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [execution-time-namesapce]))
(reset! reported-execution-time? true)))]
(with-redefs [metrics/report-histogram (fn [metric-namespaces _ _]
(is (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [execution-time-namesapce])))
(when (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [execution-time-namesapce]))
(reset! reported-execution-time? true)))]

((mapper-func (constantly :success) expected-topic-entity-name []) message)
(is @reported-execution-time?))))))
Expand Down Expand Up @@ -179,9 +179,9 @@
(testing "reports execution time with topic prefix"
(let [reported-execution-time? (atom false)
execution-time-namesapce "execution-time"]
(with-redefs [metrics/report-time (fn [metric-namespaces _ _]
(when (or (= metric-namespaces [service-name expected-topic-entity-name channel-name execution-time-namesapce])
(= metric-namespaces [execution-time-namesapce]))
(reset! reported-execution-time? true)))]
(with-redefs [metrics/report-histogram (fn [metric-namespaces _ _]
(when (or (= metric-namespaces [service-name expected-topic-entity-name channel-name execution-time-namesapce])
(= metric-namespaces [execution-time-namesapce]))
(reset! reported-execution-time? true)))]
((channel-mapper-func (constantly :success) topic channel) message)
(is @reported-execution-time?))))))
8 changes: 4 additions & 4 deletions test/ziggurat/metrics_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
(reset! mk-histogram-args {:metric-namespaces metric-namespaces
:metric metric})
histogram)]
(metrics/report-time expected-metric-namespaces time-val input-additional-tags)
(metrics/report-histogram expected-metric-namespaces time-val input-additional-tags)
(is (= 1 (.getCount histogram)))
(is (= (apply str (interpose "." expected-metric-namespaces)) (:metric-namespaces @mk-histogram-args)))
(is (= "all" (:metric @mk-histogram-args))))))
Expand All @@ -242,7 +242,7 @@
(reset! mk-histogram-args {:metric-namespaces metric-namespaces
:metric metric})
histogram)]
(metrics/report-time expected-metric-namespaces time-val input-additional-tags)
(metrics/report-histogram expected-metric-namespaces time-val input-additional-tags)
(is (= 1 (.getCount histogram)))
(is (= (str (:app-name (ziggurat-config)) "." expected-metric-namespaces) (:metric-namespaces @mk-histogram-args)))
(is (= "all" (:metric @mk-histogram-args))))))
Expand All @@ -257,7 +257,7 @@
(reset! mk-histogram-args {:metric-namespaces metric-namespaces
:metric metric})
histogram)]
(metrics/report-time expected-metric-namespaces time-val)
(metrics/report-histogram expected-metric-namespaces time-val)
(is (= 1 (.getCount histogram)))
(is (= (apply str (interpose "." expected-metric-namespaces)) (:metric-namespaces @mk-histogram-args)))
(is (= "all" (:metric @mk-histogram-args))))))
Expand All @@ -272,7 +272,7 @@
(reset! mk-histogram-args {:metric-namespaces metric-namespaces
:metric metric})
histogram)]
(metrics/report-time expected-metric-namespaces time-val input-additional-tags)
(metrics/report-histogram expected-metric-namespaces time-val input-additional-tags)
(is (= 1 (.getCount histogram)))
(is (= (apply str (interpose "." expected-metric-namespaces)) (:metric-namespaces @mk-histogram-args)))
(is (= "all" (:metric @mk-histogram-args))))))))
4 changes: 2 additions & 2 deletions test/ziggurat/timestamp_transformer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
timestamp-transformer (create expected-metric-namespaces current-time expected-topic-entity-name)]
(.init timestamp-transformer context)
(with-redefs [get-current-time-in-millis (constantly current-time)
metrics/report-time (fn [metric-namespaces delay topic-entity-name]
metrics/report-histogram (fn [metric-namespaces delay topic-entity-name]
(is (= delay expected-delay))
(is (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [default-namespace])))
Expand All @@ -52,7 +52,7 @@
timestamp-transformer (create expected-metric-namespaces current-time)]
(.init timestamp-transformer context)
(with-redefs [get-current-time-in-millis (constantly current-time)
metrics/report-time (fn [metric-namespaces delay topic-entity-name]
metrics/report-histogram (fn [metric-namespaces delay topic-entity-name]
(is (= delay expected-delay))
(is (or (= metric-namespaces expected-metric-namespaces)
(= metric-namespaces [default-namespace])))
Expand Down

0 comments on commit 7aa5a44

Please sign in to comment.