Skip to content

Add cache metrics support for LocalResponseCache#4086

Open
LivingLikeKrillin wants to merge 6 commits into
spring-cloud:mainfrom
LivingLikeKrillin:feature/local-response-cache-metrics
Open

Add cache metrics support for LocalResponseCache#4086
LivingLikeKrillin wants to merge 6 commits into
spring-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

@LivingLikeKrillin
Copy link
Copy Markdown
Author

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

See spring-cloudgh-3722

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

See spring-cloudgh-3722

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

Signed-off-by: Jooyoung Jung <143606756+LivingLikeKrillin@users.noreply.github.com>
- Remove unused constructor overload in
  LocalResponseCacheGatewayFilterFactory
- Tighten recordStats() comment
- Align bean method visibility with existing conventions

Signed-off-by: Jooyoung Jung <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: Jooyoung Jung <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: Jooyoung Jung <143606756+LivingLikeKrillin@users.noreply.github.com>
@LivingLikeKrillin LivingLikeKrillin force-pushed the feature/local-response-cache-metrics branch from de87050 to 4cbb13d Compare May 8, 2026 16:47
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