Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 23, 2020. It is now read-only.

Commit db7eea9

Browse files
committed
Merge pull request #150 from marcesher/master
Add metric collection around aggregation cache hits, misses, and waits
2 parents c96cbc6 + eb5c894 commit db7eea9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/cfpb/qu/cache.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ the same backing database have access to the same data."
1212
[cfpb.qu.util :refer :all]
1313
[cfpb.qu.data.result :refer [->DataResult]]
1414
[cfpb.qu.data.aggregation :as agg]
15+
[cfpb.qu.metrics :as metrics]
1516
[clojure.string :as str]
1617
[clojure.core.cache :as cache :refer [defcache]]
1718
[clj-time.core :refer [now]]
@@ -92,9 +93,11 @@ the same backing database have access to the same data."
9293
([database query not-found]
9394
(with-db database
9495
(let [collection (query-to-key query)]
95-
(if (coll/exists? collection)
96-
(extract-result collection query)
97-
not-found)))))
96+
(if (coll/exists? collection)
97+
(do (metrics/increment "cache.hit")
98+
(extract-result collection query))
99+
(do (metrics/increment "cache.wait")
100+
not-found))))))
98101

99102
(defn add-to-cache
100103
"Add the specified aggregation to the cache by running it through
@@ -255,6 +258,7 @@ one of `query_cache` will be used."
255258
[cache aggmap]
256259
(with-db (:database cache)
257260
(try
261+
(metrics/increment "cache.queue")
258262
(coll/insert-and-return *work-collection* {:_id (:to aggmap)
259263
:status "unprocessed"
260264
:created (now)

0 commit comments

Comments
 (0)