@@ -464,7 +464,7 @@ public static <K, V> Cache<K, V> registerAndGetCache(
464464 CacheBuilder <Object , Object > guavaCacheBuilder ,
465465 CacheLoader <? super K , V > loader ,
466466 Map <String , String > tags ) {
467- reportCacheMaxSize (cacheName , guavaCacheBuilder );
467+ reportCacheMaxSize (cacheName , guavaCacheBuilder , tags );
468468 Cache <K , V > guavaCache = guavaCacheBuilder .build (loader );
469469 GuavaCacheMetrics .monitor (meterRegistry , guavaCache , cacheName , toIterable (tags ));
470470 return guavaCache ;
@@ -476,19 +476,21 @@ public static <K, V> Cache<K, V> registerAndGetCache(
476476 */
477477 public static <K , V > Cache <K , V > registerAndGetCache (
478478 String cacheName , CacheBuilder <Object , Object > guavaCacheBuilder , Map <String , String > tags ) {
479- reportCacheMaxSize (cacheName , guavaCacheBuilder );
479+ reportCacheMaxSize (cacheName , guavaCacheBuilder , tags );
480480 Cache <K , V > guavaCache = guavaCacheBuilder .build ();
481481 GuavaCacheMetrics .monitor (meterRegistry , guavaCache , cacheName , toIterable (tags ));
482482 return guavaCache ;
483483 }
484484
485485 private static <K , V > void reportCacheMaxSize (
486- String cacheName , CacheBuilder <K , V > guavaCacheBuilder ) {
486+ String cacheName , CacheBuilder <K , V > guavaCacheBuilder , Map < String , String > tags ) {
487487 try {
488488 Field maximumSizeField = guavaCacheBuilder .getClass ().getDeclaredField ("maximumSize" );
489489 maximumSizeField .setAccessible (true );
490490 long maximumSize = maximumSizeField .getLong (guavaCacheBuilder );
491- registerGauge (CACHE_MAX_SIZE_GAUGE , Map .of ("cache" , cacheName ), maximumSize );
491+ Map <String , String > tagsCopy = new HashMap <>(tags );
492+ tagsCopy .put ("cache" , cacheName );
493+ registerGauge (CACHE_MAX_SIZE_GAUGE , tagsCopy , maximumSize );
492494 } catch (NoSuchFieldException | IllegalAccessException e ) {
493495 // ignore
494496 }
0 commit comments