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 db4d4c3
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(request.Context(), writer, err, dto.ErrorNomadInternalServerError)
case errors.Is(err, io.ErrUnexpectedEOF):
entry.Warn("Unexpected EOF while updateFileSystem")
writeInternalServerError(request.Context(), writer, err, dto.ErrorUnknown)
case errors.Is(err, nomad.ErrNoAllocationFound):
entry.Warn("No allocation found while updateFileSystem")
writeInternalServerError(request.Context(), writer, err, dto.ErrorUnknown)
case errors.Is(err, nomad.ErrNomadUnknownAllocation):
entry.Warn("Unknown allocation while updateFileSystem")
writeInternalServerError(request.Context(), writer, err, dto.ErrorUnknown)
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 db4d4c3

Please sign in to comment.