chia7712 commented on code in PR #20021:
URL: https://github.com/apache/kafka/pull/20021#discussion_r2199017407


##########
metadata/src/main/java/org/apache/kafka/image/loader/metrics/MetadataLoaderMetrics.java:
##########
@@ -142,16 +176,85 @@ public long handleLoadSnapshotCount() {
         return this.handleLoadSnapshotCount.get();
     }
 
+    /**
+     * Remove the FinalizedLevel metric for features who are no longer part of 
the
+     * current features image.
+     * Note that metadata.version and kraft.version are not included in
+     * the features image, so they are not removed.
+     * @param newFinalizedLevels The new finalized feature levels from the 
features image
+     */
+    public void maybeRemoveFinalizedFeatureLevelMetrics(Map<String, Short> 
newFinalizedLevels) {
+        finalizedFeatureLevels.keySet().stream().filter(

Review Comment:
   Perhaps we could leverage `iterator` to avoid iterating through all items 
twice.
   ```java
           var iter = finalizedFeatureLevels.keySet().iterator();
           while (iter.hasNext()) {
               var featureName = iter.next();
               if (newFinalizedLevels.containsKey(featureName) ||
                   featureName.equals(MetadataVersion.FEATURE_NAME) ||
                   featureName.equals(KRaftVersion.FEATURE_NAME)) {
                   continue;
               }
               removeFinalizedFeatureLevelMetric(featureName);
               iter.remove();
           }
   ```



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to