-
Notifications
You must be signed in to change notification settings - Fork 895
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 ExceptionReportingServerErrorHandler
to log unhandled exceptions
#4687
Conversation
…nSeconds` to `ServerConfig`
…ds` in `ServerBuilder`
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.
Looks like we're going into the right direction. Just minor comments only!
core/src/main/java/com/linecorp/armeria/internal/server/DefaultServiceRequestContext.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/DefaultServerConfig.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/DefaultServerErrorHandler.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/UncaughtExceptionsServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/UncaughtExceptionsServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/UncaughtExceptionsServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/UncaughtExceptionsServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/test/java/com/linecorp/armeria/server/ServerBuilderTest.java
Outdated
Show resolved
Hide resolved
- use `exceptionReportingInterval` instead of `shouldLogUncaughtExceptions` and `logUncaughtExceptionsIntervalInSeconds` - remove `needsToWarn` - rename `UncaughtExceptionsServerErrorHandler` to `ExceptionReportingServerErrorHandler` - Add tests
@trustin Thank you for the review, I've applied the comments. 🙇♂️ |
I'm considering whether it's worthwhile to unify the terms |
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
That's a good point, @seonwoo960000. How about this:
|
…ingServerErrorHandler.java Co-authored-by: Trustin Lee <t@motd.kr>
…ingServerErrorHandler.java Co-authored-by: Trustin Lee <t@motd.kr>
Co-authored-by: Trustin Lee <t@motd.kr>
Sure ~ I'll apply your comments. I'll also change some methods or javadocs that contain the word Btw, I'll apply the renaming as follow. It's just about capital letters fix.
|
e96b775
to
30d9059
Compare
core/src/main/java/com/linecorp/armeria/internal/server/DefaultServiceRequestContext.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/DefaultServerConfig.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ServiceRequestContext.java
Outdated
Show resolved
Hide resolved
core/src/test/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandlerTest.java
Outdated
Show resolved
Hide resolved
- unLog -> unlog - stop all running servers in tests - use assert instead of throwing exceptions(on which arguments have already been checked)
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 we're getting close to completion now. Great! There's one ask left - Could you add Flags.defaultUnloggedExceptionReportIntervalMillis()
and use it as a default value in ServerBuilder
, so that a user can override the default without touching code?
core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java
Outdated
Show resolved
Hide resolved
Test failure - https://github.com/line/armeria/actions/runs/4260354188/jobs/7413433723#step:7:1541 Seems trivial to fix 😉 |
@trustin I've fixed as below:
|
core/src/test/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandlerTest.java
Outdated
Show resolved
Hide resolved
@seonwoo960000 Could you resolve the conflicts? |
- `MicrometerCounter` is added which can be shared across multiple servers with same `MeterRegistry` - Singleton is removed from `ExceptionReportingServerErrorHandler`
487204d
to
65be9b4
Compare
Sure, I've resolved the conflict. |
…nt multiple threads creating multiple schedules at the same time
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
…ing compareAndSet
c18e278
to
382d12c
Compare
core/src/main/java/com/linecorp/armeria/internal/server/DefaultServiceRequestContext.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
- change `log` position - use `Counter` for meterRegistry
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 for putting your effort on this, @seonwoo960000. LGTM 👍 🙇
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, @seonwoo960000! 🎉 🎉
core/src/main/java/com/linecorp/armeria/common/FlagsProvider.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Ikhun Um <ih.pert@gmail.com>
Co-authored-by: Ikhun Um <ih.pert@gmail.com>
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.
Looks really nice! Thanks @seonwoo960000 🙇 👍 🚀
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 a lot for your hard work!
@@ -1961,6 +1987,14 @@ private DefaultServerConfig buildServerConfig(List<ServerPort> serverPorts) { | |||
errorHandler = errorHandler.orElse(ServerErrorHandler.ofDefault()); | |||
} | |||
|
|||
if (unhandledExceptionsReportInterval != Duration.ZERO) { | |||
final ExceptionReportingServerErrorHandler reportingErrorHandler = | |||
new ExceptionReportingServerErrorHandler(meterRegistry, this.errorHandler, |
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 would remove the ServerErrorHandler.ofDefault()
. 😄
new ExceptionReportingServerErrorHandler(meterRegistry, this.errorHandler, | |
new ExceptionReportingServerErrorHandler(meterRegistry, errorHandler, |
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 found a but that existed after fixing this. 😉
ad948d0
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.
Thank you for your detailed review!
core/src/main/java/com/linecorp/armeria/server/ExceptionReportingServerErrorHandler.java
Outdated
Show resolved
Hide resolved
Great job, @seonwoo960000! 🎉 🎉 🎉 |
Motivation:
If
LoggingService
is not added to services, exceptions(without appropriate exception handlers) thrown by those services are not caught. This default behavior can be confusing for users because, even though exceptions are being thrown, there are no logs to indicate that anything is wrong.The purpose of this feature is to enable the reporting of unhandled exceptions by default, so that users can be alerted to any issues and take appropriate action.
Modifications:
com.linecorp.armeria.defaultUnhandledExceptionsReportIntervalMillis
vm option can be used to configure intervals between reporting unhandled exceptions in milliseconds.shouldReportUnhandledExceptions
toDefaultServiceRequestContext
which determines whether to log unhandled exceptions.ExceptionReportingServerErrorHandler
to report unhandled exceptions.Result:
MeterRegistry
exist,armeria.server.exceptions.unhandled
metrics will be the sum of all the number of unhandled exceptions on those servers. However, individual servers will be reported with logs that include total number of unhandled exceptions specific to that server only.Example
ServerBuilder
Closes #4324