AndrewJSchofield commented on code in PR #14621:
URL: https://github.com/apache/kafka/pull/14621#discussion_r1370842597


##########
core/src/main/scala/kafka/server/ZkConfigManager.scala:
##########
@@ -38,7 +38,8 @@ object ConfigType {
   val User = "users"
   val Broker = "brokers"
   val Ip = "ips"
-  val all = Seq(Topic, Client, User, Broker, Ip)
+  val ClientMetrics = "client-metrics"

Review Comment:
   Given that we don't support client metrics on ZK, I am surprised to see code 
changes in ZkConfigManager.



##########
core/src/main/scala/kafka/metrics/ClientMetricsMetadata.scala:
##########
@@ -0,0 +1,130 @@
+/**
+ * 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 kafka.Kafka.info
+import kafka.metrics.ClientMetricsConfig.ClientMatchingParams._
+import kafka.network.RequestChannel
+import org.apache.kafka.common.errors.InvalidConfigurationException
+
+import java.util.regex.{Pattern, PatternSyntaxException}
+import scala.collection.mutable
+
+/**
+ * Information from the client's metadata is gathered from the client's 
request.
+ */
+object ClientMetricsMetadata {
+  def apply(request: RequestChannel.Request, clientInstanceId: String): 
ClientMetricsMetadata = {
+    val instance = new ClientMetricsMetadata
+    val ctx = request.context
+    val softwareName = if (ctx.clientInformation != null) 
ctx.clientInformation.softwareName() else ""
+    val softwareVersion = if (ctx.clientInformation != null) 
ctx.clientInformation.softwareVersion() else ""
+    instance.init(clientInstanceId, ctx.clientId(), softwareName, 
softwareVersion,
+                  ctx.clientAddress.getHostAddress, 
ctx.clientAddress.getHostAddress)
+    instance
+  }
+
+  def apply(clientInstanceId: String, clientId: String, softwareName: String,
+            softwareVersion: String, clientHostAddress: String, clientPort: 
String): ClientMetricsMetadata = {
+    val instance = new ClientMetricsMetadata
+    instance.init(clientInstanceId, clientId, softwareName, softwareVersion, 
clientHostAddress, clientPort)
+    instance
+  }
+
+  /**
+   * Parses the client matching patterns and builds a map with entries that has
+   * (PatternName, PatternValue) as the entries.
+   *  Ex: "VERSION=1.2.3" would be converted to a map entry of (Version, 1.2.3)
+   *
+   *  NOTES:
+   *  1. Client match pattern splits the input into two parts separated by 
first
+   *     occurrence of the character '='
+   *  2. '*' is considered as invalid client match pattern
+   * @param patterns List of client matching pattern strings
+   * @return map of client matching pattern entries
+   */
+  def parseMatchingPatterns(patterns: List[String]) : Map[String, String] = {
+    val patternsMap = mutable.Map[String, String]()
+    if (patterns != null) {
+      patterns.foreach(x => {
+        val nameValuePair = x.split("=", 2).map(x => x.trim)
+        if (nameValuePair.size == 2 && isValidParam(nameValuePair(0)) && 
validRegExPattern(nameValuePair(1))) {
+          patternsMap += (nameValuePair(0) -> nameValuePair(1))
+        } else {
+          throw new InvalidConfigurationException("Illegal client matching 
pattern: " + x)
+        }
+      })
+    }
+    patternsMap.toMap
+  }
+
+  private def validRegExPattern(inputPattern :String): Boolean = {
+    try {
+      Pattern.compile(inputPattern)
+      true
+    } catch {
+      case e: PatternSyntaxException =>
+        false
+    }
+  }
+
+}
+
+class ClientMetricsMetadata {
+  var attributesMap: mutable.Map[String, String] = 
scala.collection.mutable.Map[String, String]()
+
+  private def init(clientInstanceId: String,
+                   clientId: String,
+                   softwareName: String,
+                   softwareVersion: String,
+                   clientHostAddress: String,

Review Comment:
   I suggest to make this `clientSourceAddress` and `clientSourcePort` so the 
names all agree with the match selector names in the KIP.



##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -2619,6 +2619,9 @@ private ConfigEntry.ConfigSource 
configSource(DescribeConfigsResponse.ConfigSour
             case DYNAMIC_BROKER_LOGGER_CONFIG:
                 configSource = 
ConfigEntry.ConfigSource.DYNAMIC_BROKER_LOGGER_CONFIG;
                 break;
+            case DYNAMIC_CLIENT_METRICS_CONFIG:

Review Comment:
   I think I would make this match the `TOPIC_CONFIG` so that this value is 
actually `CLIENT_METRICS_CONFIG`. They're all dynamic, just like topic configs.



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