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

Deprecate setMetricRegistry in favour of setMetricsTrackerFactory #1091

Closed

Conversation

NersesAM
Copy link
Contributor

@NersesAM NersesAM commented Feb 19, 2018

Following up on my yesterday's PR #1089.
Even though it is ok, I think the fact of accepting an Object and then doing tricks to find out wether the library class is in classpath and later on casting the object to correct type are not very nice.
This is especially not great in light of Change in dropwizard metrics package name in upcoming v5. For some time we will need to support both versions. This will add even more complexity in that part of the code.

That's why I propose to deprecate/delete setMetricRegistry in favour of setMetricsTrackerFactory. Also by providing overloaded static factory methods in the MetricsTrackerFactory interface we won't need to do type checks at all. Users can just use setMetricsTrackerFactory(from(metricRegistry)) instead of setMetricRegistry(metricRegistry) allowing to greatly simplify code around registering metricRegsitry .
This is preliminary PR just to get your feedback. Can update it with complete removal.
WDYT?

… provide static factory methods in the interface.
@codecov
Copy link

codecov bot commented Feb 19, 2018

Codecov Report

Merging #1091 into dev will decrease coverage by 0.75%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev    #1091      +/-   ##
============================================
- Coverage     72.98%   72.23%   -0.76%     
+ Complexity      557      551       -6     
============================================
  Files            24       24              
  Lines          1940     1945       +5     
  Branches        258      261       +3     
============================================
- Hits           1416     1405      -11     
- Misses          369      372       +3     
- Partials        155      168      +13
Impacted Files Coverage Δ Complexity Δ
src/main/java/com/zaxxer/hikari/HikariConfig.java 68.18% <ø> (-2.5%) 125 <0> (ø)
.../main/java/com/zaxxer/hikari/HikariDataSource.java 65.04% <ø> (-6.04%) 29 <0> (-4)
...c/main/java/com/zaxxer/hikari/pool/HikariPool.java 83.96% <ø> (+1.13%) 58 <0> (ø) ⬇️
src/main/java/com/zaxxer/hikari/pool/PoolBase.java 69.48% <0%> (-0.23%) 52% <0%> (-2%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 36ffcaf...c084d54. Read the comment docs.

@@ -26,4 +31,13 @@
* @return a IMetricsTracker implementation instance
*/
IMetricsTracker create(String poolName, PoolStats poolStats);

static MetricsTrackerFactory from(MetricRegistry metricRegistry) {
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 think MetricsTrackerFactory should contain references to implementation specific code.

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 didn't want to create MetricsTrackerFactoryFactory :)
This seems not right at first but in JDK itself starting from 9 there are lots of examples like this. For example List.of(...)

Do you want me to revert this file so that users have to do setMetricsTrackerFactory(new CodahaleMetricsTrackerFactory(metricRegistry)) instead?

Copy link
Contributor

@johnou johnou Feb 19, 2018

Choose a reason for hiding this comment

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

I think that makes more sense, that way there is no risk of CNFE and it makes it easier to deprecate the old metrics tracker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no risk of CNFE here if that's your concern. This method cannot be invoked without creating MetricRegistry first. Which means the class will already be loaded by JVM before reaching this point.
When deprecating corresponding metricsTracker implementation this factory method can be deprecated at the same time.

Copy link
Contributor

Choose a reason for hiding this comment

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

More concerned about it being too tightly coupled.

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.

3 participants