-
Notifications
You must be signed in to change notification settings - Fork 207
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
Di server #846
Di server #846
Conversation
Codecov Report
@@ Coverage Diff @@
## main #846 +/- ##
============================================
- Coverage 92.21% 91.40% -0.81%
- Complexity 660 672 +12
============================================
Files 80 82 +2
Lines 1940 1955 +15
Branches 164 165 +1
============================================
- Hits 1789 1787 -2
- Misses 110 129 +19
+ Partials 41 39 -2
Continue to review full report at Codecov.
|
@Bean | ||
public Optional<MeterRegistry> prometheusMeterRegistry( | ||
final DataPrepperConfiguration dataPrepperConfiguration, | ||
final Optional<Authenticator> optionalAuthenticator, |
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.
Taking an Optional
as an argument is not a good practice. You have no non-null guarantees here, so you should do a null check, which somewhat defeats the purpose.
I noticed this in a few places. Please change these to just take the argument in without the Optional wrapper.
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.
Depending on your Data Prepper configuration and Pipeline an Authenticator Bean may not be created / available. By default, if a requested bean is not available Spring will abort startup throwing an exception. We have three options in how to handle a case like this:
- Always create an Authenticator, then use it based on configuration.
- Wrapping the dependency as an Optional - JSR-330 compliant and would require the lease amount of refactoring if we switch to another DI framework like Dagger
- Use the Spring native functionality @Autowired(required = false)
Another good example to consider is when creating the CloudWatchMeterRegistry. If the CloudWatchMeterRegistry is not configured, creating an instance of it cloud cause an exception to be thrown,
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.
@sbayer55, why not go with option 1? That sounds like it decouples DP with a dependency framework and won't require passing optionals around.
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.
Option 1 presents issues with classes like CloudWatchMeterRegistry that would need additional refactoring. Option 3 is a happy middle ground. We remove the need for optionals while limiting the scope of this PR.
@@ -55,4 +57,9 @@ public DataPrepperConfiguration dataPrepperConfiguration( | |||
return new DataPrepperConfiguration(); | |||
} | |||
} | |||
|
|||
@Bean | |||
public Optional<PluginModel> pluginModel(final DataPrepperConfiguration dataPrepperConfiguration) { |
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.
This value is the authentication. So this method should be renamed to authentication
from pluginModel
.
@Bean | ||
public CompositeMeterRegistry systemMeterRegistry( | ||
final List<MeterBinder> meterBinders, | ||
final DataPrepperConfiguration dataPrepperConfiguration | ||
final List<Optional<MeterRegistry>> optionalMeterRegistries |
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.
This List<Optional<MeterRegister>>
should be just List<MeterRegistery>
.
@@ -23,7 +23,7 @@ | |||
class PluginCreator { | |||
private static final Logger LOG = LoggerFactory.getLogger(PluginCreator.class); | |||
|
|||
<T> T newPluginInstance(final Class<T> pluginClass, | |||
public <T> T newPluginInstance(final Class<T> pluginClass, |
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.
This shouldn't be public. The class itself is already package protected, and keeping the method package protected is clearer.
|
||
final PrometheusMetricsHandler metricsHandler = new PrometheusMetricsHandler(meterRegistry); | ||
|
||
final List<HttpContext> contextList = new ArrayList<>(2); |
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.
This bean creation has two distinct concerns involved: 1) Creating the MeterRegistry
and 2) setting up the HttpServer to support it. It would be better to have a different construct handle the second concern. Perhaps there can be different beans for "server contexts" and then the HttpServer
bean can assemble them all.
final Optional<PluginModel> optional = appConfiguration.pluginModel(configuration); | ||
|
||
assertThat(optional.isPresent(), is(false)); | ||
verify(configuration, times(1)).getAuthentication(); |
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.
FYI, verify
already works only for one time. So you don't need times(1)
- it is the default behavior.
@Bean | ||
public Optional<MeterRegistry> prometheusMeterRegistry( | ||
final DataPrepperConfiguration dataPrepperConfiguration, | ||
final Optional<Authenticator> optionalAuthenticator, |
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.
@sbayer55, why not go with option 1? That sounds like it decouples DP with a dependency framework and won't require passing optionals around.
data-prepper-core/src/main/java/com/amazon/dataprepper/pipeline/server/DataPrepperServer.java
Show resolved
Hide resolved
Please update the PR description and fill in the template. |
@sbayer55 , please update the PR with a description of the change and fill in the template. |
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.
Thanks! This looks good!
data-prepper-core/src/main/java/com/amazon/dataprepper/plugin/DefaultPluginFactory.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
…ctor Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
…uration Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
…eation and config Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Signed-off-by: Steven Bayer <[email protected]>
Description
Refactor Data Prepper Server to use dependency injection
Issues Resolved
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.