generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 6
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
ADR about Application Context Supporting Different Implementations Per Thread #1690
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 27. Application Context Supporting Different Implementations Per Thread | ||
|
||
Date: 2025-01-13 | ||
|
||
## Decision | ||
|
||
One normally registers an implementation in the application context, and it stays that way for the entire execution of | ||
the program. We have added the ability for us to swap out different implementations on a thread-by-thread basis. | ||
|
||
## Status | ||
|
||
Accepted. | ||
|
||
## Context | ||
|
||
For load testing in a real environment, we decided that we didn't want to send that load testing data onto ReportStream, | ||
but we also didn't want to do a special deploy or feature flag that would temporarily disable the sending of data to | ||
ReportStream. Instead, we wanted TI to be able to handle real data while also handling fake, load test data at the same | ||
time. | ||
|
||
Because each HTTP request is handled on its own thread, we are able to change the ReportStream client implementation | ||
between the real one or a mock one depending on whether a load test HTTP request header is passed in or not. | ||
|
||
A new method was added called `ApplicationContext#registerForThread`. | ||
|
||
## Impact | ||
|
||
### Positive | ||
|
||
- We can now change implementations on an HTTP request-by-request (thread-by-thread) basis. | ||
- We can load test TI without load testing RS while still handling legitimate traffic. | ||
|
||
## Negative | ||
|
||
- We can't use `@Inject` for classes that we decide to start swapping out. Injecting registered implementations into | ||
`@Inject` fields only happens on bootstrap which is before any HTTP requests are handled. Calling | ||
`ApplicationContext#injectRegisteredImplementations` after swapping out an implementation and hoping it works with | ||
`@Inject` will not work because our program is multithreaded and we use singletons. So, that `@Inject` field is used | ||
by many HTTP requests, some of which may not want a swapped out implementation. The solution to this is to use | ||
`ApplicationContext#getImplementation` in the method that requires the implementation. For example, see | ||
`RSEndpointClient`; we never `@Inject` it anywhere now, but instead we use `ApplicationContext#getImplementation`. | ||
- Specifically for the load testing, we need to remember to duplicate the logic that swaps out the ReportStream client | ||
implementation to any new HTTP endpoint that can call ReportStream. If we forget, then we risk calling ReportStream a lot during load tests. | ||
|
||
### Risks | ||
|
||
- There are nuances to using this new mechanism of ApplicationContext that can lead to bugs. For example, thinking you can still use `@Inject`. | ||
- Specifically for the load testing, forgetting to duplicate the logic that swaps out the ReportStream client on a new | ||
HTTP endpoint that will call ReportStream. | ||
|
||
## Related Issues | ||
|
||
#1122. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
That's pretty cool