Skip to content

Commit

Permalink
Integrated code lifecycle: Improve logging when build job times out (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour authored Dec 8, 2024
1 parent 9672a77 commit afa2ce3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public void stopContainer(String containerName) {
// Get the container ID.
String containerId = container.getId();

log.info("Stopping container with id {}", containerId);

// Create a file "stop_container.txt" in the root directory of the container to indicate that the test results have been extracted or that the container should be stopped
// for some other reason.
// The container's main process is waiting for this file to appear and then stops the main process, thus stopping and removing the container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,18 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String

ZonedDateTime buildCompletedDate = ZonedDateTime.now();

msg = "~~~~~~~~~~~~~~~~~~~~ Moving test results to specified directory for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~";
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
log.debug(msg);

buildJobContainerService.moveResultsToSpecifiedDirectory(containerId, buildJob.buildConfig().resultPaths(), LOCALCI_WORKING_DIRECTORY + LOCALCI_RESULTS_DIRECTORY);

// Get an input stream of the test result files.

msg = "~~~~~~~~~~~~~~~~~~~~ Collecting test results from container " + containerId + " for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~";
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
log.info(msg);

TarArchiveInputStream testResultsTarInputStream;

try {
Expand Down Expand Up @@ -349,6 +357,10 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String
}
}

msg = "~~~~~~~~~~~~~~~~~~~~ Parsing test results for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~";
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
log.info(msg);

BuildResult buildResult;
try {
buildResult = parseTestResults(testResultsTarInputStream, buildJob.buildConfig().branch(), assignmentRepoCommitHash, testRepoCommitHash, buildCompletedDate,
Expand All @@ -362,7 +374,7 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String
}

msg = "Building and testing submission for repository " + assignmentRepositoryUri.repositorySlug() + " and commit hash " + assignmentRepoCommitHash + " took "
+ TimeLogUtil.formatDurationFrom(timeNanoStart);
+ TimeLogUtil.formatDurationFrom(timeNanoStart) + " for build job " + buildJob.id();
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
log.info(msg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;

Expand Down Expand Up @@ -176,6 +177,9 @@ public CompletableFuture<BuildResult> executeBuildJob(BuildJobQueueItem buildJob
}
else {
finishBuildJobExceptionally(buildJobItem.id(), containerName, e);
if (e instanceof TimeoutException) {
logTimedOutBuildJob(buildJobItem, buildJobTimeoutSeconds);
}
throw new CompletionException(e);
}
}
Expand All @@ -188,6 +192,18 @@ public CompletableFuture<BuildResult> executeBuildJob(BuildJobQueueItem buildJob
}));
}

private void logTimedOutBuildJob(BuildJobQueueItem buildJobItem, int buildJobTimeoutSeconds) {
String msg = "Timed out after " + buildJobTimeoutSeconds + " seconds. "
+ "This may be due to an infinite loop or inefficient code. Please review your code for potential issues. "
+ "If the problem persists, contact your instructor for assistance. (Build job ID: " + buildJobItem.id() + ")";
buildLogsMap.appendBuildLogEntry(buildJobItem.id(), msg);
log.warn(msg);

msg = "Executing build job with id " + buildJobItem.id() + " timed out after " + buildJobTimeoutSeconds + " seconds."
+ "This may be due to strict timeout settings. Consider increasing the exercise timeout and applying stricter timeout constraints within the test cases using @StrictTimeout.";
buildLogsMap.appendBuildLogEntry(buildJobItem.id(), msg);
}

Set<String> getRunningBuildJobIds() {
return Set.copyOf(runningFutures.keySet());
}
Expand Down

0 comments on commit afa2ce3

Please sign in to comment.