kirktrue commented on code in PR #14843:
URL: https://github.com/apache/kafka/pull/14843#discussion_r1409772670


##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -4387,7 +4398,52 @@ public FenceProducersResult 
fenceProducers(Collection<String> transactionalIds,
 
     @Override
     public Uuid clientInstanceId(Duration timeout) {
-        throw new UnsupportedOperationException();
+        if (timeout.isNegative()) {
+            throw new IllegalArgumentException("The timeout cannot be 
negative.");
+        }
+
+        if (!clientTelemetryEnabled) {
+            throw new IllegalStateException("Telemetry is not enabled. Set 
config `enable.metrics.push` to `true`.");
+        }
+
+        if (clientInstanceId != null) {
+            return clientInstanceId;
+        }
+
+        final long now = time.milliseconds();
+        final KafkaFutureImpl<Uuid> future = new KafkaFutureImpl<>();
+        runnable.call(new Call("getTelemetrySubscriptions", 
calcDeadlineMs(now, (int) timeout.toMillis()),
+            new LeastLoadedNodeProvider()) {
+
+            @Override
+            GetTelemetrySubscriptionsRequest.Builder createRequest(int 
timeoutMs) {
+                return new GetTelemetrySubscriptionsRequest.Builder(new 
GetTelemetrySubscriptionsRequestData(), true);
+            }
+
+            @Override
+            void handleResponse(AbstractResponse abstractResponse) {
+                GetTelemetrySubscriptionsResponse response = 
(GetTelemetrySubscriptionsResponse) abstractResponse;
+                if (response.error() != Errors.NONE) {
+                    future.completeExceptionally(response.error().exception());
+                } else {
+                    future.complete(response.data().clientInstanceId());
+                }
+            }
+
+            @Override
+            void handleFailure(Throwable throwable) {
+                future.completeExceptionally(throwable);
+            }
+        }, now);
+
+        try {
+            clientInstanceId = future.get();
+        } catch (Exception e) {
+            log.error("Error occurred while fetching client instance id", e);
+            throw new KafkaException("Error occurred while fetching client 
instance id", e);
+        }

Review Comment:
   Why do we make an explicit RPC call for the admin client, but the other two 
clients use the `ClientTelemetryUtils. fetchClientInstanceId`?



##########
clients/src/main/java/org/apache/kafka/clients/ClientTelemetryUtils.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.clients;
+
+import org.apache.kafka.common.Uuid;
+
+import java.time.Duration;
+import java.util.Optional;
+
+public class ClientTelemetryUtils {

Review Comment:
   I think moving it to `internals` makes sense.



##########
clients/src/main/java/org/apache/kafka/clients/NetworkClient.java:
##########
@@ -361,6 +370,9 @@ private void cancelInFlightRequests(String nodeId,
                 }
             } else if (request.header.apiKey() == ApiKeys.METADATA) {
                 metadataUpdater.handleFailedRequest(now, Optional.empty());
+            } else if ((request.header.apiKey() == 
ApiKeys.GET_TELEMETRY_SUBSCRIPTIONS ||
+                request.header.apiKey() == ApiKeys.PUSH_TELEMETRY) && 
telemetrySender != null) {
+                telemetrySender.handleFailedRequest(request.header.apiKey(), 
null);

Review Comment:
   nit: maybe creating an `ApiKeys` from `request.header.apiKey()` would make 
this visually cleaner?



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

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

Reply via email to