Skip to content

Commit

Permalink
fix: delete log even if nothing was uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDombo committed Nov 16, 2023
1 parent 212328c commit e0f4791
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,6 @@ private void handleCloudWatchAttemptStatus(CloudWatchAttempt cloudWatchAttempt)
return;
}

ProcessingFiles processingFiles = processingFilesInformation.get(componentName);

// Delete files based on diskspace
List<String> deletedHashes =
this.diskSpaceManagementService.freeDiskSpace(attemptLogInformation.getLogFileGroup());

processingFiles.remove(deletedHashes); // Stop tracking files already uploaded

// Delete after upload
ComponentLogConfiguration componentLogConfiguration = componentLogConfigurations.get(componentName);
completedFiles.forEach(file -> this.deleteFile(componentLogConfiguration, file));
Expand Down Expand Up @@ -710,6 +702,14 @@ private void processLogsAndUpload() throws InterruptedException {
continue;
}

ProcessingFiles componentProcessingFiles = processingFilesInformation.get(componentName);
// Delete files based on diskspace
List<String> deletedHashes =
this.diskSpaceManagementService.freeDiskSpace(logFileGroup);
if (componentProcessingFiles != null) {
componentProcessingFiles.remove(deletedHashes); // Stop tracking files that are deleted
}

ComponentLogFileInformation logFileInfo = ComponentLogFileInformation.builder()
.name(componentName)
.multiLineStartPattern(componentLogConfiguration.getMultiLineStartPattern())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.aws.greengrass.logmanager.services;

import com.aws.greengrass.logging.api.Logger;
import com.aws.greengrass.logging.impl.LogManager;
import com.aws.greengrass.logmanager.model.LogFile;
import com.aws.greengrass.logmanager.model.LogFileGroup;

Expand All @@ -13,6 +15,7 @@


public class DiskSpaceManagementService {
private static final Logger logger = LogManager.getLogger(DiskSpaceManagementService.class);

/**
* Deleted the file to make sure the log group is below its configured
Expand All @@ -32,6 +35,8 @@ public List<String> freeDiskSpace(LogFileGroup group) {
long bytesDeleted = 0;
long minimumBytesToBeDeleted = Math.max(group.totalSizeInBytes() - group.getMaxBytes().get(), 0);
List<LogFile> deletableFiles = group.getProcessedLogFiles();
logger.atInfo().log("Deletable: {}. Undeletable: {}", group.getProcessedLogFiles(), group.getLogFiles());

List<String> deletedHashes = new ArrayList<>();

for (LogFile logFile: deletableFiles) {
Expand All @@ -48,4 +53,4 @@ public List<String> freeDiskSpace(LogFileGroup group) {

return deletedHashes;
}
}
}

0 comments on commit e0f4791

Please sign in to comment.