From a7d27e8f655cbed868e175d7129b484d039c1631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Mon, 21 Aug 2023 11:36:19 +0200 Subject: [PATCH] Add missing error log statements. When "markRunnerAsUsed" fails, we silently ignored it. Only, when additionally the return of the runner failed, we threw the error. When a Runner is destroyed, we are only notified that Nomad removed the allocation, but cannot tell about the reason. For "the execution did not stop after SIGQUIT" we did not log the belonging runner id. --- internal/api/ws/codeocean_writer.go | 2 +- internal/runner/nomad_manager.go | 1 + internal/runner/nomad_runner.go | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/api/ws/codeocean_writer.go b/internal/api/ws/codeocean_writer.go index 5063b86..cbe70a6 100644 --- a/internal/api/ws/codeocean_writer.go +++ b/internal/api/ws/codeocean_writer.go @@ -144,7 +144,7 @@ func (cw *codeOceanOutputWriter) startWritingLoop(writingLoopDone context.Cancel done = sendMessage(cw.connection, message.data, cw.ctx) } if done || message.done { - log.Debug("Writing loop done") + log.WithContext(cw.ctx).Trace("Writing loop done") writingLoopDone() return } diff --git a/internal/runner/nomad_manager.go b/internal/runner/nomad_manager.go index b8c3c50..ffc3236 100644 --- a/internal/runner/nomad_manager.go +++ b/internal/runner/nomad_manager.go @@ -62,6 +62,7 @@ func (m *NomadRunnerManager) markRunnerAsUsed(runner Runner, timeoutDuration int return }) if err != nil { + log.WithError(err).WithField(dto.KeyRunnerID, runner.ID()).Error("cannot mark runner as used") err := m.Return(runner) if err != nil { log.WithError(err).WithField(dto.KeyRunnerID, runner.ID()).Error("can't mark runner as used and can't return runner") diff --git a/internal/runner/nomad_runner.go b/internal/runner/nomad_runner.go index 5573693..f2161cf 100644 --- a/internal/runner/nomad_runner.go +++ b/internal/runner/nomad_runner.go @@ -64,7 +64,8 @@ type NomadJob struct { func NewNomadJob(id string, portMappings []nomadApi.PortMapping, apiClient nomad.ExecutorAPI, onDestroy DestroyRunnerHandler, ) *NomadJob { - ctx, cancel := context.WithCancel(context.Background()) + ctx := context.WithValue(context.Background(), dto.ContextKey(dto.KeyRunnerID), id) + ctx, cancel := context.WithCancel(ctx) job := &NomadJob{ id: id, portMappings: portMappings, @@ -237,6 +238,7 @@ func (r *NomadJob) GetFileContent( func (r *NomadJob) Destroy(reason DestroyReason) (err error) { r.ctx = context.WithValue(r.ctx, destroyReasonContextKey, reason) + log.WithContext(r.ctx).Debug("Destroying Runner") r.cancel() r.StopTimeout() if r.onDestroy != nil { @@ -254,6 +256,8 @@ func (r *NomadJob) Destroy(reason DestroyReason) (err error) { if err != nil { err = fmt.Errorf("cannot destroy runner: %w", err) + } else { + log.WithContext(r.ctx).Trace("Runner destroyed") } return err }