Skip to content

Commit a02c3f2

Browse files
committed
Change caffeine_cache_eviction_weight from Gauge to Counter
Signed-off-by: Jean Hominal <[email protected]>
1 parent e05ca38 commit a02c3f2

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

prometheus-metrics-instrumentation-caffeine/src/main/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ public MetricSnapshots collect() {
146146
.name(METRIC_NAME_CACHE_EVICTION)
147147
.help("Cache eviction totals, doesn't include manually removed entries");
148148

149-
final GaugeSnapshot.Builder cacheEvictionWeight =
150-
GaugeSnapshot.builder()
149+
final CounterSnapshot.Builder cacheEvictionWeight =
150+
CounterSnapshot.builder()
151151
.name(METRIC_NAME_CACHE_EVICTION_WEIGHT)
152-
.help("Cache eviction weight");
152+
.help("Weight of evicted cache entries, doesn't include manually removed entries");
153153

154154
final CounterSnapshot.Builder cacheLoadFailure =
155155
CounterSnapshot.builder().name(METRIC_NAME_CACHE_LOAD_FAILURE).help("Cache load failures");
@@ -175,7 +175,7 @@ public MetricSnapshots collect() {
175175

176176
try {
177177
cacheEvictionWeight.dataPoint(
178-
GaugeSnapshot.GaugeDataPointSnapshot.builder()
178+
CounterSnapshot.CounterDataPointSnapshot.builder()
179179
.labels(labels)
180180
.value(stats.evictionWeight())
181181
.build());

prometheus-metrics-instrumentation-caffeine/src/test/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollectorTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void cacheExposesMetricsForHitMissAndEviction() {
5252
assertCounterMetric(registry, "caffeine_cache_miss", "users", 2.0);
5353
assertCounterMetric(registry, "caffeine_cache_requests", "users", 3.0);
5454
assertCounterMetric(registry, "caffeine_cache_eviction", "users", 2.0);
55+
assertCounterMetric(registry, "caffeine_cache_eviction_weight", "users", 2.0);
5556

5657
final String expected =
5758
"# TYPE caffeine_cache_estimated_size gauge\n"
@@ -60,9 +61,9 @@ public void cacheExposesMetricsForHitMissAndEviction() {
6061
+ "# TYPE caffeine_cache_eviction counter\n"
6162
+ "# HELP caffeine_cache_eviction Cache eviction totals, doesn't include manually removed entries\n"
6263
+ "caffeine_cache_eviction_total{cache=\"users\"} 2.0\n"
63-
+ "# TYPE caffeine_cache_eviction_weight gauge\n"
64-
+ "# HELP caffeine_cache_eviction_weight Cache eviction weight\n"
65-
+ "caffeine_cache_eviction_weight{cache=\"users\"} 2.0\n"
64+
+ "# TYPE caffeine_cache_eviction_weight counter\n"
65+
+ "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n"
66+
+ "caffeine_cache_eviction_weight_total{cache=\"users\"} 2.0\n"
6667
+ "# TYPE caffeine_cache_hit counter\n"
6768
+ "# HELP caffeine_cache_hit Cache hit totals\n"
6869
+ "caffeine_cache_hit_total{cache=\"users\"} 1.0\n"

0 commit comments

Comments
 (0)