mlbiscoc commented on code in PR #3671:
URL: https://github.com/apache/solr/pull/3671#discussion_r2372904521


##########
solr/core/src/java/org/apache/solr/search/CaffeineCache.java:
##########
@@ -471,47 +477,90 @@ public SolrMetricsContext getSolrMetricsContext() {
 
   @Override
   public String toString() {
-    return name() + (cacheMap != null ? cacheMap.getValue().toString() : "");
+    return name();
   }
 
-  // TODO SOLR-17458: Migrate to Otel
   @Override
   public void initializeMetrics(
       SolrMetricsContext parentContext, Attributes attributes, String scope) {
+    Attributes cacheAttributes =
+        attributes.toBuilder().put(CATEGORY_ATTR, 
getCategory().toString()).build();
     solrMetricsContext = parentContext.getChildContext(this);
-    cacheMap =
-        new MetricsMap(
-            map -> {
+
+    ObservableLongMeasurement cacheOperation =
+        solrMetricsContext.longCounterMeasurement(
+            "solr_searcher_cache_ops",
+            "Number of cache operations (hits, lookups, inserts and 
evictions)");
+
+    ObservableLongMeasurement hitRatioMetric =
+        
solrMetricsContext.longGaugeMeasurement("solr_searcher_cache_hit_ratio", "Cache 
hit ratio");
+
+    ObservableLongMeasurement sizeMetric =
+        solrMetricsContext.longGaugeMeasurement(
+            "solr_searcher_cache_size", "Current number cache entries");
+
+    ObservableLongMeasurement ramBytesUsedMetric =
+        solrMetricsContext.longGaugeMeasurement(
+            "solr_searcher_cache_ram_used", "RAM bytes used by cache", 
OtelUnit.BYTES);
+
+    ObservableLongMeasurement warmupTimeMetric =
+        solrMetricsContext.longGaugeMeasurement(
+            "solr_searcher_cache_warmup_time", "Cache warmup time", 
OtelUnit.MILLISECONDS);
+
+    ObservableLongMeasurement cumulativeCacheOperation =
+        solrMetricsContext.longGaugeMeasurement(
+            "solr_cache_cumulative_ops",
+            "Number of cumulative cache operations (hits, lookups, inserts and 
evictions)");
+
+    this.toClose =
+        solrMetricsContext.batchCallback(
+            () -> {
               if (cache != null) {
                 CacheStats stats = cache.stats();
                 long hitCount = stats.hitCount() + hits.sum();
                 long insertCount = inserts.sum();
                 long lookupCount = stats.requestCount() + lookups.sum();
 
-                map.put(LOOKUPS_PARAM, lookupCount);
-                map.put(HITS_PARAM, hitCount);
-                map.put(HIT_RATIO_PARAM, hitRate(hitCount, lookupCount));
-                map.put(INSERTS_PARAM, insertCount);
-                map.put(EVICTIONS_PARAM, stats.evictionCount());
-                map.put(SIZE_PARAM, cache.asMap().size());
-                map.put("warmupTime", warmupTime);
-                map.put(RAM_BYTES_USED_PARAM, ramBytesUsed());
-                map.put(MAX_RAM_MB_PARAM, getMaxRamMB());
+                cacheOperation.record(
+                    hitCount, cacheAttributes.toBuilder().put(OPERATION_ATTR, 
"hits").build());

Review Comment:
   The more I thought about it, I think you're right here. No point in a total 
metric as its redundant. Just sum `hit/miss`. Miss is `total - hits` anyways 
and the aggregation is simple. So I removed it. Only hit/miss now.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to