@@ -0,0 +1,3107 @@
+/*%0A * Copyright 2019 Netflix, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.netflix.spinnaker.kork.telemetry.caffeine;%0A%0Aimport com.github.benmanes.caffeine.cache.stats.CacheStats;%0Aimport com.github.benmanes.caffeine.cache.stats.StatsCounter;%0Aimport com.netflix.spectator.api.Counter;%0Aimport com.netflix.spectator.api.Registry;%0Aimport com.netflix.spectator.api.Timer;%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class CaffeineStatsCounter implements StatsCounter %7B%0A  private final Counter hitCount;%0A  private final Counter missCount;%0A  private final Counter loadSuccessCount;%0A  private final Counter loadFailureCount;%0A  private final Timer totalLoadTime;%0A  private final Counter evictionCount;%0A  private final Counter evictionWeight;%0A%0A  /**%0A   * Constructs an instance for use by a single cache.%0A   *%0A   * @param registry the registry of metric instances%0A   * @param metricsPrefix the prefix name for the metrics%0A   */%0A  public CaffeineStatsCounter(Registry registry, String metricsPrefix) %7B%0A    hitCount = registry.counter(metricsPrefix + %22.hits%22);%0A    missCount = registry.counter(metricsPrefix + %22.misses%22);%0A    totalLoadTime = registry.timer(metricsPrefix + %22.loads%22);%0A    loadSuccessCount = registry.counter(metricsPrefix + %22.loads-success%22);%0A    loadFailureCount = registry.counter(metricsPrefix + %22.loads-failure%22);%0A    evictionCount = registry.counter(metricsPrefix + %22.evictions%22);%0A    evictionWeight = registry.counter(metricsPrefix + %22.evictions-weight%22);%0A  %7D%0A%0A  @Override%0A  public void recordHits(int count) %7B%0A    hitCount.increment(count);%0A  %7D%0A%0A  @Override%0A  public void recordMisses(int count) %7B%0A    missCount.increment(count);%0A  %7D%0A%0A  @Override%0A  public void recordLoadSuccess(long loadTime) %7B%0A    loadSuccessCount.increment();%0A    totalLoadTime.record(loadTime, TimeUnit.NANOSECONDS);%0A  %7D%0A%0A  @Override%0A  public void recordLoadFailure(long loadTime) %7B%0A    loadFailureCount.increment();%0A    totalLoadTime.record(loadTime, TimeUnit.NANOSECONDS);%0A  %7D%0A%0A  @Override%0A  @SuppressWarnings(%22deprecation%22)%0A  public void recordEviction() %7B%0A    recordEviction(1);%0A  %7D%0A%0A  @Override%0A  public void recordEviction(int weight) %7B%0A    evictionCount.increment();%0A    evictionWeight.increment(weight);%0A  %7D%0A%0A  @Override%0A  public CacheStats snapshot() %7B%0A    return new CacheStats(%0A        hitCount.count(),%0A        missCount.count(),%0A        loadSuccessCount.count(),%0A        loadFailureCount.count(),%0A        totalLoadTime.count(),%0A        evictionCount.count(),%0A        evictionWeight.count());%0A  %7D%0A%0A  @Override%0A  public String toString() %7B%0A    return snapshot().toString();%0A  %7D%0A%7D%0A

Add caffeine cache StatsCounter implementation using Spectator registry (#440)