From d08a9e232ad1027d51b5f1d74ab82e66be657e5d Mon Sep 17 00:00:00 2001 From: Mickael Maison Date: Wed, 15 May 2024 17:26:40 +0200 Subject: [PATCH] MINOR: Remove unused method in ToolsUtils --- .../main/scala/kafka/utils/ToolsUtils.scala | 32 ------------- .../scala/kafka/utils/ToolsUtilsTest.scala | 45 ------------------- 2 files changed, 77 deletions(-) delete mode 100644 core/src/test/scala/kafka/utils/ToolsUtilsTest.scala diff --git a/core/src/main/scala/kafka/utils/ToolsUtils.scala b/core/src/main/scala/kafka/utils/ToolsUtils.scala index ffb6214d0b69f..5c076c7f746fb 100644 --- a/core/src/main/scala/kafka/utils/ToolsUtils.scala +++ b/core/src/main/scala/kafka/utils/ToolsUtils.scala @@ -17,11 +17,8 @@ package kafka.utils import joptsimple.OptionParser -import org.apache.kafka.common.{Metric, MetricName} import org.apache.kafka.server.util.CommandLineUtils -import scala.collection.mutable - object ToolsUtils { def validatePortOrDie(parser: OptionParser, hostPort: String): Unit = { @@ -37,35 +34,6 @@ object ToolsUtils { CommandLineUtils.printUsageAndExit(parser, "Please provide valid host:port like host1:9091,host2:9092\n ") } - /** - * print out the metrics in alphabetical order - * @param metrics the metrics to be printed out - */ - def printMetrics(metrics: mutable.Map[MetricName, _ <: Metric]): Unit = { - var maxLengthOfDisplayName = 0 - - val sortedMap = metrics.toSeq.sortWith( (s,t) => - Array(s._1.group(), s._1.name(), s._1.tags()).mkString(":") - .compareTo(Array(t._1.group(), t._1.name(), t._1.tags()).mkString(":")) < 0 - ).map { - case (key, value) => - val mergedKeyName = Array(key.group(), key.name(), key.tags()).mkString(":") - if (maxLengthOfDisplayName < mergedKeyName.length) { - maxLengthOfDisplayName = mergedKeyName.length - } - (mergedKeyName, value.metricValue) - } - println(s"\n%-${maxLengthOfDisplayName}s %s".format("Metric Name", "Value")) - sortedMap.foreach { - case (metricName, value) => - val specifier = value match { - case _ @ (_: java.lang.Float | _: java.lang.Double) => "%.3f" - case _ => "%s" - } - println(s"%-${maxLengthOfDisplayName}s : $specifier".format(metricName, value)) - } - } - /** * This is a simple wrapper around `CommandLineUtils.printUsageAndExit`. * It is needed for tools migration (KAFKA-14525), as there is no Java equivalent for return type `Nothing`. diff --git a/core/src/test/scala/kafka/utils/ToolsUtilsTest.scala b/core/src/test/scala/kafka/utils/ToolsUtilsTest.scala deleted file mode 100644 index 85491368a138c..0000000000000 --- a/core/src/test/scala/kafka/utils/ToolsUtilsTest.scala +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.utils - -import java.io.ByteArrayOutputStream -import java.util.Collections - -import org.apache.kafka.common.MetricName -import org.apache.kafka.common.metrics.Metrics -import org.apache.kafka.common.metrics.internals.IntGaugeSuite -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import org.slf4j.LoggerFactory - -import scala.jdk.CollectionConverters._ - -class ToolsUtilsTest { - private val log = LoggerFactory.getLogger(classOf[ToolsUtilsTest]) - - @Test def testIntegerMetric(): Unit = { - val outContent = new ByteArrayOutputStream() - val metrics = new Metrics - val suite = new IntGaugeSuite[String](log, "example", metrics, (k: String) => new MetricName(k + "-bar", "test", "A test metric", Collections.singletonMap("key", "value")), 1) - suite.increment("foo") - Console.withOut(outContent) { - ToolsUtils.printMetrics(metrics.metrics.asScala) - assertTrue(outContent.toString.split("\n").exists(line => line.trim.matches("^test:foo-bar:\\{key=value\\} : 1$"))) - } - } - -}