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

allow to configure Reservoir implementations #20

Merged
merged 4 commits into from
Feb 19, 2018

Conversation

McFoggy
Copy link
Contributor

@McFoggy McFoggy commented Jan 29, 2018

simple enhancement of MetricsConfiguration class to be able to register a ReservoirBuilder class allowing for specific Reservoir instances to be used in produced Timer & Histogram

introduction of a setting in the MetricsConfiguration class
to be able to configure the Reservoir implementation to use for
produced Timer & Histogram instances.

see astefanutti#12
@coveralls
Copy link

coveralls commented Jan 29, 2018

Coverage Status

Coverage increased (+0.005%) to 94.634% when pulling dafb23b on McFoggy:custom-reservoirs into 3b64cfa on astefanutti:master.

@McFoggy
Copy link
Contributor Author

McFoggy commented Jan 29, 2018

@astefanutti do you know why the coverage decreased even if a test covering the new behavior is included in the PR?

@astefanutti
Copy link
Owner

@McFoggy Thanks for the PR. Regarding the coverage, it looks like your test returns null which is only one logic branch. I think that explains the difference. Otherwise, I'll review the PR in depth ASAP.

@McFoggy
Copy link
Contributor Author

McFoggy commented Jan 29, 2018

You're right! I'll add more tests to cover the other branch.

@McFoggy
Copy link
Contributor Author

McFoggy commented Jan 29, 2018

If you want me to squash, do not hesitate to ask.

@@ -63,7 +81,24 @@ private static Meter meter(InjectionPoint ip, MetricRegistry registry, MetricNam
}

@Produces
private static Timer timer(InjectionPoint ip, MetricRegistry registry, MetricName metricName) {
return registry.timer(metricName.of(ip));
private static Timer timer(InjectionPoint ip, MetricRegistry registry, MetricName metricName, MetricsExtension extension) {
Copy link
Owner

Choose a reason for hiding this comment

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

The same logic is missing from the MetricsInterceptor as we want to apply the custom reservoir to metrics created by interceptors as well for timers.

* @return this Metrics CDI configuration
* @throws IllegalStateException if called outside of the observer method invocation
*/
MetricsConfiguration useReservoirBuilder(ReservoirBuidler builder);
Copy link
Owner

Choose a reason for hiding this comment

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

I would add a default implementation to avoid breaking existing implementation. That requires Java 8 and Metrics CDI still builds on Java 7. That being said, I'd be inclined to drop Java 7 for that and other benefits.

Set<MetricsParameter> getParameters() {
return Collections.unmodifiableSet(configuration);
}

ReservoirBuidler getReservoirBuilder() {
Copy link
Owner

Choose a reason for hiding this comment

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

I created an EnumSet so that we could add other configuration parameters. I wonder whether we change it to EnumMap and add the ReservoirBuidler configuration to it. The idea being that it avoids having to much getters.

* @param type the kind of metric for which a reservoir is required
* @return the reservoir to use, or null if default reservoir implementation has to be used
*/
Reservoir build(String metricName, ReservoirUsage type);
Copy link
Owner

Choose a reason for hiding this comment

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

Why not passing the metric class instead of creating a new ReservoirUsage object?

Copy link
Owner

Choose a reason for hiding this comment

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

I wonder whether returning Optional<Reservoir> would better capture the defaulting rather than returning null. That requires Java 8 but as previously said, I'm inclined to drop Java 7.

configuration.useReservoirBuilder(new ReservoirBuidler() {
@Override
public Reservoir build(String metricName, ReservoirUsage type) {
counter.incrementAndGet();
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder whether we could have a more functional test assertion rather than just checking that the build has actually being called. Not a big deal, but I'd rather have functional assertions than technical ones whenever possible.

@McFoggy
Copy link
Contributor Author

McFoggy commented Feb 19, 2018

@astefanutti I have adapted a bit the PR to integrate your remarks.

I have not changed:

  • the EnumeSet into EnumMap: I can do it if you think it is required
  • the tests to make them functional: here honestly I do not understand why a technical test like the one provided is not enough to ensure that the functionnality is correctly used ; imho in this situation writing a dedicated ReservoirBuilder building "functionally testable" Reservoirs would be far more work than what is required and provided by the PR to ensure the correctness.

@astefanutti
Copy link
Owner

@McFoggy

I have adapted a bit the PR to integrate your remarks.

Thanks a lot. That looks great!

I have not changed:

the EnumeSet into EnumMap: I can do it if you think it is required

I can do it, no big deal.

the tests to make them functional: here honestly I do not understand why a technical test like the one provided is not enough to ensure that the functionnality is correctly used ; imho in this situation writing a dedicated ReservoirBuilder building "functionally testable" Reservoirs would be far more work than what is required and provided by the PR to ensure the correctness.

It's more a matter of style and I appreciate that this is going to be a lot more work in that case. So that's perfectly ok.

@astefanutti astefanutti merged commit f1cbe1a into astefanutti:master Feb 19, 2018
@McFoggy McFoggy deleted the custom-reservoirs branch February 19, 2018 10:33
@astefanutti
Copy link
Owner

Thanks for the PR. You may want to associate your matthieu at brouilard.fr address to your GitHub account.

@McFoggy
Copy link
Contributor Author

McFoggy commented Feb 19, 2018

Thanks for the info, but in fact it is a mistake in the git config if the clone in which I did the latest changes. It should have been brouillard with 2 L ; too late to change the commit.

@astefanutti
Copy link
Owner

astefanutti commented Feb 19, 2018

@McFoggy I've just fixed the history 👌. I'll do a release ASAP.

@McFoggy
Copy link
Contributor Author

McFoggy commented Feb 19, 2018

Thank you Antoine.

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.

None yet

3 participants