Skip to content

Commit

Permalink
Add Metrics to KV Resource Store
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed May 2, 2022
1 parent 21d49df commit 12e737c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
27 changes: 21 additions & 6 deletions modules/db-resource-store/src/blaze/db/resource_store/kv.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@


(defhistogram resource-bytes
"Stored resource sizes in bytes in key-value resource store."
"Stored resource sizes in key-value resource store."
{:namespace "blaze"
:subsystem "db"
:name "resource_store_kv_resource_bytes"}
(take 16 (iterate #(* 2 %) 32)))


(defhistogram duration-seconds
"Durations in key-value resource store."
{:namespace "blaze"
:subsystem "db"
:name "resource_store_kv_duration_seconds"}
(take 16 (iterate #(* 2 %) 1e-6))
"op")


(defn- parse-msg [hash cause-msg]
(format "Error while parsing resource content with hash `%s`: %s"
hash cause-msg))
Expand Down Expand Up @@ -60,8 +69,9 @@


(defn- parse-and-conform-cbor [bytes hash]
(when-ok [x (parse-cbor bytes hash)]
(conform-cbor x hash)))
(with-open [_ (prom/timer duration-seconds "parse-resource")]
(when-ok [x (parse-cbor bytes hash)]
(conform-cbor x hash))))


(def ^:private entry-thawer
Expand All @@ -83,11 +93,13 @@


(defn- get-content [kv-store hash]
(kv/get kv-store (hash/to-byte-array hash)))
(with-open [_ (prom/timer duration-seconds "get-resource")]
(kv/get kv-store (hash/to-byte-array hash))))


(defn- multi-get-content [kv-store hashes]
(kv/multi-get kv-store (mapv hash/to-byte-array hashes)))
(with-open [_ (prom/timer duration-seconds "get-resources")]
(kv/multi-get kv-store (mapv hash/to-byte-array hashes))))


(deftype KvResourceStore [kv-store executor]
Expand All @@ -101,7 +113,6 @@
(-multi-get [_ hashes]
(log/trace "multi-get" (count hashes) "hash(es)")
(ac/supply-async
;; TODO - make thawing parallel
#(transduce entry-thawer conj {} (multi-get-content kv-store hashes))
executor))

Expand Down Expand Up @@ -152,3 +163,7 @@

(reg-collector ::resource-bytes
resource-bytes)


(reg-collector ::duration-seconds
duration-seconds)
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
(is (s/valid? :blaze.metrics/collector collector))))


(deftest duration-seconds-collector-init-test
(with-system [{collector ::rs-kv/duration-seconds} {::rs-kv/duration-seconds {}}]
(is (s/valid? :blaze.metrics/collector collector))))


(def system
{::rs/kv
{:kv-store (ig/ref ::kv/mem)
Expand Down
2 changes: 2 additions & 0 deletions resources/blaze.edn
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
{:num-threads #blaze/cfg ["DB_RESOURCE_STORE_KV_THREADS" pos-int? 4]}

:blaze.db.resource-store.kv/resource-bytes {}
:blaze.db.resource-store.kv/duration-seconds {}

;;
;; In-Memory, Volatile Key-Value Store Resource Store Backend
Expand Down Expand Up @@ -482,6 +483,7 @@
{:num-threads #blaze/cfg ["DB_RESOURCE_STORE_KV_THREADS" pos-int? 4]}

:blaze.db.resource-store.kv/resource-bytes {}
:blaze.db.resource-store.kv/duration-seconds {}

;;
;; RocksDB Key-Value Store Resource Store Backend
Expand Down

0 comments on commit 12e737c

Please sign in to comment.