Skip to content

Commit

Permalink
chore(storage): add retry metrics for Reader (#6056)
Browse files Browse the repository at this point in the history
With this change, the Reader will also send the x-goog-api-client
retry fields with each request.

Invocation ID will be different if a download is interrupted
partway through and a new ranged request is made. Discussed this
internally and this is expected.
  • Loading branch information
tritone authored May 19, 2022
1 parent bb10f9f commit 1a21711
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions storage/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64)
gen = gen64
}
return nil
}, o.retry, true, setRetryHeaderHTTP(nil))
}, o.retry, true, setRetryHeaderHTTP(&readerRequestWrapper{req}))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -356,6 +356,16 @@ func setConditionsHeaders(headers http.Header, conds *Conditions) error {
return nil
}

// Wrap a request to look similar to an apiary library request, in order to
// be used by run().
type readerRequestWrapper struct {
req *http.Request
}

func (w *readerRequestWrapper) Header() http.Header {
return w.req.Header
}

var emptyBody = ioutil.NopCloser(strings.NewReader(""))

// Reader reads a Cloud Storage object.
Expand Down Expand Up @@ -492,7 +502,7 @@ func (o *ObjectHandle) newRangeReaderWithGRPC(ctx context.Context, offset, lengt
msg, err = stream.Recv()

return err
}, o.retry, true, setRetryHeaderHTTP(nil))
}, o.retry, true, setRetryHeaderGRPC(ctx))
if err != nil {
// Close the stream context we just created to ensure we don't leak
// resources.
Expand Down

0 comments on commit 1a21711

Please sign in to comment.