Repository: bacalhau-project/bacalhau (language: python)

Issue:
226 job events logger
add some imporovements to the existing zerolog library so we can choose between a combination of:

 * text based logs
 * json based logs
 * job event logs
 
 `LOG_TYPE=event` is useful when trying to debug because it will print minimal logs only for key job events


Discussion / hints:

Fix patch:
diff --git a/pkg/executor/docker/handler.go b/pkg/executor/docker/handler.go
index 1a495a42a8..68acac15d8 100644
--- a/pkg/executor/docker/handler.go
+++ b/pkg/executor/docker/handler.go
@@ -50,6 +50,7 @@ type executionHandler struct {
 	result *models.RunCommandResult
 }
 
+//nolint:funlen
 func (h *executionHandler) run(ctx context.Context) {
 	h.running.Store(true)
 	defer func() {
@@ -101,6 +102,23 @@ func (h *executionHandler) run(ctx context.Context) {
 	case exitStatus := <-statusCh:
 		// success case, the container completed its execution, but may have experienced an error, we will attempt to collect logs.
 		containerExitStatusCode = exitStatus.StatusCode
+		containerJSON, err := h.client.ContainerInspect(ctx, h.containerID)
+		if err != nil {
+			h.logger.Warn().Err(err).Msg("failed to inspect docker container")
+			h.result = &models.RunCommandResult{
+				ExitCode: int(containerExitStatusCode),
+				ErrorMsg: err.Error(),
+			}
+			return
+		}
+		if containerJSON.ContainerJSONBase.State.OOMKilled {
+			containerError = errors.New(`memory limit exceeded. Please refer to https://docs.bacalhau.org/getting-started/resources/#docker-executor for more information`) //nolint:lll
+			h.result = &models.RunCommandResult{
+				ExitCode: int(containerExitStatusCode),
+				ErrorMsg: containerError.Error(),
+			}
+			return
+		}
 		if exitStatus.Error != nil {
 			h.logger.Warn().
 				Str("error", exitStatus.Error.Message).


Test patch:
diff --git a/pkg/executor/docker/executor_test.go b/pkg/executor/docker/executor_test.go
index 9c3022f172..400b8a6536 100644
--- a/pkg/executor/docker/executor_test.go
+++ b/pkg/executor/docker/executor_test.go
@@ -510,3 +510,15 @@ func (s *ExecutorTestSuite) TestDockerStreamsSlowTask() {
 	require.Equal(s.T(), df.Size, 6)
 	require.Equal(s.T(), df.Tag, logger.StdoutStreamTag)
 }
+
+func (s *ExecutorTestSuite) TestDockerOOM() {
+	task := mock.TaskBuilder().
+		Engine(
+			dockermodels.NewDockerEngineBuilder("ubuntu").
+				WithEntrypoint("tail", "/dev/zero").
+				Build()).BuildOrDie()
+
+	result, err := s.runJob(task, uuid.New().String())
+	require.NoError(s.T(), err)
+	require.Contains(s.T(), result.ErrorMsg, "memory limit exceeded")
+}