rondagostino commented on a change in pull request #10019:
URL: https://github.com/apache/kafka/pull/10019#discussion_r568991855



##########
File path: core/src/main/scala/kafka/server/KafkaBroker.scala
##########
@@ -0,0 +1,113 @@
+/**
+ * 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.server
+
+import java.util
+
+import com.yammer.metrics.{core => yammer}
+import kafka.controller.KafkaController
+import kafka.log.LogManager
+import kafka.metrics.{KafkaMetricsGroup, KafkaYammerMetrics, 
LinuxIoMetricsCollector}
+import kafka.network.SocketServer
+import kafka.utils.{KafkaScheduler, Logging}
+import kafka.zk.BrokerInfo
+import org.apache.kafka.clients.CommonClientConfigs
+import org.apache.kafka.common.ClusterResource
+import org.apache.kafka.common.internals.ClusterResourceListeners
+import org.apache.kafka.common.metrics.{KafkaMetricsContext, Metrics, 
MetricsReporter}
+import org.apache.kafka.common.utils.Time
+import org.apache.kafka.server.authorizer.Authorizer
+
+import scala.collection.Seq
+import scala.jdk.CollectionConverters._
+
+object KafkaBroker {
+  //properties for MetricsContext
+  val metricsPrefix: String = "kafka.server"
+  private val KAFKA_CLUSTER_ID: String = "kafka.cluster.id"
+  private val KAFKA_BROKER_ID: String = "kafka.broker.id"
+
+  private[server] def createKafkaMetricsContext(clusterId: String, config: 
KafkaConfig): KafkaMetricsContext = {
+    val contextLabels = new util.HashMap[String, Object]
+    contextLabels.put(KAFKA_CLUSTER_ID, clusterId)
+    contextLabels.put(KAFKA_BROKER_ID, config.brokerId.toString)
+    
contextLabels.putAll(config.originalsWithPrefix(CommonClientConfigs.METRICS_CONTEXT_PREFIX))
+    val metricsContext = new KafkaMetricsContext(metricsPrefix, contextLabels)
+    metricsContext
+  }
+
+  private[server] def notifyClusterListeners(clusterId: String,
+                                             clusterListeners: Seq[AnyRef]): 
Unit = {
+    val clusterResourceListeners = new ClusterResourceListeners
+    clusterResourceListeners.maybeAddAll(clusterListeners.asJava)
+    clusterResourceListeners.onUpdate(new ClusterResource(clusterId))
+  }
+
+  private[server] def notifyMetricsReporters(clusterId: String,
+                                             config: KafkaConfig,
+                                             metricsReporters: Seq[AnyRef]): 
Unit = {
+    val metricsContext = createKafkaMetricsContext(clusterId, config)
+    metricsReporters.foreach {
+      case x: MetricsReporter => x.contextChange(metricsContext)
+      case _ => //do nothing
+    }
+  }
+}
+
+trait KafkaBroker extends Logging with KafkaMetricsGroup {

Review comment:
       Metrics need to exist for compatibility, of course, and while a pure 
interface sounds like a great idea, it feels practical to put the metrics here 
since they are shared by all types of brokers -- they're basically part of the 
interface we've agreed to maintain for the sake of compatibility.
   
   I started to do the documentation as you suggested, but they're all pretty 
useless (`// the authorizer`, for example).
   
   I was able to remove `Logging` since it is redundant -- `KafkaMetricsGroup` 
already has 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.

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


Reply via email to