-
Notifications
You must be signed in to change notification settings - Fork 14.7k
KAFKA-19606: Fix anomaly of JMX metrics RequestHandlerAvgIdlePercent in kraft combined mode #20481
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
Open
0xffff-zhiyan
wants to merge
23
commits into
apache:trunk
Choose a base branch
from
0xffff-zhiyan:KIP-1207
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
716cac2
add metrics Broker/ControllerRequestHandlerAvgIdlePercent
0xffff-zhiyan 191f3bc
fix
0xffff-zhiyan 4bca99e
Merge branch 'trunk' into KIP-1207
0xffff-zhiyan 034c498
fix
0xffff-zhiyan 53098db
fix
0xffff-zhiyan 70eb3a3
fix
0xffff-zhiyan 5db6b53
fix
0xffff-zhiyan 90655da
fix
0xffff-zhiyan 46e5e7e
fix
0xffff-zhiyan b6b7102
fix
0xffff-zhiyan 73f0257
fix
0xffff-zhiyan c46ce30
fix
0xffff-zhiyan 509a0d2
fix
0xffff-zhiyan f1d7638
fix
0xffff-zhiyan 6ec4a83
fix
0xffff-zhiyan 31cd740
fix
0xffff-zhiyan 2bba71a
fix
0xffff-zhiyan a648ec7
fix
0xffff-zhiyan 7b74ab5
fix
0xffff-zhiyan 0248f3e
Merge remote-tracking branch 'upstream/trunk' into KIP-1207
0xffff-zhiyan ff01d0c
fix
0xffff-zhiyan faf5674
fix
0xffff-zhiyan edb0f3b
fix
0xffff-zhiyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ import org.apache.kafka.common.utils.{BufferSupplier, MockTime, Time} | |
| import org.apache.kafka.network.metrics.RequestChannelMetrics | ||
| import org.apache.kafka.server.common.RequestLocal | ||
| import org.apache.kafka.server.log.remote.storage.RemoteStorageMetrics | ||
| import org.apache.kafka.server.metrics.KafkaYammerMetrics | ||
| import org.apache.kafka.server.metrics.{KafkaMetricsGroup, KafkaYammerMetrics} | ||
| import org.apache.kafka.storage.log.metrics.{BrokerTopicMetrics, BrokerTopicStats} | ||
| import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue} | ||
| import org.junit.jupiter.api.Test | ||
|
|
@@ -40,7 +40,7 @@ import org.mockito.Mockito.{mock, times, verify, when} | |
|
|
||
| import java.net.InetAddress | ||
| import java.nio.ByteBuffer | ||
| import java.util.concurrent.CompletableFuture | ||
| import java.util.concurrent.{CompletableFuture, TimeUnit} | ||
| import java.util.concurrent.atomic.AtomicInteger | ||
| import java.util.stream.Collectors | ||
|
|
||
|
|
@@ -59,7 +59,7 @@ class KafkaRequestHandlerTest { | |
| val requestChannel = new RequestChannel(10, time, metrics) | ||
| val apiHandler = mock(classOf[ApiRequestHandler]) | ||
| try { | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time) | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time, "broker") | ||
|
|
||
| val request = makeRequest(time, metrics) | ||
| requestChannel.sendRequest(request) | ||
|
|
@@ -95,7 +95,7 @@ class KafkaRequestHandlerTest { | |
| val metrics = mock(classOf[RequestChannelMetrics]) | ||
| val apiHandler = mock(classOf[ApiRequestHandler]) | ||
| val requestChannel = new RequestChannel(10, time, metrics) | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time) | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time, "broker") | ||
|
|
||
| var handledCount = 0 | ||
| var tryCompleteActionCount = 0 | ||
|
|
@@ -131,7 +131,7 @@ class KafkaRequestHandlerTest { | |
| val metrics = mock(classOf[RequestChannelMetrics]) | ||
| val apiHandler = mock(classOf[ApiRequestHandler]) | ||
| val requestChannel = new RequestChannel(10, time, metrics) | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time) | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time, "broker") | ||
|
|
||
| val originalRequestLocal = mock(classOf[RequestLocal]) | ||
|
|
||
|
|
@@ -165,7 +165,7 @@ class KafkaRequestHandlerTest { | |
| val metrics = mock(classOf[RequestChannelMetrics]) | ||
| val apiHandler = mock(classOf[ApiRequestHandler]) | ||
| val requestChannel = new RequestChannel(10, time, metrics) | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time) | ||
| val handler = new KafkaRequestHandler(0, 0, mock(classOf[Meter]), new AtomicInteger(1), mock(classOf[Meter]), new AtomicInteger(1), requestChannel, apiHandler, time, "broker") | ||
|
|
||
| val originalRequestLocal = mock(classOf[RequestLocal]) | ||
| when(originalRequestLocal.bufferSupplier).thenReturn(BufferSupplier.create()) | ||
|
|
@@ -698,4 +698,81 @@ class KafkaRequestHandlerTest { | |
| // cleanup | ||
| brokerTopicStats.close() | ||
| } | ||
|
|
||
| @Test | ||
| def testRequestThreadMetrics(): Unit = { | ||
| val time = Time.SYSTEM | ||
| val metricsBroker = new RequestChannelMetrics(java.util.Set.of[ApiKeys]) | ||
| val metricsController = new RequestChannelMetrics(java.util.Set.of[ApiKeys]) | ||
| val requestChannelBroker = new RequestChannel(10, time, metricsBroker) | ||
| val requestChannelController = new RequestChannel(10, time, metricsController) | ||
| val apiHandler = mock(classOf[ApiRequestHandler]) | ||
| val metricsGroup = new KafkaMetricsGroup("kafka.server", "KafkaRequestHandlerPool") | ||
|
|
||
| // Create a factory for this test | ||
| val factory = new KafkaRequestHandlerPoolFactory() | ||
|
|
||
| // Create broker pool with 4 threads | ||
| val brokerPool = factory.createPool( | ||
| 0, | ||
| requestChannelBroker, | ||
| apiHandler, | ||
| time, | ||
| 4, | ||
|
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. Does this compile? Are you missing the "broker" string? 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. yes. thanks for the reminder |
||
| "broker" | ||
| ) | ||
|
|
||
| // Verify global counter is updated | ||
| assertEquals(4, factory.getAggregateThreads.get(), "global counter should be 4 after broker pool") | ||
|
|
||
| // Create controller pool with 4 threads | ||
| val controllerPool = factory.createPool( | ||
| 0, | ||
| requestChannelController, | ||
| apiHandler, | ||
| time, | ||
| 4, | ||
| "controller" | ||
| ) | ||
|
|
||
| // Verify global counter is updated to sum of both pools | ||
| assertEquals(8, factory.getAggregateThreads.get, "global counter should be 8 after both pools") | ||
|
|
||
| val aggregateMeter = metricsGroup.newMeter("RequestHandlerAvgIdlePercent", "percent", TimeUnit.NANOSECONDS) | ||
| val brokerPerPoolIdleMeter = metricsGroup.newMeter("BrokerRequestHandlerAvgIdlePercent", "percent", TimeUnit.NANOSECONDS) | ||
| val controllerPerPoolIdleMeter = metricsGroup.newMeter("ControllerRequestHandlerAvgIdlePercent", "percent", TimeUnit.NANOSECONDS) | ||
|
|
||
| var aggregateValue = 0.0 | ||
| var brokerPerPoolValue = 0.0 | ||
| var controllerPerPoolValue = 0.0 | ||
|
|
||
| // Wait until all idle-percent meters have been initialized with non-zero rates, | ||
| // or timeout after the given duration. | ||
| val startTime = time.milliseconds() | ||
| while(aggregateValue == 0.0 || brokerPerPoolValue == 0.0 || controllerPerPoolValue == 0.0) { | ||
| if (time.milliseconds() - startTime > 8000) | ||
| throw new RuntimeException("Timeout waiting for idle-percent metrics to initialize") | ||
| aggregateValue = aggregateMeter.oneMinuteRate() | ||
| brokerPerPoolValue = brokerPerPoolIdleMeter.oneMinuteRate() | ||
| controllerPerPoolValue = controllerPerPoolIdleMeter.oneMinuteRate() | ||
| } | ||
|
|
||
| // Verify that the meter shows reasonable idle percentage | ||
| assertTrue(aggregateValue >= 0.0 && aggregateValue <= 1.00, s"aggregate idle percent should be within [0,1], got $aggregateValue") | ||
| assertTrue(brokerPerPoolValue >= 0.0 && brokerPerPoolValue <= 1.00, s"broker per-pool idle percent should be within [0,1], got $brokerPerPoolValue") | ||
| assertTrue(controllerPerPoolValue >= 0.0 && controllerPerPoolValue <= 1.00, s"controller per-pool idle percent should be within [0,1], got $controllerPerPoolValue") | ||
|
|
||
| // Test pool resizing | ||
| // Shrink broker pool from 4 to 2 threads | ||
| brokerPool.resizeThreadPool(2) | ||
| assertEquals(2, brokerPool.threadPoolSize.get) | ||
| assertEquals(4, controllerPool.threadPoolSize.get) | ||
| assertEquals(6, factory.getAggregateThreads.get) | ||
|
|
||
| // Expand controller pool from 4 to 6 threads | ||
| controllerPool.resizeThreadPool(6) | ||
| assertEquals(2, brokerPool.threadPoolSize.get) | ||
| assertEquals(6, controllerPool.threadPoolSize.get) | ||
| assertEquals(8, factory.getAggregateThreads.get) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.