DL1231 commented on code in PR #20021:
URL: https://github.com/apache/kafka/pull/20021#discussion_r2163133666
##########
metadata/src/main/java/org/apache/kafka/image/loader/metrics/MetadataLoaderMetrics.java:
##########
@@ -142,16 +185,44 @@ public long handleLoadSnapshotCount() {
return this.handleLoadSnapshotCount.get();
}
+ public void setFinalizedFeatureLevel(String featureName, short
featureLevel) {
+ finalizedFeatureLevels.put(featureName, featureLevel);
+ }
+
+ public short finalizedFeatureLevel(String featureName) {
+ return finalizedFeatureLevels.getOrDefault(featureName, (short) 0);
+ }
+
@Override
public void close() {
registry.ifPresent(r -> List.of(
CURRENT_METADATA_VERSION,
CURRENT_CONTROLLER_ID,
HANDLE_LOAD_SNAPSHOT_COUNT
).forEach(r::removeMetric));
+ for (var featureName : finalizedFeatureLevels.keySet()) {
+ removeFinalizedFeatureLevelMetric(featureName);
+ }
}
private static MetricName getMetricName(String type, String name) {
return KafkaYammerMetrics.getMetricName("kafka.server", type, name);
}
+
+ private static MetricName getFeatureNameTagMetricName(String type, String
name, String featureName) {
+ LinkedHashMap<String, String> featureNameTag = new LinkedHashMap<>();
+ featureNameTag.put(FEATURE_NAME_TAG, sanitizeFeatureName(featureName));
+ return KafkaYammerMetrics.getMetricName("kafka.server", type, name,
featureNameTag);
+ }
+
+ private static String sanitizeFeatureName(String featureName) {
+ final var words = featureName.split("\\.");
+ final var builder = new StringBuilder(words[0]);
+ for (int i = 1; i < words.length; i++) {
+ final var word = words[i];
+ builder.append(word.substring(0, 1).toUpperCase(Locale.ROOT))
+ .append(word.substring(1).toLowerCase(Locale.ROOT));
Review Comment:
Could we use `charAt(0)` to directly get the first character? This avoids
creating temporary strings by `substring`.
```suggestion
builder.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1).toLowerCase(Locale.ROOT));
```
--
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]