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


##########
server/src/main/java/org/apache/kafka/server/metrics/NodeMetrics.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.server.metrics;
+
+import org.apache.kafka.common.MetricName;
+import org.apache.kafka.common.metrics.Metrics;
+import org.apache.kafka.controller.QuorumFeatures;
+import org.apache.kafka.metadata.VersionRange;
+import org.apache.kafka.server.common.Feature;
+import org.apache.kafka.server.common.MetadataVersion;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public final class NodeMetrics implements AutoCloseable {
+    private static final String METRIC_GROUP_NAME = "node-metrics";
+    private static final String FEATURE_NAME_TAG = "feature-name";
+    private static final String MAXIMUM_SUPPORTED_LEVEL_NAME = 
"maximum-supported-level";
+    private static final String MINIMUM_SUPPORTED_LEVEL_NAME = 
"minimum-supported-level";
+
+    private final Metrics metrics;
+    private final Map<String, VersionRange> supportedFeatureRanges;
+
+    public NodeMetrics(Metrics metrics, boolean enableUnstableVersions) {
+        this.metrics = metrics;
+        this.supportedFeatureRanges = 
QuorumFeatures.defaultSupportedFeatureMap(enableUnstableVersions);
+        for (var featureName : Feature.PRODUCTION_FEATURE_NAMES) {
+            addSupportedLevelMetric(MAXIMUM_SUPPORTED_LEVEL_NAME, featureName);
+            addSupportedLevelMetric(MINIMUM_SUPPORTED_LEVEL_NAME, featureName);
+        }
+        addSupportedLevelMetric(
+            MAXIMUM_SUPPORTED_LEVEL_NAME,
+            MetadataVersion.FEATURE_NAME
+        );
+        addSupportedLevelMetric(
+            MINIMUM_SUPPORTED_LEVEL_NAME,
+            MetadataVersion.FEATURE_NAME
+        );

Review Comment:
   Should we use `supportedFeatureRanges` instead of setting metrics 
separately? I noticed that the close method uses 
`supportedFeatureRanges.keySet()` to remove metrics.
   ```suggestion
           supportedFeatureRanges.forEach((featureName, versionRange) -> {
               addSupportedLevelMetric(MAXIMUM_SUPPORTED_LEVEL_NAME, 
featureName);
               addSupportedLevelMetric(MINIMUM_SUPPORTED_LEVEL_NAME, 
featureName);
           });
   ```



-- 
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