Skip to content

Commit

Permalink
Add more logging to TokenService on superseding doc (#68721)
Browse files Browse the repository at this point in the history
This adds two new log messages to TokenService

1. After finding a superseding document, log (DEBUG) that it was
successfully found (previously we only logged not-found+retries)
2. If a document cannot be found in order to validate it, log (WARN)
this explicitly.

Backport of: #66970
  • Loading branch information
tvernum committed Feb 9, 2021
1 parent 8ced781 commit 6354ddb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,8 @@ void decryptAndReturnSupersedingTokens(String refreshToken, RefreshTokenStatus r
public void onResponse(GetResponse response) {
if (response.isExists()) {
try {
logger.debug("Found superseding document: index=[{}] id=[{}] primTerm=[{}] seqNo=[{}]",
response.getIndex(), response.getId(), response.getPrimaryTerm(), response.getSeqNo());
listener.onResponse(
new CreateTokenResult(prependVersionAndEncodeAccessToken(refreshTokenStatus.getVersion(),
decryptedTokens[0]),
Expand Down Expand Up @@ -1662,7 +1664,18 @@ private void checkIfTokenIsValid(UserToken userToken, ActionListener<UserToken>
}
}
} else {
onFailure.accept(new IllegalStateException("token document is missing and must be present"));
// This shouldn't happen (if we have a valid `UserToken` object, then should mean that we loaded it from the
// index in a prior operation (e.g. #getUserTokenFromId), however this error can happen if either:
// 1. The document was deleted just after we read it
// 2. This Get used a different replica to the previous one, and they were out of sync.
logger.warn(
"Could not find token document (index=[{}] id=[{}]) in order to validate user token [{}] for [{}]",
response.getIndex(),
response.getId(),
userToken.getId(),
userToken.getAuthentication().getUser().principal());
onFailure.accept(traceLog("validate token", userToken.getId(),
new IllegalStateException("token document is missing and must be present")));
}
}, e -> {
// if the index or the shard is not there / available we assume that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void writeTo(StreamOutput out) throws IOException {
}

/**
* Get the authentication
* Get the authentication (will not be null)
*/
Authentication getAuthentication() {
return authentication;
Expand Down

0 comments on commit 6354ddb

Please sign in to comment.