Skip to content

Commit

Permalink
Return buffered text from log endpoint if decoding fails
Browse files Browse the repository at this point in the history
To see why I think this is a good change lets look at why I am making it

My disk was full, which means GC was happening agressively. So by the
time I called the logging endpoint from the SDK, the logs were GC'd

The error I was getting before was:
```
invalid character 'i' in literal false (expecting 'l')
```

Now the error I get is:
```
failed to decode log endpoint response as JSON: "failed to list entries: open /tmp/nomad.data.4219353875/alloc/f11fee50-2b66-a7a2-d3ec-8442cb3d557a/alloc/logs: no such file or directory"
```

Still not super descriptive but much more debugable
  • Loading branch information
Ben Buzbee committed Dec 15, 2022
1 parent c314661 commit 05e5a26
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"strconv"
"sync"
"time"

"github.com/hashicorp/go-multierror"
)

const (
Expand Down Expand Up @@ -288,7 +291,12 @@ func (a *AllocFS) Logs(alloc *Allocation, follow bool, task, logType, origin str
if err == io.EOF || err == io.ErrClosedPipe {
close(frames)
} else {
errCh <- err
buf, err2 := ioutil.ReadAll(dec.Buffered())
if err2 != nil {
errCh <- fmt.Errorf("failed to decode and failed to read buffered data: %w", multierror.Append(err, err2))
} else {
errCh <- fmt.Errorf("failed to decode log endpoint response as JSON: %q", buf)
}
}
return
}
Expand Down

0 comments on commit 05e5a26

Please sign in to comment.