Skip to content

Commit

Permalink
Log bodyreader debug data to syslog
Browse files Browse the repository at this point in the history
... to hopefully show up in the journal, and therefore
be visible in CI.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Jan 30, 2023
1 parent 15f6923 commit 0e71554
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions docker/body_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"log/syslog"
"net/http"
"net/url"
"syscall"
Expand All @@ -28,6 +29,7 @@ type bodyReader struct {
lastRetryOffset int64
offset int64 // Current offset within the blob

sysLog *syslog.Writer
}

// newBodyReader creates a bodyReader for FIXME.
Expand All @@ -37,13 +39,27 @@ func newBodyReader(ctx context.Context, c *dockerClient, path string, firstBody
if err != nil {
return nil, err
}
return &bodyReader{
sysLog, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_DAEMON, "Podman-BODYREADER")
if err != nil {
return nil, err
}
res := &bodyReader{
path: path,
logURL: logURL,
body: firstBody,
lastRetryOffset: 0,
offset: 0,
}, nil
sysLog: sysLog,
}
res.Logf("BODYREADER INIT")
return res, nil
}

// FIXME: Drop this again, replace by just logrus.Debugf or something
func (br *bodyReader) Logf(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
logrus.Error(msg)
_, _ = br.sysLog.Write([]byte(msg))
}

// Read implements io.ReadCloser
Expand All @@ -59,15 +75,15 @@ func (br *bodyReader) Read(p []byte) (int, error) {

case errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, syscall.ECONNRESET):
// FIXME: Turn this into a Debugf
logrus.Errorf("BODYREADER DEBUG: Reading blob body, decision inputs: lastRetryOffset %d, offset %d, error %#v", br.lastRetryOffset, br.offset, err)
br.Logf("BODYREADER DEBUG: Reading blob body, decision inputs: lastRetryOffset %d, offset %d, error %#v", br.lastRetryOffset, br.offset, err)
progress := br.offset - br.lastRetryOffset
if progress < bodyReaderMinimumProgress {
// FIXME: Warnf
logrus.Errorf("BODYREADER DEBUG: Error reading blob body from %s, not reconnecting because only %d bytes progress made: %v", br.logURL.Redacted(), progress, err)
br.Logf("BODYREADER DEBUG: Error reading blob body from %s, not reconnecting because only %d bytes progress made: %v", br.logURL.Redacted(), progress, err)
return n, err
}
// FIXME: Warnf
logrus.Errorf("BODYREADER DEBUG: Reading blob body from %s failed, reconnecting…: %v", br.logURL.Redacted(), err)
br.Logf("BODYREADER DEBUG: Reading blob body from %s failed, reconnecting…: %v", br.logURL.Redacted(), err)
if err2 := br.body.Close(); err2 != nil {
logrus.Debugf("Error closing blob body: %v", err2) // … and ignore err otherwise
}
Expand Down

0 comments on commit 0e71554

Please sign in to comment.