-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(storage): log additional bytes received from GCS in read path #17423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1374,6 +1374,45 @@ def test__do_download_wo_chunks_w_range_w_raw_w_headers(self): | |||||||||||||||||||||||||||||||
| w_range=True, raw_download=True, headers={"If-Match": "kittens"} | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @mock.patch("google.cloud.storage.blob._logger") | ||||||||||||||||||||||||||||||||
| def test__do_download_log_extra_bytes(self, mock_logger): | ||||||||||||||||||||||||||||||||
| blob_name = "blob-name" | ||||||||||||||||||||||||||||||||
| client = self._make_client() | ||||||||||||||||||||||||||||||||
| bucket = _Bucket(client) | ||||||||||||||||||||||||||||||||
| blob = self._make_one(blob_name, bucket=bucket) | ||||||||||||||||||||||||||||||||
| blob.chunk_size = None | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| transport = object() | ||||||||||||||||||||||||||||||||
| file_obj = io.BytesIO() | ||||||||||||||||||||||||||||||||
| download_url = "http://test.invalid" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| patch = mock.patch("google.cloud.storage.blob.Download") | ||||||||||||||||||||||||||||||||
| with patch as patched: | ||||||||||||||||||||||||||||||||
| download = patched.return_value | ||||||||||||||||||||||||||||||||
| download._bytes_downloaded = 10 | ||||||||||||||||||||||||||||||||
| type(download).finished = mock.PropertyMock(side_effect=[False, True]) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| mock_response = mock.Mock() | ||||||||||||||||||||||||||||||||
| mock_response.headers = {} | ||||||||||||||||||||||||||||||||
| download.consume_next_chunk.return_value = mock_response | ||||||||||||||||||||||||||||||||
| download._get_headers.return_value = {} | ||||||||||||||||||||||||||||||||
|
Comment on lines
+1391
to
+1398
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test does not actually execute the To make the test effective and ensure the loop runs once, you should mock
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| blob._do_download( | ||||||||||||||||||||||||||||||||
| transport, | ||||||||||||||||||||||||||||||||
| file_obj, | ||||||||||||||||||||||||||||||||
| download_url, | ||||||||||||||||||||||||||||||||
| {}, | ||||||||||||||||||||||||||||||||
| start=0, | ||||||||||||||||||||||||||||||||
| end=4, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| mock_logger.warning.assert_called_once_with( | ||||||||||||||||||||||||||||||||
| "storage: received %d more bytes than requested from GCS for bucket %r, object %r", | ||||||||||||||||||||||||||||||||
| 5, | ||||||||||||||||||||||||||||||||
| "name", | ||||||||||||||||||||||||||||||||
| "blob-name", | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def test__do_download_wo_chunks_w_custom_timeout(self): | ||||||||||||||||||||||||||||||||
| self._do_download_helper_wo_chunks( | ||||||||||||||||||||||||||||||||
| w_range=False, raw_download=False, timeout=9.58 | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the logic in
_media/_download.py,blob.pyshould also handle the case wherestartis negative andendisNone(which requests the last-startbytes of the blob).