Skip to content

Commit

Permalink
Add KV Resource Store Byte Count Metric
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed Mar 31, 2021
1 parent ab6c6f0 commit 86155c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion modules/db-resource-store/src/blaze/db/resource_store/kv.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@
[blaze.db.resource-store :as rs]
[blaze.executors :as ex]
[blaze.fhir.spec :as fhir-spec]
[blaze.module :refer [reg-collector]]
[clojure.spec.alpha :as s]
[cognitect.anomalies :as anom]
[integrant.core :as ig]
[prometheus.alpha :as prom :refer [defhistogram]]
[taoensso.timbre :as log])
(:import
[java.util.concurrent ExecutorService TimeUnit]))


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


(defn- parse-msg [hash e]
(format "Error while parsing resource content with hash `%s`: %s"
(bs/hex hash) (ex-message e)))
Expand All @@ -42,7 +52,9 @@
(def ^:private entry-freezer
(map
(fn [[k v]]
[(bs/to-byte-array k) (fhir-spec/unform-cbor v)])))
(let [content (fhir-spec/unform-cbor v)]
(prom/observe! resource-bytes (alength content))
[(bs/to-byte-array k) content]))))


(defn- get-content [kv-store hash]
Expand Down Expand Up @@ -109,3 +121,7 @@


(derive ::executor :blaze.metrics/thread-pool-executor)


(reg-collector ::resource-bytes
resource-bytes)
7 changes: 7 additions & 0 deletions resources/blaze.edn
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@
:blaze.db.resource-store.kv/executor
{:num-threads #blaze/cfg ["DB_RESOURCE_STORE_KV_THREADS" int? 4]}

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

;;
;; In-Memory, Volatile Key-Value Store Resource Store Backend
;;
Expand Down Expand Up @@ -467,6 +469,8 @@
:blaze.db.resource-store.kv/executor
{:num-threads #blaze/cfg ["DB_RESOURCE_STORE_KV_THREADS" int? 4]}

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

;;
;; RocksDB Key-Value Store Resource Store Backend
;;
Expand All @@ -486,6 +490,9 @@
:level0-file-num-compaction-trigger 2
:min-write-buffer-number-to-merge 2
:max-bytes-for-level-base-in-mb 256
;; According to Synthea test data, a resource has an average size of
;; 1300 bytes. So a block with a size of 16 kb will hold about 10
;; resources in average.
:block-size #blaze/cfg ["DB_BLOCK_SIZE" int? 16384]
:bloom-filter? true}}}

Expand Down

0 comments on commit 86155c8

Please sign in to comment.