Skip to content

Commit

Permalink
Add Trace statements for StdIn/StdOut/StdErr.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpass99 authored and MrSerth committed Sep 10, 2024
1 parent 6252699 commit e89d2e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion internal/api/ws/codeocean_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ws

import (
"context"
"fmt"
"io"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -100,7 +101,7 @@ func handleInput(ctx context.Context, reader io.Reader, buffer chan byte) (done
return true
}

log.WithContext(ctx).WithField("message", string(message)).Trace("Received message from client")
log.WithContext(ctx).WithField("message", fmt.Sprintf("%q", message)).Trace("Received message from client")
for _, character := range message {
select {
case <-ctx.Done():
Expand Down
1 change: 1 addition & 0 deletions internal/nomad/sentry_debug_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (s *SentryDebugWriter) Write(debugData []byte) (n int, err error) {
if _, err = s.Target.Write([]byte{}); err != nil {
return 0, fmt.Errorf("SentryDebugWriter cannot write to target: %w", err)
}
log.WithContext(s.lastSpan.Context()).WithField("data", fmt.Sprintf("%q", debugData)).Trace("Received data from Nomad container")

if !timeDebugMessagePatternStart.Match(debugData) {
count, err := s.Target.Write(debugData)
Expand Down
8 changes: 4 additions & 4 deletions internal/nomad/sentry_debug_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

func (s *MainTestSuite) TestSentryDebugWriter_Write() {
buf := &bytes.Buffer{}
w := SentryDebugWriter{Target: buf, Ctx: s.TestCtx}
debugWriter := NewSentryDebugWriter(s.TestCtx, buf)

description := "TestDebugMessageDescription"
data := "\x1EPoseidon " + description + " 1676646791482\x1E"
count, err := w.Write([]byte(data))
count, err := debugWriter.Write([]byte(data))

s.Require().NoError(err)
s.Equal(len(data), count)
Expand All @@ -19,10 +19,10 @@ func (s *MainTestSuite) TestSentryDebugWriter_Write() {

func (s *MainTestSuite) TestSentryDebugWriter_WriteComposed() {
buf := &bytes.Buffer{}
w := SentryDebugWriter{Target: buf, Ctx: s.TestCtx}
debugWriter := NewSentryDebugWriter(s.TestCtx, buf)

data := "Hello World!\r\n\x1EPoseidon unset 1678540012404\x1E\x1EPoseidon /sbin/setuser user 1678540012408\x1E"
count, err := w.Write([]byte(data))
count, err := debugWriter.Write([]byte(data))

s.Require().NoError(err)
s.Equal(len(data), count)
Expand Down
3 changes: 3 additions & 0 deletions internal/runner/nomad_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ func (r *NomadJob) UpdateFileSystem(requestCtx context.Context, copyRequest *dto
nomad.ErrExecutorCommunicationFailed,
err)
}
if stdErr.Len() > 0 {
log.WithContext(ctx).WithField("stdErr", fmt.Sprintf("%q", stdErr.Bytes())).Trace("Received stdErr from Nomad update fs")
}
if exitCode != 0 {
return fmt.Errorf(
"%w: stderr output '%s' and stdout output '%s'",
Expand Down

0 comments on commit e89d2e3

Please sign in to comment.