From dd7cdfffd823d6aaab9354b76b5a88e2f49a37f8 Mon Sep 17 00:00:00 2001 From: Mohamed Bilel Besrour Date: Wed, 4 Dec 2024 20:33:46 +0100 Subject: [PATCH 1/6] logging --- .../buildagent/service/BuildJobExecutionService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java index c5e042b7f20e..9210b23cc2a6 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java @@ -308,10 +308,18 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String ZonedDateTime buildCompletedDate = ZonedDateTime.now(); + msg = "~~~~~~~~~~~~~~~~~~~~ Moving test results to specified directory ~~~~~~~~~~~~~~~~~~~~"; + 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 ~~~~~~~~~~~~~~~~~~~~"; + buildLogsMap.appendBuildLogEntry(buildJob.id(), msg); + log.info(msg); + TarArchiveInputStream testResultsTarInputStream; try { From 2435c977a5992fceae892cd7fee3f681465cf0e5 Mon Sep 17 00:00:00 2001 From: Mohamed Bilel Besrour Date: Wed, 4 Dec 2024 22:31:09 +0100 Subject: [PATCH 2/6] logging --- .../buildagent/service/BuildJobExecutionService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java index 9210b23cc2a6..1323f6506a3f 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java @@ -308,7 +308,7 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String ZonedDateTime buildCompletedDate = ZonedDateTime.now(); - msg = "~~~~~~~~~~~~~~~~~~~~ Moving test results to specified directory ~~~~~~~~~~~~~~~~~~~~"; + msg = "~~~~~~~~~~~~~~~~~~~~ Moving test results to specified directory for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~"; buildLogsMap.appendBuildLogEntry(buildJob.id(), msg); log.debug(msg); @@ -316,7 +316,7 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String // Get an input stream of the test result files. - msg = "~~~~~~~~~~~~~~~~~~~~ Collecting test results from container ~~~~~~~~~~~~~~~~~~~~"; + msg = "~~~~~~~~~~~~~~~~~~~~ Collecting test results from container " + containerName + " for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~"; buildLogsMap.appendBuildLogEntry(buildJob.id(), msg); log.info(msg); @@ -357,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, @@ -370,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); From b8ab14641bcf70015ea97ce3b56bd7f0425c325a Mon Sep 17 00:00:00 2001 From: Mohamed Bilel Besrour Date: Thu, 5 Dec 2024 18:02:06 +0100 Subject: [PATCH 3/6] logging --- .../buildagent/service/BuildJobContainerService.java | 2 ++ .../buildagent/service/BuildJobManagementService.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java index b68cc7a0c001..3c7ff12881cd 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobContainerService.java @@ -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. diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java index be480892b8e3..896710ddd363 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java @@ -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; @@ -175,6 +176,11 @@ public CompletableFuture executeBuildJob(BuildJobQueueItem buildJob throw new CompletionException(msg, e); } else { + if (e instanceof TimeoutException) { + String msg = "Build job with id " + buildJobItem.id() + " timed out after " + buildJobTimeoutSeconds + " seconds."; + buildLogsMap.appendBuildLogEntry(buildJobItem.id(), msg); + log.warn(msg); + } finishBuildJobExceptionally(buildJobItem.id(), containerName, e); throw new CompletionException(e); } From 82958da98cf2e7ef1a57126210bdec4296656db1 Mon Sep 17 00:00:00 2001 From: Mohamed Bilel Besrour Date: Thu, 5 Dec 2024 20:40:03 +0100 Subject: [PATCH 4/6] logging --- .../buildagent/service/BuildJobManagementService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java index 896710ddd363..d9f7ad426b3b 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java @@ -176,12 +176,14 @@ public CompletableFuture executeBuildJob(BuildJobQueueItem buildJob throw new CompletionException(msg, e); } else { + finishBuildJobExceptionally(buildJobItem.id(), containerName, e); if (e instanceof TimeoutException) { - String msg = "Build job with id " + buildJobItem.id() + " timed out after " + buildJobTimeoutSeconds + " seconds."; + 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); } - finishBuildJobExceptionally(buildJobItem.id(), containerName, e); throw new CompletionException(e); } } From 559e16e47962d1dac965bac5d755a9f7e31a061f Mon Sep 17 00:00:00 2001 From: Mohamed Bilel Besrour Date: Thu, 5 Dec 2024 21:10:31 +0100 Subject: [PATCH 5/6] logging --- .../artemis/buildagent/service/BuildJobExecutionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java index 1323f6506a3f..2fb2c805bf13 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java @@ -316,7 +316,7 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String // Get an input stream of the test result files. - msg = "~~~~~~~~~~~~~~~~~~~~ Collecting test results from container " + containerName + " for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~"; + msg = "~~~~~~~~~~~~~~~~~~~~ Collecting test results from container " + containerId + " for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~"; buildLogsMap.appendBuildLogEntry(buildJob.id(), msg); log.info(msg); From ed26c497c466846cf77a3402ebadc3ebb9b0eb52 Mon Sep 17 00:00:00 2001 From: Mohamed Bilel Besrour Date: Sat, 7 Dec 2024 12:51:20 +0100 Subject: [PATCH 6/6] add log for instructor --- .../service/BuildJobManagementService.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java index d9f7ad426b3b..d4142e21f24a 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobManagementService.java @@ -178,11 +178,7 @@ public CompletableFuture executeBuildJob(BuildJobQueueItem buildJob else { finishBuildJobExceptionally(buildJobItem.id(), containerName, e); if (e instanceof TimeoutException) { - 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); + logTimedOutBuildJob(buildJobItem, buildJobTimeoutSeconds); } throw new CompletionException(e); } @@ -196,6 +192,18 @@ public CompletableFuture 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 getRunningBuildJobIds() { return Set.copyOf(runningFutures.keySet()); }