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
Do not swallow server errors of TransientService
#3559
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3559 +/- ##
============================================
+ Coverage 73.85% 73.91% +0.06%
- Complexity 14260 14277 +17
============================================
Files 1254 1254
Lines 54447 54466 +19
Branches 6951 6954 +3
============================================
+ Hits 40213 40261 +48
+ Misses 10688 10664 -24
+ Partials 3546 3541 -5 Continue to review full report at Codecov.
|
if (!isTransientService) { | ||
ctx.log().whenRequestComplete().thenAccept(requestLogger).exceptionally(e -> { | ||
try (SafeCloseable ignored = ctx.push()) { | ||
logger.warn("{} Unexpected exception while logging request: ", ctx, e); | ||
} | ||
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.
Don't we need to log an unexpected exception? Because it is unexpected. 😆
How about?
CompletableFuture<Void> requestCompletionFuture = ctx.log().whenRequestComplete();
if (!isTransientService) {
requestCompletionFuture = requestCompletionFuture.thenAccept(requestLogger);
}
requestCompletionFuture.exceptionally(e -> {
...
});
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.
SGTM! Updated.
core/src/main/java/com/linecorp/armeria/internal/common/logging/LoggingDecorators.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/logging/LoggingDecorators.java
Outdated
Show resolved
Hide resolved
The following test looks flaky.
|
4f8bedc
to
f4de651
Compare
requestCompletionFuture.exceptionally(e -> { | ||
try (SafeCloseable ignored = ctx.push()) { | ||
logger.warn("{} Unexpected exception while logging request: ", ctx, e); | ||
} | ||
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.
This .exceptionally()
call seems to be a duplicate. Could be simplified to:
final CompletableFuture<RequestOnlyLog> requestCompletionFuture;
if (!isTransientService) {
requestCompletionFuture = ctx.log().whenRequestComplete().thenAccept(...);
} else {
requestCompletionFuture = ctx.log().whenRequestComplete();
}
requestCompletionFuture.exceptionally(...);
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 also considered. But, even if whenRequestComplete()
returns CompletableFuture<RequestOnlyLog>
, whenRequestComplete().thenAccept(...)
returns CompletableFuture<Void>
. Meanwhile, raw use of CompletableFuture
is ambiguous and using a template seems complicated. 🤔
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.
Then, perhaps we can use thenApply
? 😄
requestCompletionFuture = ctx.log().whenRequestComplete().thenApply(log -> {
requestLogger.accept(log);
return log;
});
It's a bit verbose though. 😄
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.
LGTM once Trustin's comment is addressed.
Thanks a lot! @hexoul
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!
requestCompletionFuture.exceptionally(e -> { | ||
try (SafeCloseable ignored = ctx.push()) { | ||
logger.warn("{} Unexpected exception while logging request: ", ctx, e); | ||
} | ||
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.
Then, perhaps we can use thenApply
? 😄
requestCompletionFuture = ctx.log().whenRequestComplete().thenApply(log -> {
requestLogger.accept(log);
return log;
});
It's a bit verbose though. 😄
I like this way! #3559 (comment) |
ae031ce
to
0c261de
Compare
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!
Motivation:
TransientService
#3551 Should not swallow server errors ofTransientService
Modifications:
TransientServiceOption
.HealthCheckServiceTest
andPrometheusExpositionServiceTest
as they areTransientService
s.Result:
TransientService
.TransientService
#3551