Skip to content
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

Merged
merged 7 commits into from May 14, 2021

Conversation

hexoul
Copy link
Contributor

@hexoul hexoul commented May 13, 2021

Motivation:

Modifications:

  • Log response in case of server error regardless of TransientServiceOption.
  • Modify verifications of HealthCheckServiceTest and PrometheusExpositionServiceTest as they are TransientServices.

Result:

@codecov
Copy link

codecov bot commented May 13, 2021

Codecov Report

Merging #3559 (ae031ce) into master (161f082) will increase coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head ae031ce differs from pull request most recent head 0c261de. Consider uploading reports for the commit 0c261de to get more accurate results
Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
...ria/internal/common/logging/LoggingDecorators.java 92.59% <100.00%> (+2.11%) 21.00 <6.00> (+7.00)
...inecorp/armeria/server/logging/LoggingService.java 100.00% <100.00%> (ø) 6.00 <2.00> (-1.00)
.../linecorp/armeria/client/DefaultClientFactory.java 69.89% <0.00%> (-2.16%) 29.00% <0.00%> (-1.00%)
...a/com/linecorp/armeria/common/util/Exceptions.java 43.35% <0.00%> (-2.10%) 31.00% <0.00%> (-1.00%)
...p/armeria/common/stream/AbstractStreamMessage.java 81.73% <0.00%> (-1.93%) 15.00% <0.00%> (ø%)
...armeria/internal/common/CancellationScheduler.java 77.14% <0.00%> (-0.96%) 85.00% <0.00%> (-1.00%)
.../linecorp/armeria/client/Http1ResponseDecoder.java 66.66% <0.00%> (-0.61%) 44.00% <0.00%> (-1.00%)
...inecorp/armeria/server/HttpResponseSubscriber.java 78.94% <0.00%> (-0.36%) 68.00% <0.00%> (ø%)
...corp/armeria/common/logging/DefaultRequestLog.java 77.08% <0.00%> (+0.25%) 225.00% <0.00%> (+1.00%)
...a/com/linecorp/armeria/client/HttpChannelPool.java 78.68% <0.00%> (+0.27%) 67.00% <0.00%> (ø%)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 384df27...0c261de. Read the comment docs.

Comment on lines 54 to 63
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;
});
}
Copy link
Contributor

@ikhoon ikhoon May 13, 2021

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 -> {
    ...
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM! Updated.

@ikhoon ikhoon added the defect label May 13, 2021
@ikhoon ikhoon added this to the 1.8.0 milestone May 13, 2021
@ikhoon
Copy link
Contributor

ikhoon commented May 13, 2021

The following test looks flaky.
https://github.com/line/armeria/pull/3559/checks?check_run_id=2573691460#step:7:2150

HealthCheckServiceTest > waitWithWrongTimeout() FAILED
    Wanted but not invoked:
    logger.isDebugEnabled();
    -> at com.linecorp.armeria.server.healthcheck.HealthCheckServiceTest.waitWithWrongTimeout(HealthCheckServiceTest.java:327)
    Actually, there were zero interactions with this mock.
        at com.linecorp.armeria.server.healthcheck.HealthCheckServiceTest.waitWithWrongTimeout(HealthCheckServiceTest.java:327)

Comment on lines 64 to 69
requestCompletionFuture.exceptionally(e -> {
try (SafeCloseable ignored = ctx.push()) {
logger.warn("{} Unexpected exception while logging request: ", ctx, e);
}
return null;
});
Copy link
Member

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(...);

Copy link
Contributor Author

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. 🤔

Copy link
Member

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. 😄

Copy link
Contributor

@ikhoon ikhoon left a 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

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Comment on lines 64 to 69
requestCompletionFuture.exceptionally(e -> {
try (SafeCloseable ignored = ctx.push()) {
logger.warn("{} Unexpected exception while logging request: ", ctx, e);
}
return null;
});
Copy link
Member

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. 😄

@hexoul
Copy link
Contributor Author

hexoul commented May 14, 2021

I like this way! #3559 (comment)

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@trustin trustin merged commit 52675f7 into line:master May 14, 2021
@hexoul hexoul deleted the do-not-swallow-5xx branch May 14, 2021 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should not swallow errors of TransientService
4 participants