You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "gensericghiro (via GitHub)" <gi...@apache.org> on 2025/11/13 21:47:48 UTC

[PR] KAFKA-19882 Cleaning client level metric tags [kafka]

gensericghiro opened a new pull request, #20883:
URL: https://github.com/apache/kafka/pull/20883

   ## Summary
   When working on [KIP-1091](https://cwiki.apache.org/confluence/display/KAFKA/KIP-1091%3A+Improved+Kafka+Streams+operator+metrics), we mistakenly applied the `process-id` tag to all client-level metrics, rather than just the `client-state`, `thread-state`, and `recording-level` metrics as specified in the KIP. This issue came to light while working on KIP-1221, which aimed to add the `application-id` as a tag to the `client-state` metric introduced by KIP-1091. This PR removes these tags from all metrics by default, and adds them to only the `client-state` (application-id + process-id) and the `recording-level` (process-id only)
   
   ## Tests
   Unit tests in `ClientMetricsTest.java` and `StreamsMetricsImplTest.java`
   


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529197970


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
+    }
+
+    @Test
+    public void shouldAddClientLevelImmutableMetricWithAdditionalTags() {
+        final RecordingLevel recordingLevel = RecordingLevel.INFO;
+        final String value = "immutable-value";
+
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            Collections.singletonMap("additional-tag", "additional-value"),
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID),
+                mkEntry("additional-tag", "additional-value")
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
     }
 
     @Test
     public void shouldAddClientLevelMutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
-        final Gauge<String> valueProvider = (config, now) -> "mutable-value";
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(valueProvider));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
+        final String value = "mutable-value";
 
-        streamsMetrics.addClientLevelMutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, valueProvider);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelMutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            (c, t) -> value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Let's change the other code, too. It's a little weird to not check the name (or is there some non-deterministic naming, like a "thread name" which could mess with us?)



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529164752


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -254,7 +253,7 @@ public void shouldGetNewThreadLevelSensor() {
         final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
         setupGetNewSensorTest(metrics);
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
+        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID,

Review Comment:
   nit: formatting. Let's move `time` parameter into this line, too, for some cleanup (same below)



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "gensericghiro (via GitHub)" <gi...@apache.org>.
gensericghiro commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529176583


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Agreed, but I was being consistent with what's [here](https://github.com/apache/kafka/blob/b58aae288fb794b01fd2fc6a29748eba1d277bd6/streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java#L1354). I can change both



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
+    }
+
+    @Test
+    public void shouldAddClientLevelImmutableMetricWithAdditionalTags() {
+        final RecordingLevel recordingLevel = RecordingLevel.INFO;
+        final String value = "immutable-value";
+
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            Collections.singletonMap("additional-tag", "additional-value"),
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID),
+                mkEntry("additional-tag", "additional-value")
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
     }
 
     @Test
     public void shouldAddClientLevelMutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
-        final Gauge<String> valueProvider = (config, now) -> "mutable-value";
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(valueProvider));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
+        final String value = "mutable-value";
 
-        streamsMetrics.addClientLevelMutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, valueProvider);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelMutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            (c, t) -> value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Agreed, but I was being consistent with what's [here](https://github.com/apache/kafka/blob/b58aae288fb794b01fd2fc6a29748eba1d277bd6/streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java#L1354). I can change both



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on PR #20883:
URL: https://github.com/apache/kafka/pull/20883#issuecomment-3549286220

   Replaced by https://github.com/apache/kafka/pull/20906 


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529200507


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImpl.java:
##########
@@ -199,7 +193,16 @@ public <T> void addClientLevelImmutableMetric(final String name,
                                                   final String description,
                                                   final RecordingLevel recordingLevel,
                                                   final T value) {
-        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description, clientLevelTagMap());
+        addClientLevelImmutableMetric(name, description, Collections.emptyMap(), recordingLevel, value);
+    }
+
+    public <T> void addClientLevelImmutableMetric(final String name,
+                                                  final String description,
+                                                  final Map<String, String> additionalTags,
+                                                  final RecordingLevel recordingLevel,
+                                                  final T value) {
+        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description,
+            clientLevelTagMap(additionalTags));

Review Comment:
   No that I know of (and 100 would be very tight). As long as checkstyle does not complain, we are good.
   
   The other point is: if we really have too many parameter, the current formatting with a single line break is also very hard to read, and if we thing the line gets to long, we should go with a single-parameter per line formatting:
   ```
   final MetricName metricName = metrics.metricName(
       name,
       CLIENT_LEVEL_GROUP,
       description,
       clientLevelTagMap(additionalTags)
   );
   ```



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "bbejeck (via GitHub)" <gi...@apache.org>.
bbejeck commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529085770


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
+    }
+
+    @Test
+    public void shouldAddClientLevelImmutableMetricWithAdditionalTags() {
+        final RecordingLevel recordingLevel = RecordingLevel.INFO;
+        final String value = "immutable-value";
+
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            Collections.singletonMap("additional-tag", "additional-value"),
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID),
+                mkEntry("additional-tag", "additional-value")
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
     }
 
     @Test
     public void shouldAddClientLevelMutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
-        final Gauge<String> valueProvider = (config, now) -> "mutable-value";
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(valueProvider));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
+        final String value = "mutable-value";
 
-        streamsMetrics.addClientLevelMutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, valueProvider);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelMutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            (c, t) -> value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Why just `not null` vs. asserting the name is equal?



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
+    }
+
+    @Test
+    public void shouldAddClientLevelImmutableMetricWithAdditionalTags() {
+        final RecordingLevel recordingLevel = RecordingLevel.INFO;
+        final String value = "immutable-value";
+
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            Collections.singletonMap("additional-tag", "additional-value"),
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID),
+                mkEntry("additional-tag", "additional-value")
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
     }
 
     @Test
     public void shouldAddClientLevelMutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
