Skip to content

Commit 2e63181

Browse files
committed
Update caffeine.md to take in account modifications from #1251
Signed-off-by: Jean Hominal <[email protected]>
1 parent 3ceb37a commit 2e63181

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

docs/content/instrumentation/caffeine.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ In order to collect metrics:
3434

3535
```java
3636
var cache = Caffeine.newBuilder().recordStats().build();
37-
var cacheMetrics = new CacheMetricsCollector();
37+
var cacheMetrics = CacheMetricsCollector.builder().build();
3838
PrometheusRegistry.defaultRegistry.register(cacheMetrics);
3939
cacheMetrics.addCache("mycache", cache);
4040
```
4141

42+
{{< hint type=note >}}
43+
44+
In version 1.3.5 and older of the caffeine instrumentation library, `CacheMetricsCollector.builder`
45+
does not exist, i.e. a constructor call `new CacheMetricsCollector()` is the only option.
46+
47+
{{< /hint >}}
48+
4249
All example metrics on this page will use the `mycache` label value.
4350

4451
Generic Cache Metrics
@@ -87,15 +94,33 @@ caffeine_cache_load_duration_seconds_sum{cache="mycache"} 0.0034
8794
Weighted Cache Metrics
8895
----------------------
8996

90-
If the cache is weighted, i.e. it defines a `weigher` function, then the following metrics
91-
become interesting:
97+
Two metrics exist for observability specifically of caches that define a `weigher`:
9298

9399
```
94-
# TYPE caffeine_cache_eviction_weight gauge
95-
# HELP caffeine_cache_eviction_weight Cache eviction weight
96-
caffeine_cache_eviction_weight{cache="mycache"} 5.0
100+
# TYPE caffeine_cache_eviction_weight counter
101+
# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries
102+
caffeine_cache_eviction_weight_total{cache="mycache"} 5.0
103+
# TYPE caffeine_cache_weighted_size gauge
104+
# HELP caffeine_cache_weighted_size Approximate accumulated weight of cache entries
105+
caffeine_cache_weighted_size{cache="mycache"} 30.0
97106
```
98107

99-
Note: while `caffeine_cache_eviction_weight` is exported as a `gauge` metric, it represents
100-
a monotonicaly increasing value. Also, in the case where the cache does not define a `weigher`
101-
function, it will return the same values as `caffeine_cache_eviction_total`.
108+
{{< hint type=note >}}
109+
110+
`caffeine_cache_weighted_size` is available only if the cache instance defines a `maximumWeight`.
111+
112+
{{< /hint >}}
113+
114+
Up to version 1.3.5 and older, the weighted metrics had a different behavior:
115+
116+
* `caffeine_cache_weighted_size` was not implemented;
117+
* `caffeine_cache_eviction_weight` was exposed as a `gauge`;
118+
119+
It is possible to restore the behavior of version 1.3.5 and older, by either:
120+
121+
* Using the deprecated `new CacheMetricsCollector()` constructor;
122+
* Using the flags provided on the `CacheMetricsCollector.Builder` object to opt-out of each of the
123+
elements of the post-1.3.5 behavior:
124+
* `builder.collectWeightedSize(false)` will disable collection of `caffeine_cache_weighted_size`;
125+
* `builder.collectEvictionWeightAsCounter(false)` will expose `caffeine_cache_eviction_weight` as
126+
a `gauge` metric;

0 commit comments

Comments
 (0)