Skip to content

Commit 3f12dc9

Browse files
committed
Also record, and output, the time of last retry, if any
This will be used for more heuristics. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent f14b391 commit 3f12dc9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

docker/body_reader.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type bodyReader struct {
3131

3232
body io.ReadCloser // The currently open connection we use to read data, or nil if there is nothing to read from / close.
3333
lastRetryOffset int64
34+
lastRetryTime time.Time // time.Time{} if N/A
3435
offset int64 // Current offset within the blob
3536
lastSuccessTime time.Time // time.Time{} if N/A
3637
}
@@ -52,7 +53,9 @@ func newBodyReader(ctx context.Context, c *dockerClient, path string, firstBody
5253

5354
body: firstBody,
5455
lastRetryOffset: 0,
56+
lastRetryTime: time.Time{},
5557
offset: 0,
58+
lastSuccessTime: time.Time{},
5659
}
5760
return res, nil
5861
}
@@ -190,6 +193,7 @@ func (br *bodyReader) Read(p []byte) (int, error) {
190193
consumedBody = true
191194
br.body = res.Body
192195
br.lastRetryOffset = br.offset
196+
br.lastRetryTime = time.Time{}
193197
return n, nil
194198

195199
default:
@@ -212,14 +216,15 @@ func millisecondsSinceOptional(currentTime time.Time, tm time.Time) float64 {
212216
func (br *bodyReader) errorIfNotReconnecting(originalErr error, redactedURL string) error {
213217
currentTime := time.Now()
214218
msSinceFirstConnection := millisecondsSinceOptional(currentTime, br.firstConnectionTime)
219+
msSinceLastRetry := millisecondsSinceOptional(currentTime, br.lastRetryTime)
215220
msSinceLastSuccess := millisecondsSinceOptional(currentTime, br.lastSuccessTime)
216-
logrus.Debugf("Reading blob body from %s failed (%#v), decision inputs: lastRetryOffset %d, offset %d, %.3f ms since first connection, %.3f ms since last progress",
217-
redactedURL, originalErr, br.lastRetryOffset, br.offset, msSinceFirstConnection, msSinceLastSuccess)
221+
logrus.Debugf("Reading blob body from %s failed (%#v), decision inputs: total %d @%.3f ms, last retry %d @%.3f ms, last progress @%.3f ms",
222+
redactedURL, originalErr, br.offset, msSinceFirstConnection, br.lastRetryOffset, msSinceLastRetry, msSinceLastSuccess)
218223
progress := br.offset - br.lastRetryOffset
219224
if progress < bodyReaderMinimumProgress {
220225
logrus.Debugf("Not reconnecting to %s because only %d bytes progress made", redactedURL, progress)
221-
return fmt.Errorf("(heuristic tuning data: last retry %d, current offset %d; %.3f ms total, %.3f ms since progress): %w",
222-
br.lastRetryOffset, br.offset, msSinceFirstConnection, msSinceLastSuccess, originalErr)
226+
return fmt.Errorf("(heuristic tuning data: total %d @%.3f ms, last retry %d @%.3f ms, last progress @ %.3f ms): %w",
227+
br.offset, msSinceFirstConnection, br.lastRetryOffset, msSinceLastRetry, msSinceLastSuccess, originalErr)
223228
}
224229
logrus.Infof("Reading blob body from %s failed (%v), reconnecting…", redactedURL, originalErr)
225230
return nil

0 commit comments

Comments
 (0)