-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-16446: Improve controller event duration logging #15622
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ec2ce56
proof of concept
mumrah 238ce5a
wip
mumrah af04828
WIP
mumrah c20ec56
updates
mumrah 0172e81
Merge remote-tracking branch 'origin/trunk' into KAFKA-16446-log-slow…
mumrah b71ab8b
Merge remote-tracking branch 'origin/trunk' into KAFKA-16446-log-slow…
mumrah c010cb4
pr feedback
mumrah 23dff09
Merge remote-tracking branch 'origin/trunk' into KAFKA-16446-log-slow…
mumrah d23e4af
pr feedback
mumrah 7676dd4
Merge remote-tracking branch 'origin/trunk' into KAFKA-16446-log-slow…
mumrah a2ded76
set eventPerformanceMonitor earlier
mumrah 17acae0
Merge remote-tracking branch 'origin/trunk' into KAFKA-16446-log-slow…
mumrah 8993f10
logging changes etc.
cmccabe 9323eef
Merge branch 'trunk' into KAFKA-16446-log-slow-events
cmccabe dee71c4
nanosecondsToDecimalMillis -> formatNsAsDecimalMs
cmccabe 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
85 changes: 85 additions & 0 deletions
85
metadata/src/main/java/org/apache/kafka/controller/SlowEventsLogger.java
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * 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 org.apache.kafka.controller; | ||
|
|
||
| import org.apache.kafka.common.utils.LogContext; | ||
|
|
||
| import org.slf4j.Logger; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
| import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
|
|
||
| /** | ||
| * Track the p99 for controller event queue processing time. If we encounter an event that takes longer | ||
| * than this cached p99 time, we will log it at INFO level on the controller logger. | ||
| */ | ||
| public class SlowEventsLogger { | ||
| /** | ||
| * Don't report any p99 events below this threshold. This prevents the controller from reporting p99 event | ||
| * times in the idle case where p99 event times are essentially the average as well. | ||
| */ | ||
| private final long minSlowEventTimeNs; | ||
|
|
||
| /** | ||
| * Function that returns the current p99 time in millis. This call can be expensive, and since the histogram is | ||
| * biased towards the last 5 minutes of data, we only need to update this p99 every so often. | ||
| */ | ||
| private final Supplier<Double> thresholdMsSupplier; | ||
|
|
||
| private final Logger log; | ||
|
|
||
| /** | ||
| * The current p99 threshold in nanos. | ||
| */ | ||
| private long thresholdNs; | ||
|
|
||
| public SlowEventsLogger( | ||
| int minSlowEventTimeMs, | ||
| Supplier<Double> thresholdMsSupplier, | ||
| LogContext logContext | ||
| ) { | ||
| this.minSlowEventTimeNs = MILLISECONDS.toNanos(minSlowEventTimeMs); | ||
| this.thresholdMsSupplier = thresholdMsSupplier; | ||
| this.thresholdNs = minSlowEventTimeMs; | ||
| this.log = logContext.logger(SlowEventsLogger.class); | ||
| } | ||
|
|
||
| /** | ||
| * Produce an INFO log if the given event ran for at least as long as the current p99 event processing time. | ||
| * | ||
| * @return true if a slow event was logged, false otherwise. | ||
| */ | ||
| public boolean maybeLogEvent(String name, long durationNs) { | ||
| if (durationNs >= minSlowEventTimeNs && durationNs >= thresholdNs) { | ||
| log.info("Slow controller event {} processed in {} us which is larger or equal to the p99 of {} us", | ||
| name, | ||
| NANOSECONDS.toMicros(durationNs), | ||
| NANOSECONDS.toMicros(thresholdNs) | ||
| ); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public void refreshPercentile() { | ||
| thresholdNs = (long) (thresholdMsSupplier.get() * 1000000); | ||
| log.trace("Update slow controller event threshold (p99) to {} us.", NANOSECONDS.toMicros(thresholdNs)); | ||
| } | ||
| } |
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
89 changes: 89 additions & 0 deletions
89
metadata/src/test/java/org/apache/kafka/controller/SlowEventsLoggerTest.java
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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 org.apache.kafka.controller; | ||
|
|
||
| import org.apache.kafka.common.utils.LogContext; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
|
|
||
| public class SlowEventsLoggerTest { | ||
| @Test | ||
| public void testSlowEvents() { | ||
| LogContext logContext = new LogContext(); | ||
|
|
||
| AtomicReference<Double> p99 = new AtomicReference<>(0.0); | ||
| SlowEventsLogger logger = new SlowEventsLogger(100, p99::get, logContext); | ||
|
|
||
| // Initially, the p99 is zero | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(10))); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(99))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(100))); | ||
|
|
||
|
|
||
| // Idle controller, low p99 | ||
| p99.set(30.0); | ||
| logger.refreshPercentile(); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(90))); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(99))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(100))); | ||
|
|
||
| // Busy controller, high p99 | ||
| p99.set(1000.0); | ||
| logger.refreshPercentile(); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(100))); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(200))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(1000))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(2000))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testThresholdDisabled() { | ||
| LogContext logContext = new LogContext(); | ||
|
|
||
| AtomicReference<Double> p99 = new AtomicReference<>(0.0); | ||
| // Set min slow event time to zero, effectively disabling the threshold | ||
| SlowEventsLogger logger = new SlowEventsLogger(0, p99::get, logContext); | ||
|
|
||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(0))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(10))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(99))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(100))); | ||
|
|
||
| p99.set(30.0); | ||
| logger.refreshPercentile(); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(0))); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(29))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(30))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(100))); | ||
|
|
||
|
|
||
| p99.set(1000.0); | ||
| logger.refreshPercentile(); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(100))); | ||
| assertFalse(logger.maybeLogEvent("test", MILLISECONDS.toNanos(999))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(1000))); | ||
| assertTrue(logger.maybeLogEvent("test", MILLISECONDS.toNanos(2000))); | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though there are no code paths that change the value, within the scope of
QuorumController.Builderthis is in fact a default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand your comment. Are you just agreeing with the change to
DEFAULT_or something else?