-
Notifications
You must be signed in to change notification settings - Fork 10
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
Initial Caffeine CacheStats recorder #1897
Conversation
Generate changelog in
|
2eb59bc
to
61e72e5
Compare
public static CacheStats of(CacheMetrics metrics, String name) { | ||
return new CacheStats(metrics, name); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if we made CacheMetrics
private -- metric-schema doesn't make any guarantees around backward compatibility of generated code because it's expected to be consumed by the project which declares the metrics.
I suppose we may want to reuse the same metrics for guava and caffeine caches. If that's the case, I might recommend a new jar module with internal
in the name, like tritium-cache-internal
, where metrics may be defined and generated as public classes. The tritium-cache-internal
module can be used as an implementation
dep into the tritium modules which instrument specific cache implementations, so that the classes aren't directly visible to consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I can move the metric-schema definition and make package private.
Generally I'd like to deprecate all uses of Guava caches and migrate any remaining to Caffeine, so not sure its worth adding similar for Guava caches. We already have BanGuavaCaches
in baseline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
* @return Caffeine stats instance to register via | ||
* {@link com.github.benmanes.caffeine.cache.Caffeine#recordStats(Supplier)}. | ||
*/ | ||
public static CacheStats of(TaggedMetricRegistry taggedMetricRegistry, String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well sprinkle safety annotations:
public static CacheStats of(TaggedMetricRegistry taggedMetricRegistry, String name) { | |
public static CacheStats of(TaggedMetricRegistry taggedMetricRegistry, @Safe String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
hit.count: | ||
type: counter | ||
tags: [cache] | ||
docs: Count of cache hits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this in the previous round of review, I think all the counters should be updated to type: meter
. Counter is interpreted as a gauge in most backends because it doesn't guarantee monotonic increasing values, where our Meter, confusingly, uses the Prometheus Counter type for slightly easier indexing.
We may want to remove the .count
name suffixes as well (otherwise we'll end up with queries for cache_hit_count_count
), since those are described by both the counter
and meter
metric types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'm trying to keep metric name compatibility with the existing metrics produced by com.palantir.tritium.metrics.caffeine.CaffeineCacheStats#registerCache(com.palantir.tritium.metrics.registry.TaggedMetricRegistry, com.github.benmanes.caffeine.cache.Cache<?,?>, java.lang.String)
for now as I'm not sure how complex the migration will be across the fleet.
load.success.count: | ||
type: counter | ||
tags: [cache] | ||
docs: Count of successful cache loads | ||
load.failure.count: | ||
type: counter | ||
tags: [cache] | ||
docs: Count of failed cache loads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud here, entirely up to you either way:
We could declare a single metric along these lines, using a tag to distinguish success and failure:
load:
type: meter
tags:
- name: cache
- name: result
values: [success, failure]
Sometimes this makes it easier to track total interactions
@Override | ||
public void recordLoadFailure(@NonNegative long loadTime) { | ||
loadFailureMeter.mark(); | ||
totalLoadNanos.add(loadTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we could make the meter into a timer, which also provides a “count” value in addition to percentiles, more timeseries though
Invalidated by push of 1bcf527
Released 0.83.0 |
Before this PR
Begin to address #1895
Supersedes #1075
After this PR
==COMMIT_MSG==
Initial Caffeine CacheStats recorder
Example usage:
==COMMIT_MSG==
Possible downsides?