Skip to content

KAFKA-20750: Add divide-by-zero error check in KafkaConsumerMetrics/KafkaShareConsumerMetrics.#22718

Merged
AndrewJSchofield merged 2 commits into
apache:trunkfrom
ShivsundarR:KAFKA-20750
Jul 1, 2026
Merged

KAFKA-20750: Add divide-by-zero error check in KafkaConsumerMetrics/KafkaShareConsumerMetrics.#22718
AndrewJSchofield merged 2 commits into
apache:trunkfrom
ShivsundarR:KAFKA-20750

Conversation

@ShivsundarR

@ShivsundarR ShivsundarR commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added triage PRs from the community consumer clients small Small PRs labels Jul 1, 2026

@AndrewJSchofield AndrewJSchofield left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add some parentheses to make this easier to read.

double pollIdleRatio = pollCycleTimeMs == 0 ? 0.0 : (pollTimeMs * 1.0 / pollCycleTimeMs);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@AndrewJSchofield AndrewJSchofield merged commit 02c0ce9 into apache:trunk Jul 1, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants