Skip to content

Commit

Permalink
Refine updateFileSystem logging messages
Browse files Browse the repository at this point in the history
to be able to differentiate between the different errors that occur.
  • Loading branch information
mpass99 authored and MrSerth committed Aug 1, 2024
1 parent 88bbb51 commit 7f2d6ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
26 changes: 21 additions & 5 deletions internal/api/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (

"github.com/google/uuid"
"github.com/gorilla/mux"
nomadApi "github.com/hashicorp/nomad/api"
"github.com/openHPI/poseidon/internal/config"
"github.com/openHPI/poseidon/internal/nomad"
"github.com/openHPI/poseidon/internal/runner"
"github.com/openHPI/poseidon/pkg/dto"
"github.com/openHPI/poseidon/pkg/logging"
Expand Down Expand Up @@ -137,13 +139,27 @@ func (r *RunnerController) updateFileSystem(writer http.ResponseWriter, request
logging.StartSpan(request.Context(), "api.fs.update", "Update File System", func(ctx context.Context) {
err = targetRunner.UpdateFileSystem(ctx, fileCopyRequest)
})
if err != nil {
log.WithContext(request.Context()).WithError(err).Error("Could not perform the requested updateFileSystem.")

entry := log.WithContext(request.Context()).WithError(err)
switch {
case err == nil:
writer.WriteHeader(http.StatusNoContent)
case errors.Is(err, nomadApi.NodeDownErr):
entry.Debug("Nomad Node Down while updateFileSystem")
writeInternalServerError(writer, err, dto.ErrorNomadInternalServerError, request.Context())

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use writer (variable of type "net/http".ResponseWriter) as context.Context value in argument to writeInternalServerError: "net/http".ResponseWriter does not implement context.Context (missing method Deadline)

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use err (variable of type error) as "net/http".ResponseWriter value in argument to writeInternalServerError: error does not implement "net/http".ResponseWriter (missing method Header)

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use dto.ErrorNomadInternalServerError (constant "NOMAD_INTERNAL_SERVER_ERROR" of type dto.ErrorCode) as error value in argument to writeInternalServerError: dto.ErrorCode does not implement error (missing method Error)

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use request.Context() (value of type context.Context) as dto.ErrorCode value in argument to writeInternalServerError

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use writer (variable of type "net/http".ResponseWriter) as context.Context value in argument to writeInternalServerError: "net/http".ResponseWriter does not implement context.Context (missing method Deadline)

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use err (variable of type error) as "net/http".ResponseWriter value in argument to writeInternalServerError: error does not implement "net/http".ResponseWriter (missing method Header)

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use dto.ErrorNomadInternalServerError (constant "NOMAD_INTERNAL_SERVER_ERROR" of type dto.ErrorCode) as error value in argument to writeInternalServerError: dto.ErrorCode does not implement error (missing method Error)

Check failure on line 149 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use request.Context() (value of type context.Context) as dto.ErrorCode value in argument to writeInternalServerError
case errors.Is(err, io.ErrUnexpectedEOF):
entry.Warn("Unexpected EOF while updateFileSystem")
writeInternalServerError(writer, err, dto.ErrorUnknown, request.Context())

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use writer (variable of type "net/http".ResponseWriter) as context.Context value in argument to writeInternalServerError: "net/http".ResponseWriter does not implement context.Context (missing method Deadline)

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use err (variable of type error) as "net/http".ResponseWriter value in argument to writeInternalServerError: error does not implement "net/http".ResponseWriter (missing method Header)

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use dto.ErrorUnknown (constant "UNKNOWN" of type dto.ErrorCode) as error value in argument to writeInternalServerError: dto.ErrorCode does not implement error (missing method Error)

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use request.Context() (value of type context.Context) as dto.ErrorCode value in argument to writeInternalServerError

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use writer (variable of type "net/http".ResponseWriter) as context.Context value in argument to writeInternalServerError: "net/http".ResponseWriter does not implement context.Context (missing method Deadline)

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use err (variable of type error) as "net/http".ResponseWriter value in argument to writeInternalServerError: error does not implement "net/http".ResponseWriter (missing method Header)

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use dto.ErrorUnknown (constant "UNKNOWN" of type dto.ErrorCode) as error value in argument to writeInternalServerError: dto.ErrorCode does not implement error (missing method Error)

Check failure on line 152 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

cannot use request.Context() (value of type context.Context) as dto.ErrorCode value in argument to writeInternalServerError
case errors.Is(err, nomad.ErrorNoAllocationFound):

Check failure on line 153 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

undefined: nomad.ErrorNoAllocationFound

Check failure on line 153 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / lint

undefined: nomad.ErrorNoAllocationFound
entry.Warn("No allocation found while updateFileSystem")
writeInternalServerError(writer, err, dto.ErrorUnknown, request.Context())

Check failure on line 155 in internal/api/runners.go

View workflow job for this annotation

GitHub Actions / compile

cannot use writer (variable of type "net/http".ResponseWriter) as context.Context value in argument to writeInternalServerError: "net/http".ResponseWriter does not implement context.Context (missing method Deadline)
case errors.Is(err, nomad.ErrNomadUnknownAllocation):
entry.Warn("Unknown allocation while updateFileSystem")
writeInternalServerError(writer, err, dto.ErrorUnknown, request.Context())
default:
entry.Error("Could not perform the requested updateFileSystem.")
writeInternalServerError(request.Context(), writer, err, dto.ErrorUnknown)
return
}

writer.WriteHeader(http.StatusNoContent)
}

func (r *RunnerController) fileContent(writer http.ResponseWriter, request *http.Request) {
Expand Down
7 changes: 6 additions & 1 deletion internal/nomad/api_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import (
"github.com/openHPI/poseidon/pkg/logging"
)

var ErrNoAllocationFound = errors.New("no allocation found")
var (
ErrNoAllocationFound = errors.New("no allocation found")
ErrNomadUnknownAllocation = errors.New("unknown allocation")
)

// apiQuerier provides access to the Nomad functionality.
type apiQuerier interface {
Expand Down Expand Up @@ -135,6 +138,8 @@ func (nc *nomadAPIClient) Execute(ctx context.Context, runnerID string, cmd stri
case errors.Is(err, context.Canceled):
log.WithContext(ctx).Debug("Execution canceled by context")
return 0, nil
case strings.Contains(err.Error(), "Unknown allocation"):
return 1, ErrNomadUnknownAllocation
default:
return 1, fmt.Errorf("error executing command in allocation: %w", err)
}
Expand Down

0 comments on commit 7f2d6ba

Please sign in to comment.