Skip to content

Commit

Permalink
fix: downgrade logging level for invalid sequence token (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
junfuchen99 authored Apr 4, 2022
1 parent 0f2f10b commit da9e9db
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CloudWatchLogsUploader {
private CloudWatchLogsClient cloudWatchLogsClient;
private static final int MAX_RETRIES = 3;

// logGroup -> logStream -> savedSequenceToken
final Map<String, Map<String, String>> logGroupsToSequenceTokensMap = new ConcurrentHashMap<>();

@Inject
Expand Down Expand Up @@ -100,7 +101,7 @@ public void unregisterAttemptStatus(String name) {
private boolean uploadLogs(String logGroupName, String logStreamName, List<InputLogEvent> logEvents,
int tryCount) {
if (tryCount > MAX_RETRIES) {
logger.atWarn().log("Unable to upload {} logs to {}-{} as max retry ({}) times reached",
logger.atError().log("Unable to upload {} logs to {}-{} as max retry ({}) times reached",
logEvents.size(), logGroupName, logStreamName, MAX_RETRIES);
return false;
}
Expand Down Expand Up @@ -144,10 +145,14 @@ private boolean uploadLogs(String logGroupName, String logStreamName, List<Input
return true;
} catch (InvalidSequenceTokenException e) {
// Get correct token using describe
logger.atError()
.log("Invalid token while uploading logs to {}-{}. Getting the correct sequence token.",
logGroupName,
logStreamName);
if (tryCount < MAX_RETRIES) {
logger.atInfo().log("Invalid token while uploading logs to {}-{}. Retrying with the expected sequence "
+ "token in CloudWatch response.", logGroupName, logStreamName);
} else {
logger.atError().log("Invalid token while uploading logs to {}-{} with max retry ({}) times "
+ "reached.",
logGroupName, logStreamName, tryCount);
}
addNextSequenceToken(logGroupName, logStreamName, e.expectedSequenceToken());
// TODO: better do the retry mechanism? Maybe need to have a scheduled task to handle this.
return uploadLogs(logGroupName, logStreamName, logEvents, tryCount + 1);
Expand Down

0 comments on commit da9e9db

Please sign in to comment.