-
Notifications
You must be signed in to change notification settings - Fork 973
Add decorator support for ServiceErrorHandler #6570
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
Open
0x1306e6d
wants to merge
3
commits into
line:main
Choose a base branch
from
0x1306e6d:service-error-handler-decorator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−94
Open
Changes from all commits
Commits
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Question) Since the
ServiceErrorHandleris decorated, is there still a need to decorate theServerErrorHandler?e.g. the following diff seems to still pass the test:
The concern is that implementors of the default
ErrorHandlerDecorators#decoratorFunctionsneed to be aware that eachDecoratingErrorHandlerFunctionmay be applied twice.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 a good finding. I think we need to remove the decorating here:
armeria/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Line 2338 in 69ba77d
and add it here instead:
armeria/core/src/main/java/com/linecorp/armeria/server/DefaultServerConfig.java
Line 261 in 603fc86
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!
Regardless, I found another edge case where the content preview is not recorded. An
HttpResponsecan be created directly viarenderStatus(...)when it is anAbortedHttpResponse. If a service returnsHttpResponse.ofFailure(HttpResponseException(...))without an error handler, the error response is created usingrenderStatus(...)directly:armeria/core/src/main/java/com/linecorp/armeria/server/AbstractHttpResponseSubscriber.java
Lines 275 to 278 in 897b5a0
armeria/core/src/main/java/com/linecorp/armeria/server/AbstractHttpResponseHandler.java
Lines 202 to 211 in 897b5a0
Because
onServiceException(...)is not called with the returned response, the request log does not complete. My idea is to apply the same decorating logic to the response returned from the delegate’srenderStatus(...).I’m unsure whether there is any chance the decorator could be applied twice. For example, via
renderStatus(...)->FallbackService->ContentPreviewingServiceorCorsService.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.
Good catch, there's definitely an edge case here.
Plus, it looks like we're generating a content preview even when a preceding decorator fails, which we shouldn't be doing.
What do you think about preventing the preview from being generated whenever an exception is raised?
Since we already set the preview to null on an exception in DefaultRequestLog, this seems like the right fix.
armeria/core/src/main/java/com/linecorp/armeria/common/logging/DefaultRequestLog.java
Lines 1471 to 1473 in d068172
I think we could set the preview to null at these two spots to solve it:
armeria/core/src/main/java/com/linecorp/armeria/server/logging/ContentPreviewingService.java
Line 178 in 1aed83b
armeria/core/src/main/java/com/linecorp/armeria/internal/logging/ContentPreviewingUtil.java
Line 118 in 0fc9cd1
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.
Indeed, because content preview generation is done after the response is processed by the recovery step and whether the content preview decorator was actually executed is not considered.
If so, should we generate the preview for an aborted response (
HttpResponse.ofFailure(...))? I’m a bit confused about whatContentPreviewErrorHandlerwould do if we choose this behavior.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.
Glad to hear that. I agree that #6577 is the ultimate goal for addressing all of these issues.
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.
@0x1306e6d So, could you fix this PR to always complete the request log?
Uh oh!
There was an error while loading. Please reload this page.
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 don't fully understand what 'always complete the request log' means. Could you please provide more details? If you meant setting the content preview to null for failed responses, I’m unsure how to retrieve the failed response preview until #6577 is available.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah, that's what I meant. 😉
I initially thought we should prioritize the completeness of the request log, even if it meant disabling the content preview on failed responses. The idea was to ship this fix before #6577.
However, we already released 1.35.0 and Since #6577 will likely be included in the next release, we can probably wait for that.
So if you don't want to apply the workaround for this PR, I think we can just close this PR and implement #6577.
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. I added a commit to ensure the termination of
RequestLog, and #6577 will provide the fundamental fix for the content preview.One question I have is that the
RequestLogtermination may have different characteristics from the original PR. Also,CorsServicerequires aServiceErrorHandlerdecorator. Shouldn’t we separate these into different PRs for better management?