-        final Gauge<String> valueProvider = (config, now) -> "mutable-value";
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(valueProvider));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
+        final String value = "mutable-value";
 
-        streamsMetrics.addClientLevelMutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, valueProvider);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelMutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            (c, t) -> value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
+    }
+
+    @Test
+    public void shouldAddClientLevelMutableMetricWithAdditionalTags() {
+        final RecordingLevel recordingLevel = RecordingLevel.INFO;
+        final String value = "mutable-value";
+
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelMutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            Collections.singletonMap("additional-tag", "additional-value"),
+            recordingLevel,
+            (c, t) -> value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID),
+                mkEntry("additional-tag", "additional-value")
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Same here



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529162843


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImpl.java:
##########
@@ -285,10 +297,12 @@ private String threadSensorPrefix(final String threadId) {
     }
 
     public Map<String, String> clientLevelTagMap() {

Review Comment:
   Is this method still in use? If not, should we remove it?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "AndrewJSchofield (via GitHub)" <gi...@apache.org>.
AndrewJSchofield commented on PR #20883:
URL: https://github.com/apache/kafka/pull/20883#issuecomment-3536826563

   @gensericghiro Please fix the check style failure in the build.


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529170284


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -726,7 +802,7 @@ private void setupRemoveSensorsTest(final Metrics metrics,
     @Test
     public void shouldRemoveClientLevelMetricsAndSensors() {
         final Metrics metrics = mock(Metrics.class);
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
+        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID,

Review Comment:
   Nit: more formatting cleanup in this file, too :) 



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529161584


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImpl.java:
##########
@@ -211,7 +214,16 @@ public <T> void addClientLevelMutableMetric(final String name,
                                                 final String description,
                                                 final RecordingLevel recordingLevel,
                                                 final Gauge<T> valueProvider) {
-        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description, clientLevelTagMap());
+        addClientLevelMutableMetric(name, description, Collections.emptyMap(), recordingLevel, valueProvider);
+    }
+
+    public <T> void addClientLevelMutableMetric(final String name,
+                                                final String description,
+                                                final Map<String, String> additionalTags,
+                                                final RecordingLevel recordingLevel,
+                                                final Gauge<T> valueProvider) {
+        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description,
+            clientLevelTagMap(additionalTags));

Review Comment:
   as above



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529170284


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -726,7 +802,7 @@ private void setupRemoveSensorsTest(final Metrics metrics,
     @Test
     public void shouldRemoveClientLevelMetricsAndSensors() {
         final Metrics metrics = mock(Metrics.class);
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
+        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID,

Review Comment:
   Nit: more formatting cleanup :) 



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "gensericghiro (via GitHub)" <gi...@apache.org>.
gensericghiro commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529179866


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImpl.java:
##########
@@ -199,7 +193,16 @@ public <T> void addClientLevelImmutableMetric(final String name,
                                                   final String description,
                                                   final RecordingLevel recordingLevel,
                                                   final T value) {
-        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description, clientLevelTagMap());
+        addClientLevelImmutableMetric(name, description, Collections.emptyMap(), recordingLevel, value);
+    }
+
+    public <T> void addClientLevelImmutableMetric(final String name,
+                                                  final String description,
+                                                  final Map<String, String> additionalTags,
+                                                  final RecordingLevel recordingLevel,
+                                                  final T value) {
+        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description,
+            clientLevelTagMap(additionalTags));

Review Comment:
   Do we not enforce a max 100 width on columns? It makes the code hard to read otherwise



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "gensericghiro (via GitHub)" <gi...@apache.org>.
gensericghiro closed pull request #20883: KAFKA-19882 Cleaning client level metric tags
URL: https://github.com/apache/kafka/pull/20883


-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529169420


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Same question as Bill asks further below



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
+    }
+
+    @Test
+    public void shouldAddClientLevelImmutableMetricWithAdditionalTags() {
+        final RecordingLevel recordingLevel = RecordingLevel.INFO;
+        final String value = "immutable-value";
+
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            Collections.singletonMap("additional-tag", "additional-value"),
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID),
+                mkEntry("additional-tag", "additional-value")
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Same



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529161302


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImpl.java:
##########
@@ -199,7 +193,16 @@ public <T> void addClientLevelImmutableMetric(final String name,
                                                   final String description,
                                                   final RecordingLevel recordingLevel,
                                                   final T value) {
-        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description, clientLevelTagMap());
+        addClientLevelImmutableMetric(name, description, Collections.emptyMap(), recordingLevel, value);
+    }
+
+    public <T> void addClientLevelImmutableMetric(final String name,
+                                                  final String description,
+                                                  final Map<String, String> additionalTags,
+                                                  final RecordingLevel recordingLevel,
+                                                  final T value) {
+        final MetricName metricName = metrics.metricName(name, CLIENT_LEVEL_GROUP, description,
+            clientLevelTagMap(additionalTags));

Review Comment:
   nit: Formatting. Why the line break? Should just go to above line?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-19882 Cleaning client level metric tags [kafka]

Posted by "gensericghiro (via GitHub)" <gi...@apache.org>.
gensericghiro commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529183049


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImpl.java:
##########
@@ -285,10 +297,12 @@ private String threadSensorPrefix(final String threadId) {
     }
 
     public Map<String, String> clientLevelTagMap() {

Review Comment:
   Yes, [here](https://github.com/apache/kafka/blob/b58aae288fb794b01fd2fc6a29748eba1d277bd6/streams/src/main/java/org/apache/kafka/streams/internals/metrics/ClientMetrics.java#L164)



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org