-
Notifications
You must be signed in to change notification settings - Fork 231
Load metrics factory service from classpath if available #433
Load metrics factory service from classpath if available #433
Conversation
8a849d3
to
43eef19
Compare
Codecov Report
@@ Coverage Diff @@
## master #433 +/- ##
============================================
+ Coverage 87.15% 87.45% +0.29%
- Complexity 510 512 +2
============================================
Files 65 65
Lines 1978 1985 +7
Branches 258 259 +1
============================================
+ Hits 1724 1736 +12
+ Misses 164 160 -4
+ Partials 90 89 -1
Continue to review full report at Codecov.
|
/** | ||
* Whether to skip loading a metrics factory from the classpath. Boolean. Optional. | ||
*/ | ||
public static final String JAEGER_SKIP_METRICS_FACTORY_LOADER = JAEGER_PREFIX + "SKIP_METRICS_FACTORY_LOADER"; |
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.
Do we need an env var to skip? Wouldn't it be good enough to just not include the dependency on the metrics factory?
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.
We never know what sort of crazy use cases people have. For instance, there might be someone extending our Micrometer Metrics Factory to build their own factory, so, they would have both dependencies on the classpath.
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.
Isn't it better to use ENV to define impl which would you like to load?
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.
The most appropriate thing to do for a Java application is to try to load implementations from the classpath using the service loader. The env var/property here is to skip the service loader entirely. Requiring an env var to specify an implementation isn't really idiomatic and wouldn't be the right direction, IMO.
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.
Maybe I didn't express well myself... I would never require conf property to specify the impl...
With ServiceLoader I have seen patterns (e.g jax-rs clientbuilder resolution) that it's possible to specify implementation by fully qualified class name in case if there are multiple impl on classpath. It's useful for test purposes or just when you have multiple implementations on class path and you want to choose a specific one.
So In this case, if there are multiple impls on classpath I would expect a way how I can specify the impl I want... Or if the env/prop is defined let's load it if not pick the first(random!) one.
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 see now what you mean.
How about we keep this idea as a separate issue and see whether this is actually needed? While the code for this would be easy to implement (Class.forName()
, basically), it's more code, and it's a code we aren't really sure will be used.
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 see that as a common practice rather than skip parameter. I am +1 on removing skip parameter and if necessary add parameter with FQCN in a separate PR (if you don't want to handle it here)
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.
Alright, the latest commit just removed the skip parameter.
There is also missing some documentation in readme how to use this with configuration. |
Changes to README added |
I have yet another comment :/. What about moving service loader method to a separate class? Then users can use with programmatic API. class MicricsFactoryProvider {
MetricsFactory newMetricsFactory() {
// service loader
}
}
```
And other suggestion. The service loader classes are usually in `spi` package. We could define `interface MicricsFactoryProvider` which would be used to provide the implementation rather then binding it directly to `MetricsFactory` |
That sounds reasonable for a "core" feature, but I don't think this is the case for the internal client metrics. I'm not sure enough people will care about it and will just be bloat :-/ |
I mean something like this https://stackoverflow.com/a/2956981/4158442. It's a nice design |
It's indeed a nice design and would probably make sense for core parts of the API. This PR is about a marginal feature. Let's implement what we need first. If people need a more fully featured SPI for the internal metrics, it's easy add in the future. |
I'm merging this as is and will let the discussion about a fully featured SPI loading mechanism as part of #436 |
Closes jaegertracing#339 Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
3fb58bf
to
9a82c6a
Compare
Signed-off-by: Juraci Paixão Kröhling juraci@kroehling.de
Closes #339