Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log a warning when instrumenting a cache that is not recording stats in CaffeineCacheMetrics #5402

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.micrometer.common.lang.NonNullApi;
import io.micrometer.common.lang.NonNullFields;
import io.micrometer.common.lang.Nullable;
import io.micrometer.common.util.internal.logging.InternalLogger;
import io.micrometer.common.util.internal.logging.InternalLoggerFactory;
import io.micrometer.core.instrument.*;

import java.util.concurrent.TimeUnit;
Expand All @@ -48,6 +50,8 @@ public class CaffeineCacheMetrics<K, V, C extends Cache<K, V>> extends CacheMete

private static final String DESCRIPTION_CACHE_LOAD = "The number of times cache lookup methods have successfully loaded a new value or failed to load a new value, either because no value was found or an exception was thrown while loading";

private static final InternalLogger log = InternalLoggerFactory.getInstance(CaffeineCacheMetrics.class);

/**
* Creates a new {@link CaffeineCacheMetrics} instance.
* @param cache The cache to be instrumented. You must call
Expand All @@ -58,6 +62,12 @@ public class CaffeineCacheMetrics<K, V, C extends Cache<K, V>> extends CacheMete
*/
public CaffeineCacheMetrics(C cache, String cacheName, Iterable<Tag> tags) {
super(cache, cacheName, tags);

if (!cache.policy().isRecordingStats()) {
log.warn(
"The cache '{}' is not recording statistics, so their values will be zero. Call 'Caffeine#recordStats()' prior to building the cache for metrics to be recorded.",
cacheName);
}
}

/**
Expand Down