apoorvmittal10 commented on code in PR #14699:
URL: https://github.com/apache/kafka/pull/14699#discussion_r1391640685


##########
core/src/main/java/kafka/metrics/ClientMetricsInstanceMetadata.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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 kafka.metrics;
+
+import java.util.regex.Pattern;
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.requests.RequestContext;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Information from the client's metadata is gathered from the client's 
request.
+ */
+public class ClientMetricsInstanceMetadata {
+
+    private final Map<String, String> attributesMap;
+
+    public ClientMetricsInstanceMetadata(Uuid clientInstanceId, RequestContext 
requestContext) {
+        Objects.requireNonNull(clientInstanceId);
+        Objects.requireNonNull(requestContext);
+
+        attributesMap = new HashMap<>();
+
+        attributesMap.put(ClientMetricsConfigs.CLIENT_INSTANCE_ID, 
clientInstanceId.toString());
+        attributesMap.put(ClientMetricsConfigs.CLIENT_ID, 
requestContext.clientId());
+        attributesMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_NAME, 
requestContext.clientInformation != null ?
+            requestContext.clientInformation.softwareName() : null);
+        attributesMap.put(ClientMetricsConfigs.CLIENT_SOFTWARE_VERSION, 
requestContext.clientInformation != null ?
+            requestContext.clientInformation.softwareVersion() : null);
+        attributesMap.put(ClientMetricsConfigs.CLIENT_SOURCE_ADDRESS, 
requestContext.clientAddress != null ?
+            requestContext.clientAddress.getHostAddress() : null);
+        // KIP-714 mentions client source port should be the client 
connection's source port from the
+        // broker's point of view. But the broker does not have this 
information rather the port could be
+        // the broker's port where the client connection is established. We 
might want to consider removing
+        // the client source port from the KIP or use broker port if that can 
be helpful.
+        // TODO: fix port

Review Comment:
   Thanks a lot @junrao this is helpful. I will make the changes in subsequent 
PR to address this. I have created following jira for same: 
https://issues.apache.org/jira/browse/KAFKA-15811



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