squah-confluent commented on code in PR #21043:
URL: https://github.com/apache/kafka/pull/21043#discussion_r2580626617
##########
coordinator-common/src/test/java/org/apache/kafka/coordinator/common/runtime/CoordinatorRuntimeMetricsImplTest.java:
##########
@@ -99,6 +110,62 @@ public void testMetricNames() {
));
}
+ @Test
+ public void testMetricsGroupIsolation() {
+ Metrics metrics = spy(new Metrics());
+
+ // Create first CoordinatorRuntimeMetricsImpl instance and capture
sensor and metric names.
+ Set<String> sensorNames;
+ Set<MetricName> metricNames;
+ try (CoordinatorRuntimeMetricsImpl runtimeMetrics = new
CoordinatorRuntimeMetricsImpl(metrics, METRICS_GROUP)) {
+ runtimeMetrics.registerEventQueueSizeGauge(() -> 0);
+
+ ArgumentCaptor<String> sensorCaptor =
ArgumentCaptor.forClass(String.class);
+ verify(metrics, atLeastOnce()).sensor(sensorCaptor.capture());
+ sensorNames = new HashSet<>(sensorCaptor.getAllValues());
+
+ ArgumentCaptor<MetricName> metricNameCaptor =
ArgumentCaptor.forClass(MetricName.class);
+ verify(metrics,
atLeastOnce()).addMetric(metricNameCaptor.capture(),
any(MetricValueProvider.class));
+ metricNames = new HashSet<>(metricNameCaptor.getAllValues());
+
+ // Check that all gauges were registered.
+ expectedMetricNames(metrics).forEach(metricName ->
assertTrue(metrics.metrics().containsKey(metricName)));
+ }
+
+ clearInvocations(metrics);
+
+ // Create second CoordinatorRuntimeMetricsImpl instance and capture
sensor and metric names.
+ Set<String> otherSensorNames;
+ Set<MetricName> otherMetricNames;
+ try (CoordinatorRuntimeMetricsImpl otherRuntimeMetrics = new
CoordinatorRuntimeMetricsImpl(metrics, OTHER_METRICS_GROUP)) {
+ otherRuntimeMetrics.registerEventQueueSizeGauge(() -> 0);
+
+ ArgumentCaptor<String> sensorCaptor =
ArgumentCaptor.forClass(String.class);
+ verify(metrics, atLeastOnce()).sensor(sensorCaptor.capture());
+ otherSensorNames = new HashSet<>(sensorCaptor.getAllValues());
+
+ ArgumentCaptor<MetricName> metricNameCaptor =
ArgumentCaptor.forClass(MetricName.class);
+ verify(metrics,
atLeastOnce()).addMetric(metricNameCaptor.capture(),
any(MetricValueProvider.class));
+ otherMetricNames = new HashSet<>(metricNameCaptor.getAllValues());
+
+ // Check that all gauges were registered.
+ assertEquals(sensorNames.size(), otherSensorNames.size());
+ assertEquals(metricNames.size(), otherMetricNames.size());
Review Comment:
We can't use `expectedMetricNames` here because it's tied to the
`METRICS_GROUP` metrics group.
--
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]