Skip to content

Add cache metrics support for LocalResponseCache#4086

Open
LivingLikeKrillin wants to merge 7 commits intospring-cloud:mainfrom
LivingLikeKrillin:feature/local-response-cache-metrics
Open

Add cache metrics support for LocalResponseCache#4086
LivingLikeKrillin wants to merge 7 commits intospring-cloud:mainfrom
LivingLikeKrillin:feature/local-response-cache-metrics

Conversation

@LivingLikeKrillin
Copy link
Copy Markdown

Summary

  • Enable Caffeine recordStats() so cache statistics are collected at runtime
  • Introduce CacheMetricsListener callback in LocalResponseCacheGatewayFilterFactory to notify external components when caches are created
  • Add LocalResponseCacheMetricsAutoConfiguration that binds Caffeine caches to MeterRegistry via CaffeineCacheMetrics, exposing standard cache metrics (cache.gets, cache.puts, cache.evictions, cache.size) through Actuator

Fixes gh-3722

Test plan

  • Verify CacheMetricsListener bean is created when MeterRegistry is present
  • Verify no bean is created when MeterRegistry is absent
  • Verify no bean is created when gateway.metrics.enabled=false
  • Verify Caffeine recordStats() collects hit/miss counts
  • Verify cache metrics are bound to MeterRegistry via listener callback

See spring-cloudgh-3722

Signed-off-by: LivingLikeKrillin <143606756+LivingLikeKrillin@users.noreply.github.com>
…actory

See spring-cloudgh-3722

Signed-off-by: LivingLikeKrillin <143606756+LivingLikeKrillin@users.noreply.github.com>
Fixes spring-cloudgh-3722

Signed-off-by: LivingLikeKrillin <143606756+LivingLikeKrillin@users.noreply.github.com>
@LivingLikeKrillin LivingLikeKrillin force-pushed the feature/local-response-cache-metrics branch from d2db7c3 to 2edc354 Compare March 9, 2026 09:32
@LivingLikeKrillin
Copy link
Copy Markdown
Author

The two test failures (GatewayAutoConfigurationTests and FormIntegrationTests) are pre-existing on main and unrelated to this change.

- Add WARN log when global cache is not CaffeineCache (only when
  a real metrics listener is present)
- Add explanatory comment for always-on recordStats() decision
- Remove unused constructor overload in
  LocalResponseCacheGatewayFilterFactory
- Add FQN disambiguation comment in CacheMetricsListener
- Align bean method visibility with existing conventions

Signed-off-by: LivingLikeKrillin <143606756+LivingLikeKrillin@users.noreply.github.com>
Verify that CaffeineCacheMetrics are registered for the global
response-cache when both MeterRegistry and global filter are enabled.

Signed-off-by: LivingLikeKrillin <143606756+LivingLikeKrillin@users.noreply.github.com>
- Reorder class-level annotations to match GatewayMetricsAutoConfiguration
- Add DispatcherHandler to @ConditionalOnClass for WebFlux environment guard
- Move @ConditionalOnBean and metrics property check to bean method level
- Make test class public to match existing test conventions
- Add test for gateway disabled scenario
- Add per-route cache metrics integration test

See spring-cloudgh-3722

Signed-off-by: LivingLikeKrillin <143606756+LivingLikeKrillin@users.noreply.github.com>
@LivingLikeKrillin LivingLikeKrillin force-pushed the feature/local-response-cache-metrics branch from d53454c to de87050 Compare March 25, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cache metrics for LocalResponseCache

2 participants