kevin-wu24 commented on code in PR #20021: URL: https://github.com/apache/kafka/pull/20021#discussion_r2167663705
########## server/src/main/java/org/apache/kafka/server/metrics/NodeMetrics.java: ########## @@ -0,0 +1,89 @@ +/* + * 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 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); + supportedFeatureRanges.forEach((featureName, versionRange) -> { + addSupportedLevelMetric(MAXIMUM_SUPPORTED_LEVEL_NAME, featureName); + addSupportedLevelMetric(MINIMUM_SUPPORTED_LEVEL_NAME, featureName); + }); + } + + private void addSupportedLevelMetric(String metricName, String featureName) { + metrics.addMetric( + getFeatureNameTagMetricName( + metricName, + METRIC_GROUP_NAME, + featureName + ), + (config, now) -> { Review Comment: I remember bringing this issue up when working on the `KafkaRaftMetrics` a while back: https://github.com/apache/kafka/pull/18304#discussion_r1935864197. Yes, it will upcast to a double. I guess the actual values we want are `short` right? Since feature levels themselves are `shorts`. I'll update the KIP with that so it's consistent. -- 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