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
KAFKA-9219: prevent NullPointerException when polling metrics from Kafka Connect #7652
Conversation
Thanks for the PR. |
metrics.addMetric(metrics.metricName("assigned-tasks", | ||
this.metricGrpName, | ||
"The number of tasks currently assigned to this consumer"), numTasks); | ||
if (assignmentSnapshot != null) { |
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.
With this change, if assignmentSnapshot
is null when we enter this constructor, the metrics will never get registered, even if it gets initialized shortly after.
Should we still register the metrics, and return Double.NaN
in both measure()
method if assignmentSnapshot
is null?
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.
@mimaison that sounds a good option that I have also considered. Let me make this change :)
09fb4a1
to
bb4ec47
Compare
@mimaison updated the pr, please take another review |
@ning2008wisc I would consider returning |
…onnect `assignmentSnapshot` may not always get initialized in some cases, especially when Kafka connect is started from scratch. If `assignmentSnapshot` is not initialized, blindly resgistering `assigned-connectors` and `assigned-tasks` metrics will cause NullPointerException when the two metrics are polled. the proposed fix is to return 0 in both measure() method if `assignmentSnapshot` is null
bb4ec47
to
f70454e
Compare
@edoardocomar updated the pr to return |
assignmentSnapshot
may not always get initialized in some cases. IfassignmentSnapshot
is not initialized, registeringassigned-connectors
andassigned-tasks
metrics upfront will causeNullPointerException when the two metrics are polled via JmxReporter later
Committer Checklist (excluded from commit message)