ivanyu commented on code in PR #13067: URL: https://github.com/apache/kafka/pull/13067#discussion_r1116206680
########## core/src/main/scala/kafka/log/UnifiedLog.scala: ########## @@ -247,10 +248,19 @@ class UnifiedLog(@volatile var logStartOffset: Long, @volatile private var _topicId: Option[Uuid], val keepPartitionMetadataFile: Boolean, val remoteStorageSystemEnable: Boolean = false, - remoteLogManager: Option[RemoteLogManager] = None) extends Logging with KafkaMetricsGroup { + remoteLogManager: Option[RemoteLogManager] = None) extends Logging { import kafka.log.UnifiedLog._ + private val metricsGroup = new KafkaMetricsGroup(this.getClass) { + // For compatibility, metrics are defined to be under `Log` class + override def metricName(name: String, tags: util.Map[String, String]): MetricName = { + val pkg = getClass.getPackage + val pkgStr = if (pkg == null) "" else pkg.getName Review Comment: Sure, removed. ########## core/src/main/scala/kafka/network/RequestChannel.scala: ########## @@ -497,51 +501,58 @@ object RequestMetrics { val ErrorsPerSec = "ErrorsPerSec" } -class RequestMetrics(name: String) extends KafkaMetricsGroup { +class RequestMetrics(name: String) { import RequestMetrics._ - val tags = Map("request" -> name) + private val metricsGroup = new KafkaMetricsGroup(this.getClass) + + val tags = Map("request" -> name).asJava val requestRateInternal = new Pool[Short, Meter]() // time a request spent in a request queue - val requestQueueTimeHist = newHistogram(RequestQueueTimeMs, biased = true, tags) + val requestQueueTimeHist = metricsGroup.newHistogram(RequestQueueTimeMs, true, tags) // time a request takes to be processed at the local broker - val localTimeHist = newHistogram(LocalTimeMs, biased = true, tags) + val localTimeHist = metricsGroup.newHistogram(LocalTimeMs, true, tags) // time a request takes to wait on remote brokers (currently only relevant to fetch and produce requests) - val remoteTimeHist = newHistogram(RemoteTimeMs, biased = true, tags) + val remoteTimeHist = metricsGroup.newHistogram(RemoteTimeMs, true, tags) // time a request is throttled, not part of the request processing time (throttling is done at the client level // for clients that support KIP-219 and by muting the channel for the rest) - val throttleTimeHist = newHistogram(ThrottleTimeMs, biased = true, tags) + val throttleTimeHist = metricsGroup.newHistogram(ThrottleTimeMs, true, tags) // time a response spent in a response queue - val responseQueueTimeHist = newHistogram(ResponseQueueTimeMs, biased = true, tags) + val responseQueueTimeHist = metricsGroup.newHistogram(ResponseQueueTimeMs, true, tags) // time to send the response to the requester - val responseSendTimeHist = newHistogram(ResponseSendTimeMs, biased = true, tags) - val totalTimeHist = newHistogram(TotalTimeMs, biased = true, tags) + val responseSendTimeHist = metricsGroup.newHistogram(ResponseSendTimeMs, true, tags) + val totalTimeHist = metricsGroup.newHistogram(TotalTimeMs, true, tags) // request size in bytes - val requestBytesHist = newHistogram(RequestBytes, biased = true, tags) + val requestBytesHist = metricsGroup.newHistogram(RequestBytes, true, tags) // time for message conversions (only relevant to fetch and produce requests) val messageConversionsTimeHist = if (name == ApiKeys.FETCH.name || name == ApiKeys.PRODUCE.name) - Some(newHistogram(MessageConversionsTimeMs, biased = true, tags)) + Some(metricsGroup.newHistogram(MessageConversionsTimeMs, true, tags)) else None // Temporary memory allocated for processing request (only populated for fetch and produce requests) // This shows the memory allocated for compression/conversions excluding the actual request size val tempMemoryBytesHist = if (name == ApiKeys.FETCH.name || name == ApiKeys.PRODUCE.name) - Some(newHistogram(TemporaryMemoryBytes, biased = true, tags)) + Some(metricsGroup.newHistogram(TemporaryMemoryBytes, true, tags)) else None private val errorMeters = mutable.Map[Errors, ErrorMeter]() Errors.values.foreach(error => errorMeters.put(error, new ErrorMeter(name, error))) - def requestRate(version: Short): Meter = { - requestRateInternal.getAndMaybePut(version, newMeter(RequestsPerSec, "requests", TimeUnit.SECONDS, tags + ("version" -> version.toString))) + def requestRate(version: Short): Meter = + requestRateInternal.getAndMaybePut(version, metricsGroup.newMeter(RequestsPerSec, "requests", TimeUnit.SECONDS, tagsWithVersion(version))) + + def tagsWithVersion(version: Short): java.util.Map[String, String] = { + val tags1 = new util.HashMap(tags) Review Comment: Yeah, thanks. Done -- 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