mimaison commented on code in PR #20672:
URL: https://github.com/apache/kafka/pull/20672#discussion_r2459854014


##########
server/src/main/java/org/apache/kafka/server/metrics/DefaultClientTelemetryContext.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.server.authorizer.AuthorizableRequestContext;
+import org.apache.kafka.server.telemetry.ClientTelemetryContext;
+
+/**
+ * Default implementation of {@link ClientTelemetryContext}.
+ */
+public class DefaultClientTelemetryContext implements ClientTelemetryContext {
+
+    private final int pushIntervalMs;
+    private final AuthorizableRequestContext authorizableRequestContext;
+
+    public DefaultClientTelemetryContext(int pushIntervalMs, 
AuthorizableRequestContext authorizableRequestContext) {
+        this.pushIntervalMs = pushIntervalMs;
+        this.authorizableRequestContext = authorizableRequestContext;
+    }
+
+    @Override
+    public int pushIntervalMs() {
+        return pushIntervalMs;
+    }
+
+    @Override
+    public AuthorizableRequestContext authorizableRequestContext() {
+        return authorizableRequestContext;
+    }
+}

Review Comment:
   Can we have a newline?



##########
core/src/test/scala/unit/kafka/server/DynamicBrokerConfigTest.scala:
##########
@@ -1086,3 +1126,50 @@ class TestDynamicThreadPool extends BrokerReconfigurable 
{
     assertEquals(100, newConfig.backgroundThreads)
   }
 }
+
+class TestExporterOnly extends org.apache.kafka.common.metrics.MetricsReporter 
with ClientTelemetryExporterProvider {

Review Comment:
   Can we import `MetricsReporter`? same below for other classes



##########
server/src/main/java/org/apache/kafka/server/metrics/ClientTelemetryExporterPlugin.java:
##########
@@ -18,40 +18,60 @@
 
 import org.apache.kafka.common.requests.PushTelemetryRequest;
 import org.apache.kafka.common.requests.RequestContext;
+import org.apache.kafka.server.telemetry.ClientTelemetryExporter;
 import org.apache.kafka.server.telemetry.ClientTelemetryReceiver;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
 /**
- * Plugin to register client telemetry receivers and export metrics. This 
class is used by the Kafka
- * server to export client metrics to the registered receivers.
+ * Plugin to register client telemetry receivers/exporters and export metrics. 
This class is used by the Kafka
+ * server to export client metrics to the registered receivers and exporters, 
supporting both the deprecated
+ * {@link ClientTelemetryReceiver} and the new {@link ClientTelemetryExporter} 
interfaces.
  */
-public class ClientMetricsReceiverPlugin {
+@SuppressWarnings({"deprecation", "overloads", "removal"})
+public class ClientTelemetryExporterPlugin {
 
     private final List<ClientTelemetryReceiver> receivers;
+    private final List<ClientTelemetryExporter> exporters;
 
-    public ClientMetricsReceiverPlugin() {
+    public ClientTelemetryExporterPlugin() {
         this.receivers = Collections.synchronizedList(new ArrayList<>());
+        this.exporters = Collections.synchronizedList(new ArrayList<>());
     }
 
     public boolean isEmpty() {
-        return receivers.isEmpty();
+        return receivers.isEmpty() && exporters.isEmpty();
     }
 
     public void add(ClientTelemetryReceiver receiver) {
         receivers.add(receiver);
     }
 
+    public void add(ClientTelemetryExporter exporter) {
+        exporters.add(exporter);
+    }
+
     public DefaultClientTelemetryPayload getPayLoad(PushTelemetryRequest 
request) {
         return new DefaultClientTelemetryPayload(request);
     }
 
-    public void exportMetrics(RequestContext context, PushTelemetryRequest 
request) {
+    @SuppressWarnings("deprecation")

Review Comment:
   Do we need this suppression since we also have it on the class?



##########
core/src/test/scala/unit/kafka/server/DynamicBrokerConfigTest.scala:
##########
@@ -1065,6 +1066,45 @@ class DynamicBrokerConfigTest {
     )
     
assertFalse(ctx.currentDefaultLogConfig.get().originals().containsKey(SocketServerConfigs.ADVERTISED_LISTENERS_CONFIG))
   }
+
+  @Test
+  def testClientTelemetryExporter(): Unit = {
+    val brokerId = 0
+    val origProps = TestUtils.createBrokerConfig(brokerId, port = 8181)
+    val config = KafkaConfig(origProps)
+    val metrics = mock(classOf[Metrics])
+    val telemetryPlugin = mock(classOf[ClientTelemetryExporterPlugin])
+
+    config.dynamicConfig.initialize(Some(telemetryPlugin))
+    val m = new DynamicMetricsReporters(brokerId, config, metrics, "clusterId")
+    config.dynamicConfig.addReconfigurable(m)
+
+    def updateReporter(reporterClass: Class[_]): Unit = {
+      val props = new Properties()
+      props.put(MetricConfigs.METRIC_REPORTER_CLASSES_CONFIG, 
reporterClass.getName)
+      config.dynamicConfig.updateDefaultConfig(props)
+    }
+
+    // Reporter implementing only ClientTelemetryExporterProvider
+    updateReporter(classOf[TestExporterOnly])

Review Comment:
   I wonder if we can just do 
`updateReporter(classOf[ClientTelemetryExporterProvider])` and not need 
`TestExporterOnly`. Same below for `TestReceiverOnly`



-- 
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]

Reply via email to