Skip to content

Commit

Permalink
DROP THIS: Log all debug entries to syslog
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Feb 7, 2023
1 parent 45e9e66 commit b08f980
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 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"
"strconv"
Expand All @@ -31,6 +32,9 @@ type bodyReader struct {
offset int64 // Current offset within the blob
firstConnectionTime time.Time
lastSuccessTime time.Time // time.Time{} if N/A

// FIXME: Remove the syslog code entirely
sysLog *syslog.Writer
}

// newBodyReader creates a bodyReader for FIXME.
Expand All @@ -40,6 +44,11 @@ func newBodyReader(ctx context.Context, c *dockerClient, path string, firstBody
if err != nil {
return nil, err
}
sysLog, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_DAEMON, "Podman-BODYREADER")
if err != nil {
logrus.Debugf("Error connecting to syslog: %v", err)
sysLog = nil
}
res := &bodyReader{
ctx: ctx,
c: c,
Expand All @@ -50,10 +59,21 @@ func newBodyReader(ctx context.Context, c *dockerClient, path string, firstBody
lastRetryOffset: 0,
offset: 0,
firstConnectionTime: time.Now(),
sysLog: sysLog,
}
res.logf(logrus.DebugLevel, "bodyReader init") // Drop this entirely
return res, nil
}

// FIXME: Drop this again, replace by direct calls to logrus.
func (br *bodyReader) logf(level logrus.Level, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
logrus.StandardLogger().Logf(level, "%s", msg)
if br.sysLog != nil {
_, _ = br.sysLog.Write([]byte("" + msg))
}
}

// parseDecimalInString ensures that s[start:] starts with a non-negative decimal number, and returns that number and the offset after the number.
func parseDecimalInString(s string, start int) (int64, int, error) {
i := start
Expand Down Expand Up @@ -146,15 +166,15 @@ func (br *bodyReader) Read(p []byte) (int, error) {
if (br.lastSuccessTime != time.Time{}) {
failureTime = time.Since(br.lastSuccessTime).Milliseconds()
}
logrus.Debugf("Reading blob body from %s failed (%#v), decision inputs: lastRetryOffset %d, offset %d, %d ms since first connection, %d ms since last progress",
br.logf(logrus.DebugLevel, "Reading blob body from %s failed (%#v), decision inputs: lastRetryOffset %d, offset %d, %d ms since first connection, %d ms since last progress",
redactedURL, originalErr, br.lastRetryOffset, br.offset, totalTime, failureTime)
progress := br.offset - br.lastRetryOffset
if progress < bodyReaderMinimumProgress {
logrus.Debugf("Not reconnecting to %s because only %d bytes progress made", redactedURL, progress)
br.logf(logrus.DebugLevel, "Not reconnecting to %s because only %d bytes progress made", redactedURL, progress)
return n, fmt.Errorf("(heuristic tuning data: last retry %d, current offset %d; %d ms total, %d ms since progress): %w",
br.lastRetryOffset, br.offset, totalTime, failureTime, originalErr)
}
logrus.Infof("Reading blob body from %s failed (%v), reconnecting…", redactedURL, originalErr)
br.logf(logrus.InfoLevel, "Reading blob body from %s failed (%v), reconnecting…", redactedURL, originalErr)
if err := br.body.Close(); err != nil {
logrus.Debugf("Error closing blob body: %v", err) // … and ignore err otherwise
}
Expand Down Expand Up @@ -195,14 +215,14 @@ func (br *bodyReader) Read(p []byte) (int, error) {
return n, fmt.Errorf("%w (after reconnecting, fetching blob: %v)", originalErr, err)
}

logrus.Debugf("Succesfully reconnected to %s", redactedURL)
br.logf(logrus.DebugLevel, "Succesfully reconnected to %s", redactedURL)
consumedBody = true
br.body = res.Body
br.lastRetryOffset = br.offset
return n, nil

default:
logrus.Debugf("Error reading blob body from %s: %#v", br.logURL.Redacted(), err)
br.logf(logrus.DebugLevel, "Error reading blob body from %s: %#v", br.logURL.Redacted(), err)
return n, err
}
}
Expand Down

0 comments on commit b08f980

Please sign in to comment.