-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Cache Collector into it's own Module
We need the cache collector in the CQL expression cache. Needed in: #1051
- Loading branch information
1 parent
8a4b1a9
commit a2d8afe
Showing
16 changed files
with
257 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{:config-paths | ||
["../../../.clj-kondo/root" | ||
"../../module-test-util/resources/clj-kondo.exports/blaze/module-test-util"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
fmt: | ||
cljfmt check | ||
|
||
lint: | ||
clj-kondo --lint src test deps.edn | ||
|
||
prep: | ||
clojure -X:deps prep | ||
|
||
test: prep | ||
clojure -M:test:kaocha --profile :ci | ||
|
||
test-coverage: prep | ||
clojure -M:test:coverage | ||
|
||
deps-tree: | ||
clojure -X:deps tree | ||
|
||
deps-list: | ||
clojure -X:deps list | ||
|
||
clean: | ||
rm -rf .clj-kondo/.cache .cpcache target | ||
|
||
.PHONY: fmt lint prep test test-coverage deps-tree deps-list clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{:deps | ||
{blaze/metrics | ||
{:local/root "../metrics"} | ||
|
||
blaze/module-base | ||
{:local/root "../module-base"} | ||
|
||
com.github.ben-manes.caffeine/caffeine | ||
{:mvn/version "3.1.8"}} | ||
|
||
:aliases | ||
{:test | ||
{:extra-paths ["test"] | ||
|
||
:extra-deps | ||
{blaze/module-test-util | ||
{:local/root "../module-test-util"}}} | ||
|
||
:kaocha | ||
{:extra-deps | ||
{lambdaisland/kaocha | ||
{:mvn/version "1.85.1342"}} | ||
|
||
:main-opts ["-m" "kaocha.runner"]} | ||
|
||
:test-perf | ||
{:extra-paths ["test-perf"] | ||
|
||
:extra-deps | ||
{blaze/fhir-test-util | ||
{:local/root "../fhir-test-util"} | ||
|
||
criterium/criterium | ||
{:mvn/version "0.4.6"} | ||
|
||
org.openjdk.jol/jol-core | ||
{:mvn/version "0.17"}}} | ||
|
||
:coverage | ||
{:extra-deps | ||
{cloverage/cloverage | ||
{:mvn/version "1.2.4"}} | ||
|
||
:main-opts ["-m" "cloverage.coverage" "--codecov" "-p" "src" "-s" "test" | ||
"-e" ".+spec"]}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rc/blaze/db/cache_collector/protocols.clj → ...r/src/blaze/cache_collector/protocols.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns blaze.cache-collector.spec | ||
(:require | ||
[blaze.cache-collector.protocols :as p] | ||
[clojure.spec.alpha :as s])) | ||
|
||
(s/def :blaze.cache-collector/caches | ||
(s/map-of string? (s/nilable #(satisfies? p/StatsCache %)))) |
142 changes: 142 additions & 0 deletions
142
modules/cache-collector/test/blaze/cache_collector_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
(ns blaze.cache-collector-test | ||
(:require | ||
[blaze.cache-collector] | ||
[blaze.metrics.core :as metrics] | ||
[blaze.module.test-util :refer [with-system]] | ||
[blaze.test-util :as tu :refer [given-thrown]] | ||
[clojure.spec.alpha :as s] | ||
[clojure.spec.test.alpha :as st] | ||
[clojure.test :as test :refer [deftest testing]] | ||
[integrant.core :as ig] | ||
[juxt.iota :refer [given]]) | ||
(:import | ||
[com.github.benmanes.caffeine.cache AsyncCache Cache Caffeine] | ||
[java.util.function Function])) | ||
|
||
(set! *warn-on-reflection* true) | ||
(st/instrument) | ||
|
||
(test/use-fixtures :each tu/fixture) | ||
|
||
(def ^Cache cache (-> (Caffeine/newBuilder) (.recordStats) (.build))) | ||
(def ^AsyncCache async-cache (-> (Caffeine/newBuilder) (.recordStats) (.buildAsync))) | ||
|
||
(def config | ||
{:blaze/cache-collector | ||
{:caches | ||
{"name-135224" cache | ||
"name-145135" async-cache | ||
"name-093214" nil}}}) | ||
|
||
(deftest init-test | ||
(testing "nil config" | ||
(given-thrown (ig/init {:blaze/cache-collector nil}) | ||
:key := :blaze/cache-collector | ||
:reason := ::ig/build-failed-spec | ||
[:cause-data ::s/problems 0 :pred] := `map?)) | ||
|
||
(testing "missing config" | ||
(given-thrown (ig/init {:blaze/cache-collector {}}) | ||
:key := :blaze/cache-collector | ||
:reason := ::ig/build-failed-spec | ||
[:cause-data ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :caches)))) | ||
|
||
(testing "invalid caches" | ||
(given-thrown (ig/init {:blaze/cache-collector {:caches ::invalid}}) | ||
:key := :blaze/cache-collector | ||
:reason := ::ig/build-failed-spec | ||
[:cause-data ::s/problems 0 :pred] := `map? | ||
[:cause-data ::s/problems 0 :val] := ::invalid))) | ||
|
||
(deftest cache-collector-test | ||
(with-system [{collector :blaze/cache-collector} config] | ||
|
||
(testing "all zero on fresh cache" | ||
(given (metrics/collect collector) | ||
[0 :name] := "blaze_cache_hits" | ||
[0 :type] := :counter | ||
[0 :samples count] := 2 | ||
[0 :samples 0 :value] := 0.0 | ||
[0 :samples 0 :label-values] := ["name-135224"] | ||
[0 :samples 1 :value] := 0.0 | ||
[0 :samples 1 :label-values] := ["name-145135"] | ||
[1 :name] := "blaze_cache_misses" | ||
[1 :type] := :counter | ||
[1 :samples count] := 2 | ||
[1 :samples 0 :value] := 0.0 | ||
[1 :samples 1 :value] := 0.0 | ||
[2 :name] := "blaze_cache_load_successes" | ||
[2 :type] := :counter | ||
[2 :samples count] := 2 | ||
[2 :samples 0 :value] := 0.0 | ||
[2 :samples 1 :value] := 0.0 | ||
[3 :name] := "blaze_cache_load_failures" | ||
[3 :type] := :counter | ||
[3 :samples count] := 2 | ||
[3 :samples 0 :value] := 0.0 | ||
[3 :samples 1 :value] := 0.0 | ||
[4 :name] := "blaze_cache_load_seconds" | ||
[4 :type] := :counter | ||
[4 :samples count] := 2 | ||
[4 :samples 0 :value] := 0.0 | ||
[4 :samples 1 :value] := 0.0 | ||
[5 :name] := "blaze_cache_evictions" | ||
[5 :type] := :counter | ||
[5 :samples count] := 2 | ||
[5 :samples 0 :value] := 0.0 | ||
[5 :samples 1 :value] := 0.0 | ||
[6 :name] := "blaze_cache_estimated_size" | ||
[6 :type] := :gauge | ||
[6 :samples count] := 2 | ||
[6 :samples 0 :value] := 0.0 | ||
[6 :samples 1 :value] := 0.0)) | ||
|
||
(testing "one load" | ||
(.get cache "1" (reify Function (apply [_ key] key))) | ||
(.get async-cache "1" (reify Function (apply [_ key] key))) | ||
(Thread/sleep 100) | ||
|
||
(given (metrics/collect collector) | ||
[0 :name] := "blaze_cache_hits" | ||
[0 :samples 0 :value] := 0.0 | ||
[0 :samples 1 :value] := 0.0 | ||
[1 :name] := "blaze_cache_misses" | ||
[1 :samples 0 :value] := 1.0 | ||
[1 :samples 1 :value] := 1.0 | ||
[2 :name] := "blaze_cache_load_successes" | ||
[2 :samples 0 :value] := 1.0 | ||
[2 :samples 1 :value] := 1.0 | ||
[3 :name] := "blaze_cache_load_failures" | ||
[3 :samples 0 :value] := 0.0 | ||
[3 :samples 1 :value] := 0.0 | ||
[5 :name] := "blaze_cache_evictions" | ||
[5 :samples 0 :value] := 0.0 | ||
[5 :samples 1 :value] := 0.0 | ||
[6 :name] := "blaze_cache_estimated_size" | ||
[6 :samples 0 :value] := 1.0 | ||
[6 :samples 1 :value] := 1.0)) | ||
|
||
(testing "one loads and one hit" | ||
(.get cache "1" (reify Function (apply [_ key] key))) | ||
(.get async-cache "1" (reify Function (apply [_ key] key))) | ||
(Thread/sleep 100) | ||
|
||
(given (metrics/collect collector) | ||
[0 :name] := "blaze_cache_hits" | ||
[0 :samples 0 :value] := 1.0 | ||
[0 :samples 1 :value] := 1.0 | ||
[1 :name] := "blaze_cache_misses" | ||
[1 :samples 0 :value] := 1.0 | ||
[1 :samples 1 :value] := 1.0 | ||
[2 :name] := "blaze_cache_load_successes" | ||
[2 :samples 0 :value] := 1.0 | ||
[2 :samples 1 :value] := 1.0 | ||
[3 :name] := "blaze_cache_load_failures" | ||
[3 :samples 0 :value] := 0.0 | ||
[3 :samples 1 :value] := 0.0 | ||
[5 :name] := "blaze_cache_evictions" | ||
[5 :samples 0 :value] := 0.0 | ||
[5 :samples 1 :value] := 0.0 | ||
[6 :name] := "blaze_cache_estimated_size" | ||
[6 :samples 0 :value] := 1.0 | ||
[6 :samples 1 :value] := 1.0)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#kaocha/v1 | ||
#merge | ||
[{} | ||
#profile {:ci {:reporter kaocha.report/documentation | ||
:color? false}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.