Skip to content
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

Merged
merged 1 commit into from
Aug 2, 2018

Conversation

zd-project
Copy link
Contributor

STORM-3150

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved in #2771

Copy link
Contributor

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:

  1. put the changes to the patch where is using these methods
  2. Port the changes in STORM-3157: General improvement to StormMetricsRegistry #2771 about registerMetricSet and unregisterMetricSet here. This is to avoid to change the same methods multiple times.

I prefer option 1.

Copy link
Contributor Author

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?

@srdo
Copy link
Contributor

srdo commented Jul 24, 2018

+1, thanks for your patience. Please squash to one commit, and I'll merge.

@zd-project
Copy link
Contributor Author

Okay thanks. Can you also help reviewing #2771? If you think merging two PR is better.

@srdo
Copy link
Contributor

srdo commented Jul 24, 2018

Yes, I'll take a look.

Copy link
Contributor

@Ethanlm Ethanlm left a 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

Copy link
Contributor

@revans2 revans2 left a 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

@zd-project zd-project Jul 27, 2018

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.

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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

@zd-project
Copy link
Contributor Author

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?

@srdo
Copy link
Contributor

srdo commented Jul 31, 2018

@zd-project I think we can merge this immediately. Could you please squash back to one commit?

@zd-project
Copy link
Contributor Author

@srdo I've squashed the commits. Sorry about the delay.

STORM-3150: Simplify gauge registration method.
@asfgit asfgit merged commit 4d43947 into apache:master Aug 2, 2018
@srdo
Copy link
Contributor

srdo commented Aug 2, 2018

@zd-project Merged, thanks for your patience. JIRA is down right now, will update the ticket when it comes back up.

@zd-project zd-project deleted the STORM-3150 branch August 2, 2018 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants