-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
STORM-3150: Improve Gauge registration methods and refactored code #2763
Conversation
@@ -2809,21 +2809,19 @@ public void launchServer() throws Exception { | |||
} | |||
}); | |||
|
|||
//Be cautious using method reference instead of lambda. subexpression preceding :: will be evaluated only upon evaluation |
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.
Nit: Not sure about this comment, it's not really specific to this code, but applies to any use of method references anywhere.
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.
Sorry I was writing this to myself because I was not super familiar with Java lambda. Should probably delete it as it's not relevant to code.
.sum()); | ||
StormMetricsRegistry.registerGauge("nimbus:available-cpu", () -> nodeIdToResources.get().values().parallelStream().mapToDouble( | ||
SupervisorResources::getAvailableCpu).sum()); | ||
.mapToDouble(SupervisorResources::getAvailableMem).sum()); |
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.
Nit: I think the readability of method chaining is improved by having one call per line, e.g.
x.stream
.map
.collect
rather than
x.stream
.map.collect
It's a super minor complaint though.
} | ||
}; | ||
return register(name, gauge); | ||
return 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.
Why does it make sense to return null rather than 0?
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.
Because we are using generic type now. In addition reporters from metrics package seem to be handling null case gracefully so I think it's safe to use. That being said I should probably add this in the doc or notify people in some way if they want to inherit custom reporter.
} | ||
return 0; | ||
/** | ||
* Register a gauge with provided callback. |
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.
Nit: Consider adding a note that this handles exceptions thrown from the callback.
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.
Should I note so in the JavaDoc then?
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.
Yes please :)
public static void registerProvidedGauge(final String name, Gauge gauge) { | ||
/** | ||
* Register a provided gauge. Use this method if custom gauges is needed or | ||
* no checked exceptions should be handled. |
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.
Nit: Consider rephrasing as "or exceptions should not be handled"
return register(name, new Histogram(reservoir)); | ||
} | ||
|
||
public static void registerAll(final String prefix, MetricSet metrics) { |
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.
Why is this method necessary?
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.
This is used in #2764. Should move the change there?
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.
Having it here is fine, but I'm not sure I understand what it does differently from just calling the register method directly? Is it just for clarity?
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.
For wrapper to the private register()
method. I don't see any problem if we should make register
public though.
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 think it's a little weird to have this and unregister
be public, but not the generic register
method.
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 don't have a strong opinion on this, but making the register
method public might make for a nicer API, especially since unregister
can unregister any kind of metric.
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'll have to think about this a bit more, since I will have a few more PR depending on this. The way MetricRegistry
handles MetricSet
under the hood is a bit wacky, and they haven't supported removeAll(MetricSet set)
method in their release yet. Do you have any advice of improving StormMetricsRegistry
in general?
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.
Improved in #2771
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 like the idea of having registerMetricSet
and unregisterMetricSet
in #2771 better.
But to make the commit history easier to understand, I would suggest one of the following options:
- put the changes to the patch where is using these methods
- Port the changes in STORM-3157: General improvement to StormMetricsRegistry #2771 about
registerMetricSet
andunregisterMetricSet
here. This is to avoid to change the same methods multiple times.
I prefer option 1.
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.
Okay, should I first merge change in this PR into #2771 and then port them to where they are actually invoked?
+1, thanks for your patience. Please squash to one commit, and I'll merge. |
Okay thanks. Can you also help reviewing #2771? If you think merging two PR is better. |
Yes, I'll take a look. |
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.
Overall it looks good to me. Left some comment
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.
Just a few nits.
* @param <V> type of measurement the callback returns, also the type of gauge | ||
* @return registered gauge | ||
*/ | ||
public static <V> Gauge<V> registerGauge(final String name, final Callable<V> fn) { |
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.
Could we just change this to take a guage instead?
public static <V> Gauge<V> registerGauge(final String name, final Gauge<V> gauge) {
return register(name, gauge);
}
We are not calling this from clojure anymore so we didn't need the Callable any more, and for the most part there are no code changes to make this happen.
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.
Callable seems to be existed only for swallowing exceptions now. I don't know if this is part of the original design but I don't see a problem eliminating so.
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.
Please do I don't see a reason to keep it here
return blacklistHost.size(); | ||
} | ||
}); | ||
//nimbus:num-blacklisted-supervisor + none blacklisted supervisor = nimbus:num-supervisors |
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.
nit: I have no idea what this comment means, so could we remove it? Unless you understand it, then can we make it clearer?
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.
It looks to me that there's a typo: nimbus:num-blacklisted-supervisor + non-blacklisted supervisor = nimbus:num-supervisors
All nits are addressed and PR is rebased on current master branch. Do you want to merge this PR right now or merge this together with #2771? |
@zd-project I think we can merge this immediately. Could you please squash back to one commit? |
@srdo I've squashed the commits. Sorry about the delay. |
STORM-3150: Simplify gauge registration method.
@zd-project Merged, thanks for your patience. JIRA is down right now, will update the ticket when it comes back up. |
STORM-3150