-
Notifications
You must be signed in to change notification settings - Fork 843
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
Add file configuration ComponentProvider support for exporters #6493
Add file configuration ComponentProvider support for exporters #6493
Conversation
exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java
Outdated
Show resolved
Hide resolved
exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpConfigUtil.java
Outdated
Show resolved
Hide resolved
MetricExporter.class, | ||
exporterKeyValue.getKey(), | ||
exporterKeyValue.getValue()); | ||
return FileConfigUtil.addAndReturn(closeables, metricExporter); | ||
} | ||
|
||
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.
Is returning nulls from these Factory implementations a pattern that we like? I looked at the interface definition, and it didn't seem to imply that null return value was acceptable.
interface Factory<ModelT, ResultT> {
/**
* Interpret the model and create {@link ResultT} with corresponding configuration.
*
* @param model the configuration model
* @param spiHelper the service loader helper
* @param closeables mutable list of closeables created
* @return the {@link ResultT}
*/
ResultT create(@Nullable ModelT model, SpiHelper spiHelper, List<Closeable> closeables);
}
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 the contract of the parent Factory
interface should probably be adjusted.
Currently, the contract is ResultT create(@Nullable ModelT model, SpiHelper spiHelper, List<Closeable> closeables)
, so it can accept a null model but is always expected to either return (or throw). This is odd. Always returning when the model is null means that every type has to have some no-op or default representation, which is too strict. Throwing when the model is nullable is a weird pattern too. Why allow the model to be nullable if its just going to throw NPE?
So I think we (i.e. me) need to adjust the factory contract to be consistent: Either both the input model and response are nullabe, OR neither is nullable. And it seems best if neither the input or the response is null. This means that callers have to do some additional work to ensure they're not working with a null model, but should be a good thing in net.
If you're on board, I'll open up an issue and follow up. For the purposes of this PR, there is no appropriate MetricExporter to return when the input model is null, so we need to throw an exception or return null. Returning null is preferable because it is handled by the caller and we can generate a more appropriate error message in MetricReaderFactory
than we can in MetricExporterFactory
:
Lines 49 to 53 in 9a13f68
io.opentelemetry.sdk.metrics.export.MetricExporter metricExporter = | |
MetricExporterFactory.getInstance().create(exporterModel, spiHelper, closeables); | |
if (metricExporter == null) { | |
throw new ConfigurationException("exporter required for periodic reader"); | |
} |
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.
Seems totally reasonable to me to adjust the interface to reflect what appears to be the reality. The other Option (heh) would be to return Optional<ResultT>
from the interface, which might signal the correct semantics? Since this isn't a hot-path interface, I think we should at least consider it.
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.
Created #6612 to refactor away from using nullable in the factory contract. Not sure why I thought that was necessary, but it was clearly a mistake.
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.
Any thoughts on using Optional?
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 need for optional goes away when we embrace avoiding null
. Once you eliminate the ability for Factory
to accept a @Nullable
model, there aren't actually any cases where its useful to return Optional.empty()
. When model is always non-null, Factory
should always returns a valid component or throws ConfigurationException
.
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.
Doh! I completely misread what you did over in the other PR. Thanks! Great refactoring of that!
Generally seems good to me. A couple of comments provided. |
…y-java into component-provider-spis
@open-telemetry/java-approvers could use a look when you have a chance. Thanks! |
Followup to #6457, adding file configuration support for custom SpanExporter, MetricExporter, LogRecordExporter.
As a part of this, adds ComponentProvider implementations for all the exporters maintained in this module.