Skip to content

Commit

Permalink
Log TokenNotFoundException at the debug level (#1011)
Browse files Browse the repository at this point in the history
Motivation:

`TokenNotFoundException` may be useful to debug a request failure but
the warning log would be noisy to the maintainers of a Central Dogma
cluster.

Modifications:

- Use the `DEBUG` level to log `TokenNotFoundException`.
  - `IllegalArgumentException` is also logged at `DEBUG`.

Result:

`TokenNotFoundException` is now logged at the `DEBUG` level in
`ApplicationTokenAuthorizer`.
  • Loading branch information
ikhoon authored Aug 16, 2024
1 parent b06bc11 commit 93f839b
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@

import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.auth.OAuth2Token;
import com.linecorp.armeria.common.logging.LogLevel;
import com.linecorp.armeria.common.util.Exceptions;
import com.linecorp.armeria.server.ServiceRequestContext;
import com.linecorp.armeria.server.auth.AuthTokenExtractors;
import com.linecorp.armeria.server.auth.Authorizer;
import com.linecorp.centraldogma.internal.CsrfToken;
import com.linecorp.centraldogma.server.internal.admin.auth.AuthUtil;
import com.linecorp.centraldogma.server.internal.admin.service.TokenNotFoundException;
import com.linecorp.centraldogma.server.metadata.Token;
import com.linecorp.centraldogma.server.metadata.Tokens;
import com.linecorp.centraldogma.server.metadata.User;
Expand Down Expand Up @@ -89,10 +91,15 @@ public CompletionStage<Boolean> authorize(ServiceRequestContext ctx, HttpRequest
// Should be authorized by the next authorizer.
.exceptionally(voidFunction(cause -> {
cause = Exceptions.peel(cause);
if (!(cause instanceof IllegalArgumentException)) {
logger.warn("Application token authorization failed: token={}, addr={}",
token.accessToken(), ctx.clientAddress(), cause);
final LogLevel level;
if (cause instanceof IllegalArgumentException ||
cause instanceof TokenNotFoundException) {
level = LogLevel.DEBUG;
} else {
level = LogLevel.WARN;
}
level.log(logger, "Failed to authorize an application token: token={}, addr={}",
token.accessToken(), ctx.clientAddress(), cause);
res.complete(false);
}));

Expand Down

0 comments on commit 93f839b

Please sign in to comment.