KAFKA-20750: Add divide-by-zero error check in KafkaConsumerMetrics/KafkaShareConsumerMetrics.#22718
Merged
Merged
Conversation
AndrewJSchofield
requested changes
Jul 1, 2026
AndrewJSchofield
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR. Just a couple of legibility comments.
| long pollTimeMs = pollEndMs - pollStartMs; | ||
| double pollIdleRatio = pollTimeMs * 1.0 / (pollTimeMs + timeSinceLastPollMs); | ||
| long pollCycleTimeMs = pollTimeMs + timeSinceLastPollMs; | ||
| double pollIdleRatio = pollCycleTimeMs == 0 ? 0.0 : pollTimeMs * 1.0 / pollCycleTimeMs; |
Member
There was a problem hiding this comment.
I'd add some parentheses to make this easier to read.
double pollIdleRatio = pollCycleTimeMs == 0 ? 0.0 : (pollTimeMs * 1.0 / pollCycleTimeMs);
Contributor
Author
There was a problem hiding this comment.
Thanks, I have updated it now.
| long pollTimeMs = pollEndMs - pollStartMs; | ||
| double pollIdleRatio = pollTimeMs * 1.0 / (pollTimeMs + timeSinceLastPollMs); | ||
| long pollCycleTimeMs = pollTimeMs + timeSinceLastPollMs; | ||
| double pollIdleRatio = pollCycleTimeMs == 0 ? 0.0 : pollTimeMs * 1.0 / pollCycleTimeMs; |
AndrewJSchofield
approved these changes
Jul 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
https://issues.apache.org/jira/browse/KAFKA-20750
During testing it was observed that the poll idle ratio metric was
showing NaN even when the fetches were happening successfully. This was
a case when there were fast polls (sub-millisecond values) leading to a
divide by zero error. PR adds a check and sets the value to 0 in such
cases.
Reviewers: Andrew Schofield aschofield@confluent.io