You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "snicholasbarton (via GitHub)" <gi...@apache.org> on 2026/08/26 17:56:26 UTC
[PR] feat(metrics): instrument the entity cache with Micrometer [polaris]
snicholasbarton opened a new pull request, #5388:
URL: https://github.com/apache/polaris/pull/5388
Report InMemoryEntityCache statistics so that the [cache weighter option available in configuration](https://github.com/apache/polaris/blob/7866ce5c009d64e4c1454b47bca3df9873c6c0b2/polaris-core/src/main/java/org/apache/polaris/core/config/FeatureConfiguration.java#L494) can be tuned according to observed usage. Right now there isn't a good way to view this information since these caches are uninstrumented.
There were a a couple of interesting wrinkles here:
- I tried to keep the implementation as close to the [NoSQL version](https://github.com/apache/polaris/blob/7866ce5c009d64e4c1454b47bca3df9873c6c0b2/persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/cache/CaffeineCacheBackend.java) as I could (the additional meters, the cache weighter as a local field, etc.)
- Tagging the cache stats with the realm ID would have meant Prometheus silently dropped them, requiring the StatsCounter that delegates to the CaffeineCacheStats while also tracking the realm ID.
- Had to extend the EntityCache interface with closing logic so that we don't continue to register metrics for purged realms.
- Tracking hits across the byId and byName lookups needed some extra handling, thus the additional byName counters. I figure that the unified hit rate can be calculated via PromQL.
I'm not terribly attached to the implementation of the work to get per-realm hit rates - in our deployments we only use a single realm, so this is a bit of a non-issue - so I'm open to reworking these parts if others have strong opinions.
## Checklist
- [x] ๐ก๏ธ Don't disclose security issues! (contact security@apache.org)
- [x] ๐ Clearly explained why the changes are needed, or linked related issues: Fixes #
- [x] ๐งช Added/updated tests with good coverage, or manually tested (and explained how)
- [x] ๐ก Added comments for complex logic
- [ ] ๐งพ Updated `CHANGELOG.md` (if needed)
- [ ] ๐ Updated documentation in `site/content/in-dev/unreleased` (if needed)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the entity cache with Micrometer [polaris]
Posted by "snicholasbarton (via GitHub)" <gi...@apache.org>.
snicholasbarton commented on PR #5388:
URL: https://github.com/apache/polaris/pull/5388#issuecomment-5429065850
Does this need a CHANGELOG entry?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "snicholasbarton (via GitHub)" <gi...@apache.org>.
snicholasbarton commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r4027715095
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java:
##########
@@ -29,6 +29,13 @@
/** Interface for a Polaris entity cache */
public interface EntityCache {
Review Comment:
Yeah, probably worth it. Added!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #5388: feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups
URL: https://github.com/apache/polaris/pull/5388
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r4029381357
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java:
##########
@@ -102,13 +186,159 @@ public InMemoryEntityCache(
byIdBuilder.softValues();
}
+ // Caffeine's own statistics are reported without the extra tags: 'cache.gets' and friends are
+ // shared with the other Caffeine caches of this service, which report them tagged with 'cache'
+ // only, and a registry requires the same tag keys for a given meter name. Those meters are
+ // therefore aggregated over all realms, and the hit ratio of a single realm is recovered from
+ // the by-id counters registered alongside them.
+ Optional<StatsCounter> statsCounter = meterRegistry.map(reg -> statsCounter(reg, extraTags));
+ statsCounter.ifPresent(counter -> byIdBuilder.recordStats(() -> counter));
+
// use a Caffeine cache to purge entries when those have not been used for a long time.
this.byId = byIdBuilder.build();
+ var eviction = byId.policy().eviction().orElseThrow();
+ this.weightSupplier = () -> eviction.weightedSize().orElse(0L);
+
+ this.byNameHits = byNameLookupCounter(extraTags, "hit");
Review Comment:
Should we wait for #5396 , which makes "by name" call paths use a proper `Cache`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "snicholasbarton (via GitHub)" <gi...@apache.org>.
snicholasbarton commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r3873942160
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java:
##########
@@ -239,7 +441,13 @@ private boolean entityNameKeyMismatch(
*/
public @Nullable ResolvedPolarisEntity getEntityByName(
@NonNull EntityCacheByNameKey entityNameKey) {
- return byName.get(entityNameKey);
+ ResolvedPolarisEntity entry = byName.get(entityNameKey);
+ if (entry != null) {
+ byNameHits.ifPresent(Counter::increment);
Review Comment:
Yep, good call out, missed that one. Will amend `getRefreshIfNeeded` to use `byName.get` to elide the metrics collection.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r3927956839
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java:
##########
@@ -29,6 +29,13 @@
/** Interface for a Polaris entity cache */
public interface EntityCache {
Review Comment:
Should this interface extend `AutoCloseable`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "vigneshio (via GitHub)" <gi...@apache.org>.
vigneshio commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r3870845647
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java:
##########
@@ -239,7 +441,13 @@ private boolean entityNameKeyMismatch(
*/
public @Nullable ResolvedPolarisEntity getEntityByName(
@NonNull EntityCacheByNameKey entityNameKey) {
- return byName.get(entityNameKey);
+ ResolvedPolarisEntity entry = byName.get(entityNameKey);
+ if (entry != null) {
+ byNameHits.ifPresent(Counter::increment);
Review Comment:
`getAndRefreshIfNeeded` also calls this, and that path is invalidation bookkeeping (stale name key), not a caller by-name lookup. same idea as the `asMap().get()` change in `cacheNewEntry`. consider `byName.get(nameKey)` there so refresh doesn't land on these counters.
not every resolve - resolver only hits `getAndRefreshIfNeeded` when change-tracking says the entity is stale. WDYT? ..
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java:
##########
@@ -57,21 +69,64 @@
public class InMemoryEntityCache implements EntityCache {
private static final Logger LOGGER = LoggerFactory.getLogger(InMemoryEntityCache.class);
public static final int MAX_CACHE_REFRESH_ATTEMPTS = 100;
+
+ // These meters are registered per cache instance and hence carry the per-instance tags, for
+ // example the realm. Their names must stay specific to the entity cache: registering a name that
+ // another cache already registered with a different set of tag keys does not fail loudly, the
+ // Prometheus registry simply omits the conflicting series from the scrape.
+ public static final String METER_CACHE_CAPACITY = "polaris.entity-cache.capacity";
Review Comment:
Add these names to `telemetry.md` (`polaris.entity-cache.*` per realm, `cache.gets` aggregated). that's what operators will scrape to tune `ENTITY_CACHE_WEIGHER_TARGET`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "nicholasbarton-nominal (via GitHub)" <gi...@apache.org>.
nicholasbarton-nominal commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r3873931812
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java:
##########
@@ -239,7 +441,13 @@ private boolean entityNameKeyMismatch(
*/
public @Nullable ResolvedPolarisEntity getEntityByName(
@NonNull EntityCacheByNameKey entityNameKey) {
- return byName.get(entityNameKey);
+ ResolvedPolarisEntity entry = byName.get(entityNameKey);
+ if (entry != null) {
+ byNameHits.ifPresent(Counter::increment);
Review Comment:
yep, missed this one. good call out, will amend the byName lookup in getRefreshIfNeeded to not record the hit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #5388:
URL: https://github.com/apache/polaris/pull/5388#issuecomment-5702332957
Please convert all commits to personal commits (no Claude co-authors): https://polaris.apache.org/community/contributing-guidelines/#guidelines-for-ai-assisted-contributions
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b commented on PR #5388:
URL: https://github.com/apache/polaris/pull/5388#issuecomment-5702418946
`Tagging the cache stats with the realm ID ...` currently `InMemoryEntityCache` has a separate instance in each realm. This effectively defeats cache weight limits in servers that support many / unrestricted number of realms (the heap is shared).
I believe we should have a shared cache for all realms (realm ID being a part of the cache key, of course) and also store entities in JSON form, allowing exact size computation.
... this is for later, of course :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "snicholasbarton (via GitHub)" <gi...@apache.org>.
snicholasbarton commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r3873942160
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java:
##########
@@ -239,7 +441,13 @@ private boolean entityNameKeyMismatch(
*/
public @Nullable ResolvedPolarisEntity getEntityByName(
@NonNull EntityCacheByNameKey entityNameKey) {
- return byName.get(entityNameKey);
+ ResolvedPolarisEntity entry = byName.get(entityNameKey);
+ if (entry != null) {
+ byNameHits.ifPresent(Counter::increment);
Review Comment:
Yep, good call out, missed that one. Will amend `getRefreshIfNeeded` to use `byName.get` to elide the metrics collection. Will also add a test to pin that behaviour
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "vigneshio (via GitHub)" <gi...@apache.org>.
vigneshio commented on PR #5388:
URL: https://github.com/apache/polaris/pull/5388#issuecomment-5437640607
> Does this need a CHANGELOG entry?
yes - New Features under `## [Unreleased]`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "nicholasbarton-nominal (via GitHub)" <gi...@apache.org>.
nicholasbarton-nominal commented on code in PR #5388:
URL: https://github.com/apache/polaris/pull/5388#discussion_r3873931812
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java:
##########
@@ -239,7 +441,13 @@ private boolean entityNameKeyMismatch(
*/
public @Nullable ResolvedPolarisEntity getEntityByName(
@NonNull EntityCacheByNameKey entityNameKey) {
- return byName.get(entityNameKey);
+ ResolvedPolarisEntity entry = byName.get(entityNameKey);
+ if (entry != null) {
+ byNameHits.ifPresent(Counter::increment);
Review Comment:
yep, missed this one. good call out, will amend the byName lookup in getRefreshIfNeeded to not record the hit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "snicholasbarton (via GitHub)" <gi...@apache.org>.
snicholasbarton commented on PR #5388:
URL: https://github.com/apache/polaris/pull/5388#issuecomment-5442483296
Thanks @vigneshio for the review, I think it's ready for another pass. Let me know if there's anything else you think is worth addressing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(metrics): instrument the InMemoryEntityCache for JDBC persistence setups [polaris]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #5388:
URL: https://github.com/apache/polaris/pull/5388#issuecomment-6228046454
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@polaris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org