Skip to content

Commit

Permalink
refactor(telemetry): replace the deprecated method and constructor du…
Browse files Browse the repository at this point in the history
…ring upgrade of spring boot 3.0.x

While upgrading the spring boot to 3.0.13 and spring cloud 2022.0.5, encountered the below errors during build process of kork-telemetry module:
```
> Task :kork-telemetry:compileJava FAILED
/kork/kork-telemetry/src/main/java/com/netflix/spinnaker/kork/telemetry/caffeine/CaffeineStatsCounter.java:26: error: CaffeineStatsCounter is not abstract and does not override abstract method recordEviction(int,RemovalCause) in StatsCounter
public class CaffeineStatsCounter implements StatsCounter {
       ^
/kork/kork-telemetry/src/main/java/com/netflix/spinnaker/kork/telemetry/caffeine/CaffeineStatsCounter.java:73: error: method does not override or implement a method from a supertype
  @OverRide
  ^
/kork/kork-telemetry/src/main/java/com/netflix/spinnaker/kork/telemetry/caffeine/CaffeineStatsCounter.java:79: error: method does not override or implement a method from a supertype
  @OverRide
  ^
/kork/kork-telemetry/src/main/java/com/netflix/spinnaker/kork/telemetry/caffeine/CaffeineStatsCounter.java:87: error: CacheStats(long,long,long,long,long,long,long) has private access in CacheStats
    return new CacheStats(
           ^
4 errors
```
Spring boot upgrade brings the caffeine 3.1.8 transitively, that was 2.9.3 with spring boot 2.7.x.
In caffeine 3.x, `StatsCounter.recordEviction` method variation has been deprecated and `CacheStats` constructor. So, update the both of them.
https://github.com/ben-manes/caffeine/releases/tag/v3.0.0
https://javadoc.io/doc/com.github.ben-manes.caffeine/caffeine/latest/com.github.benmanes.caffeine/com/github/benmanes/caffeine/cache/stats/StatsCounter.html
https://javadoc.io/doc/com.github.ben-manes.caffeine/caffeine/2.9.3/com/github/benmanes/caffeine/cache/stats/StatsCounter.html
  • Loading branch information
j-sandy committed Dec 19, 2024
1 parent 2fc453e commit b847d01
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.kork.telemetry.caffeine;

import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.stats.CacheStats;
import com.github.benmanes.caffeine.cache.stats.StatsCounter;
import com.netflix.spectator.api.Counter;
Expand Down Expand Up @@ -71,20 +72,14 @@ public void recordLoadFailure(long loadTime) {
}

@Override
@SuppressWarnings("deprecation")
public void recordEviction() {
recordEviction(1);
}

@Override
public void recordEviction(int weight) {
public void recordEviction(int weight, RemovalCause cause) {
evictionCount.increment();
evictionWeight.increment(weight);
}

@Override
public CacheStats snapshot() {
return new CacheStats(
return CacheStats.of(
hitCount.count(),
missCount.count(),
loadSuccessCount.count(),
Expand Down

0 comments on commit b847d01

Please sign in to comment.