frankvicky commented on code in PR #20021:
URL: https://github.com/apache/kafka/pull/20021#discussion_r2162910427
##########
metadata/src/test/java/org/apache/kafka/image/loader/metrics/MetadataLoaderMetricsTest.java:
##########
@@ -153,8 +161,43 @@ public void testSetValueOfCurrentControllerId() {
}
}
+ @Test
+ public void testFinalizedFeatureLevelMetrics() {
+ MetricsRegistry registry = new MetricsRegistry();
+ try {
+ try (FakeMetadataLoaderMetrics fakeMetrics = new
FakeMetadataLoaderMetrics(registry)) {
+ @SuppressWarnings("unchecked")
+ Gauge<Short> finalizedMetadataVersion = (Gauge<Short>) registry
+ .allMetrics()
+ .get(metricName("MetadataLoader", "FinalizedLevel",
"featureName=metadataVersion"));
+ @SuppressWarnings("unchecked")
+ Gauge<Short> finalizedKRaftVersion = (Gauge<Short>) registry
+ .allMetrics()
+ .get(metricName("MetadataLoader", "FinalizedLevel",
"featureName=kraftVersion"));
+
+ assertEquals(MINIMUM_VERSION.featureLevel(),
finalizedMetadataVersion.value());
+ assertEquals((short) 0, finalizedKRaftVersion.value());
+
+
fakeMetrics.metrics.setFinalizedFeatureLevel(MetadataVersion.FEATURE_NAME,
MetadataVersion.LATEST_PRODUCTION.featureLevel());
+ assertEquals(MetadataVersion.LATEST_PRODUCTION.featureLevel(),
finalizedMetadataVersion.value());
+
+
fakeMetrics.metrics.setFinalizedFeatureLevel(KRaftVersion.FEATURE_NAME,
KRaftVersion.LATEST_PRODUCTION.featureLevel());
+ assertEquals(KRaftVersion.LATEST_PRODUCTION.featureLevel(),
finalizedKRaftVersion.value());
+ }
+ ControllerMetricsTestUtils.assertMetricsForTypeEqual(registry,
"kafka.server",
+ Set.of());
+ } finally {
+ registry.shutdown();
+ }
+ }
+
private static MetricName metricName(String type, String name) {
String mBeanName = String.format("kafka.server:type=%s,name=%s", type,
name);
return new MetricName("kafka.server", type, name, null, mBeanName);
}
+
+ private static MetricName metricName(String type, String name, String
scope) {
+ String mBeanName = String.format("kafka.server:type=%s,name=%s,%s",
type, name, scope);
+ return new MetricName("kafka.server", type, name, scope, mBeanName);
+ }
Review Comment:
Could we combine these two similar methods?
For example:
```java
private static MetricName metricName(String type, String... nameParts) {
if (nameParts.length == 0) {
throw new IllegalArgumentException("At least one name part is
required");
}
String name = nameParts[0];
String scope = nameParts.length > 1 ? String.join(",",
Arrays.copyOfRange(nameParts, 1, nameParts.length)) : null;
String mBeanName = scope == null
? String.format("kafka.server:type=%s,name=%s", type, name)
: String.format("kafka.server:type=%s,name=%s,%s", type, name,
scope);
return new MetricName("kafka.server", type, name, scope, mBeanName);
}
```
--
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]