-
Notifications
You must be signed in to change notification settings - Fork 217
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
ft-reaper-improvements-final small npe fix #111
ft-reaper-improvements-final small npe fix #111
Conversation
try{ | ||
hostProxy = context.jmxConnectionFactory.connect(hostName); | ||
connected = true; | ||
hostMetrics = getMetricsForHost(hostName, hostProxy); |
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.
Moving this here won't work because if we cannot connect to one host through JMX (which will happen in multi region clusters) then Reaper won't look if metrics are already there in storage, which it does here : https://github.com/thelastpickle/cassandra-reaper/blob/ft-reaper-improvements-final/src/main/java/com/spotify/reaper/service/SegmentRunner.java#L417-L436
The error are only displayed in DEBUG so it shouldn't clutter the logs.
In which conditions did you get a NPE ?
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.
hostProxy can be null
(either context.jmxConnectionFactory.connect(hostName)
throws an exception or returns null.
before getMetricsForHost(..)
would throw a NPE that wasn't caught.
now it's caught, and subsequently gotMetricsForAllHosts
is correctly set to false.
2d8c98d
to
ea3b853
Compare
@michaelsembwever : I've reworked the patch a bit, using Optional<> to avoid the NPE. Thanks |
LGTM. Personally, I would have avoided changing so many lines of code on a living feature-branch. But that's me. Presuming you'll rebase the commits to one before merging. |
ea3b853
to
8bf0b8c
Compare
try{ | ||
Optional<HostMetrics> hostMetrics; | ||
Optional<HostMetrics> hostMetrics = Optional.absent(); |
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.
SonarQube analysis reported 3 issues Watch the comments in this conversation to review them. 1 extra issueNote: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:
|
try{ | ||
Optional<HostMetrics> hostMetrics; | ||
Optional<HostMetrics> hostMetrics = Optional.absent(); | ||
try{ |
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.
Avoid NPE when jmx is unreachable, when getting metrics for host