-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-15189: only init remote topic metrics when enabled #14133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
e7fa43e
6f7a39c
f7696e8
6b76e3b
9efb0e2
aa89b79
7ba060c
3241b60
5dc462b
c0536c8
4987727
4f37d9c
4c2d335
86ed825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * 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.log.remote; | ||
|
|
||
| import com.yammer.metrics.core.MetricName; | ||
| import kafka.server.BrokerTopicStats; | ||
| import org.apache.kafka.server.metrics.KafkaYammerMetrics; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import static org.apache.kafka.storage.internals.log.RemoteStorageThreadPool.AVG_IDLE_PERCENT; | ||
| import static org.apache.kafka.storage.internals.log.RemoteStorageThreadPool.TASK_QUEUE_SIZE; | ||
|
|
||
| public class RemoteStorageMetrics { | ||
| final static MetricName REMOTE_BYTES_OUT_PER_SEC = getMetricName( | ||
| "kafka.server", "BrokerTopicMetrics", BrokerTopicStats.RemoteBytesOutPerSec()); | ||
| final static MetricName REMOTE_BYTES_IN_PER_SEC = getMetricName( | ||
| "kafka.server", "BrokerTopicMetrics", BrokerTopicStats.RemoteBytesInPerSec()); | ||
| final static MetricName REMOTE_READ_REQUESTS_PER_SEC = getMetricName( | ||
| "kafka.server", "BrokerTopicMetrics", BrokerTopicStats.RemoteReadRequestsPerSec()); | ||
| final static MetricName REMOTE_WRITE_REQUESTS_PER_SEC = getMetricName( | ||
| "kafka.server", "BrokerTopicMetrics", BrokerTopicStats.RemoteWriteRequestsPerSec()); | ||
| final static MetricName FAILED_REMOTE_READ_REQUESTS_PER_SEC = getMetricName( | ||
| "kafka.server", "BrokerTopicMetrics", BrokerTopicStats.FailedRemoteReadRequestsPerSec()); | ||
| final static MetricName FAILED_REMOTE_WRITE_REQUESTS_PER_SEC = getMetricName( | ||
| "kafka.server", "BrokerTopicMetrics", BrokerTopicStats.FailedRemoteWriteRequestsPerSec()); | ||
| final static MetricName REMOTE_LOG_MANAGER_TASKS_AVG_IDLE_PERCENT = getMetricName( | ||
| "kafka.log.remote", "RemoteLogManager", RemoteLogManager.REMOTE_LOG_MANAGER_TASKS_AVG_IDLE_PERCENT); | ||
| final static MetricName REMOTE_LOG_READER_TASK_QUEUE_SIZE = getMetricName( | ||
| "org.apache.kafka.storage.internals.log", "RemoteStorageThreadPool", RemoteLogManager.REMOTE_LOG_READER_METRICS_NAME_PREFIX + TASK_QUEUE_SIZE); | ||
|
divijvaidya marked this conversation as resolved.
Outdated
|
||
| final static MetricName REMOTE_LOG_READER_AVG_IDLE_PERCENT = getMetricName( | ||
| "org.apache.kafka.storage.internals.log", "RemoteStorageThreadPool", RemoteLogManager.REMOTE_LOG_READER_METRICS_NAME_PREFIX + AVG_IDLE_PERCENT); | ||
|
|
||
| public static Set<MetricName> allMetrics() { | ||
| Set<MetricName> metrics = new HashSet<>(); | ||
| metrics.add(REMOTE_BYTES_OUT_PER_SEC); | ||
| metrics.add(REMOTE_BYTES_IN_PER_SEC); | ||
| metrics.add(REMOTE_READ_REQUESTS_PER_SEC); | ||
| metrics.add(REMOTE_WRITE_REQUESTS_PER_SEC); | ||
| metrics.add(FAILED_REMOTE_READ_REQUESTS_PER_SEC); | ||
| metrics.add(FAILED_REMOTE_WRITE_REQUESTS_PER_SEC); | ||
| metrics.add(REMOTE_LOG_MANAGER_TASKS_AVG_IDLE_PERCENT); | ||
| metrics.add(REMOTE_LOG_READER_AVG_IDLE_PERCENT); | ||
| metrics.add(REMOTE_LOG_READER_TASK_QUEUE_SIZE); | ||
|
|
||
| return metrics; | ||
| } | ||
| private static MetricName getMetricName(String group, String type, String name) { | ||
| return KafkaYammerMetrics.getMetricName(group, type, name); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import java.util.{Locale, Properties} | |
| import kafka.server.{KafkaConfig, KafkaServer} | ||
| import kafka.utils.{JaasTestUtils, TestUtils} | ||
| import com.yammer.metrics.core.{Gauge, Histogram, Meter} | ||
| import kafka.log.remote.RemoteStorageMetrics | ||
| import org.apache.kafka.clients.consumer.Consumer | ||
| import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig, ProducerRecord} | ||
| import org.apache.kafka.common.{Metric, MetricName, TopicPartition} | ||
|
|
@@ -24,9 +25,12 @@ import org.apache.kafka.common.errors.{InvalidTopicException, UnknownTopicOrPart | |
| import org.apache.kafka.common.network.ListenerName | ||
| import org.apache.kafka.common.security.auth.SecurityProtocol | ||
| import org.apache.kafka.common.security.authenticator.TestJaasConfig | ||
| import org.apache.kafka.server.log.remote.storage.{NoOpRemoteLogMetadataManager, NoOpRemoteStorageManager, RemoteLogManagerConfig} | ||
| import org.apache.kafka.server.metrics.KafkaYammerMetrics | ||
| import org.junit.jupiter.api.{AfterEach, BeforeEach, Test, TestInfo} | ||
| import org.junit.jupiter.api.{AfterEach, BeforeEach, TestInfo} | ||
| import org.junit.jupiter.api.Assertions._ | ||
| import org.junit.jupiter.params.ParameterizedTest | ||
| import org.junit.jupiter.params.provider.ValueSource | ||
|
|
||
| import scala.annotation.nowarn | ||
| import scala.jdk.CollectionConverters._ | ||
|
|
@@ -54,6 +58,12 @@ class MetricsTest extends IntegrationTestHarness with SaslSetup { | |
|
|
||
| @BeforeEach | ||
| override def setUp(testInfo: TestInfo): Unit = { | ||
| if (testInfo.getDisplayName.endsWith("true")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this enable RemoteStorage for all tests which use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right! Currently there's only 1 test in this test suite, but we should make it much clear. Updating now. |
||
| // systemRemoteStorageEnabled is enabled | ||
| this.serverConfig.setProperty(RemoteLogManagerConfig.REMOTE_LOG_STORAGE_SYSTEM_ENABLE_PROP, "true") | ||
| this.serverConfig.setProperty(RemoteLogManagerConfig.REMOTE_STORAGE_MANAGER_CLASS_NAME_PROP, classOf[NoOpRemoteStorageManager].getName) | ||
| this.serverConfig.setProperty(RemoteLogManagerConfig.REMOTE_LOG_METADATA_MANAGER_CLASS_NAME_PROP, classOf[NoOpRemoteLogMetadataManager].getName) | ||
| } | ||
| verifyNoRequestMetrics("Request metrics not removed in a previous test") | ||
| startSasl(jaasSections(kafkaServerSaslMechanisms, Some(kafkaClientSaslMechanism), KafkaSasl, kafkaServerJaasEntryName)) | ||
| super.setUp(testInfo) | ||
|
|
@@ -70,8 +80,9 @@ class MetricsTest extends IntegrationTestHarness with SaslSetup { | |
| * Verifies some of the metrics of producer, consumer as well as server. | ||
| */ | ||
| @nowarn("cat=deprecation") | ||
| @Test | ||
| def testMetrics(): Unit = { | ||
| @ParameterizedTest(name = "testMetrics with systemRemoteStorageEnabled: {0}") | ||
| @ValueSource(booleans = Array(true, false)) | ||
| def testMetrics(systemRemoteStorageEnabled: Boolean): Unit = { | ||
| val topic = "topicWithOldMessageFormat" | ||
| val props = new Properties | ||
| props.setProperty(TopicConfig.MESSAGE_FORMAT_VERSION_CONFIG, "0.9.0") | ||
|
|
@@ -103,6 +114,7 @@ class MetricsTest extends IntegrationTestHarness with SaslSetup { | |
|
|
||
| generateAuthenticationFailure(tp) | ||
| verifyBrokerAuthenticationMetrics(server) | ||
| verifyRemoteStorageMetrics(systemRemoteStorageEnabled) | ||
| } | ||
|
|
||
| private def sendRecords(producer: KafkaProducer[Array[Byte], Array[Byte]], numRecords: Int, | ||
|
|
@@ -308,4 +320,17 @@ class MetricsTest extends IntegrationTestHarness with SaslSetup { | |
| } | ||
| assertTrue(metrics.isEmpty, s"$errorMessage: ${metrics.keys}") | ||
| } | ||
|
|
||
| private def verifyRemoteStorageMetrics(shouldContainMetrics: Boolean): Unit = { | ||
| val metrics = RemoteStorageMetrics.allMetrics().asScala.filter(name => | ||
| KafkaYammerMetrics.defaultRegistry.allMetrics.asScala.find(metric => { | ||
| metric._1.getMBeanName().equals(name.getMBeanName) | ||
| }).isDefined | ||
| ).toList | ||
| if (shouldContainMetrics) { | ||
| assertEquals(RemoteStorageMetrics.allMetrics().size(), metrics.size, s"Only $metrics appear in the metrics") | ||
| } else { | ||
| assertEquals(0, metrics.size, s"$metrics should not appear in the metrics") | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.