Skip to content

chore(storage): log additional bytes#14608

Open
cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:logbytes
Open

chore(storage): log additional bytes#14608
cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:logbytes

Conversation

@cpriti-os
Copy link
Copy Markdown
Contributor

No description provided.

@cpriti-os cpriti-os requested review from a team as code owners May 18, 2026 12:00
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label May 18, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements logging to detect and report instances where Google Cloud Storage returns more data than requested, covering both the standard Reader and the gRPC multi-range downloader. Feedback highlights a missing 'bytes' import in the tests and suggests a more robust method for capturing log output to avoid side effects on global state. Additionally, the reviewer noted that the current logging logic might under-report the total number of extra bytes if they are delivered across multiple read calls or gRPC chunks.

Comment thread storage/reader_test.go
Comment thread storage/reader_test.go Outdated
Comment thread storage/reader_test.go Outdated
Comment thread storage/reader.go Outdated
Comment thread storage/grpc_reader_multi_range.go Outdated
// failRange capacity calculations.
if req.length >= 0 && req.bytesWritten > req.length {
if !req.extraBytesLogged {
log.Printf("storage: received %d more bytes than requested from GCS", req.bytesWritten-req.length)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the issue in Reader.Read, the count of extra bytes logged here might be under-reported if the excess data is delivered across multiple gRPC data chunks. The extraBytesLogged flag ensures only the first chunk that exceeds the limit is logged, which may not represent the total amount of additional data received from GCS.

req.completed = true
delete(mrdStream.pendingRanges, req.readID)
mrdStream.updateCapacity(m, -1, 0)
if req.length >= 0 && req.bytesWritten > req.length {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check scenarios with negative length and negative offset? I know we convert them when the metadata is available but can be useful to doubt check.

Comment thread storage/reader.go

func (r *Reader) Read(p []byte) (int, error) {
n, err := r.reader.Read(p)
r.mu.Lock()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this locking will introduce regressions. Should perform some regression testing I think.

Comment thread storage/reader.go
Comment on lines 375 to 377
if r.remain != -1 {
r.remain -= int64(n)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the explicit check for -1? I don't see us initializing r.remain with -1 anywhere. Can you check if it is still relevant?

Comment thread storage/reader_test.go

r := &Reader{
reader: m,
remain: 5, // We pretend we only requested 5 bytes
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Add periods everywhere.

Comment thread storage/reader_test.go
}

logStr := logOutput.String()
expectedLog := `storage: received 7 more bytes than requested from GCS for bucket "my-bucket", object "my-object"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: replace "my-bucket" with r.bucket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants