-
Notifications
You must be signed in to change notification settings - Fork 663
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
BlobUploader utilities to enable handling of large data in instrumentation #3122
Draft
michaelsafyan
wants to merge
21
commits into
open-telemetry:main
Choose a base branch
from
michaelsafyan:blob_upload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4341b2e
Start of BlobUploader code in Python client library.
michaelsafyan 924cd37
Implement the adaptor, add comments.
michaelsafyan 84fe250
Implement the GCS uploader.
michaelsafyan dba3aea
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan 8cd6ce1
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan 9906a13
Began adding tests.
michaelsafyan 8a4362e
Upload current snapshot.
michaelsafyan 1667374
Add dependencies.
michaelsafyan 41b7eea
Add more tests and fix some of the code that wasn't working.
michaelsafyan 2b51a15
Completed writing unit tests for functionality implemented so far.
michaelsafyan 410099a
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan d147a79
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan 0a3430e
Add license comments and documentation.
michaelsafyan 587e61e
Remove redundant explicit inheritance from object per review comment.
michaelsafyan c25a6b8
Format with ruff.
michaelsafyan a7bb5f5
Address additional ruff checks that could not be automatically fixed.
michaelsafyan 7f88a2b
Apply suggestions from code review
michaelsafyan 2ce62f6
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan ef648de
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan 6965a44
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan ab94250
Merge branch 'open-telemetry:main' into blob_upload
michaelsafyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add more tests and fix some of the code that wasn't working.
- Loading branch information
commit 41b7eead616012e437085b764ad65b6746ef2ab2
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...trumentation/src/opentelemetry/instrumentation/_blobupload/backend/google/gcs/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
from opentelemetry.instrumentation._blobupload.backend.google.gcs._gcs_impl import GcsBlobUploader | ||
|
||
__all__ = [ | ||
GcsBlobUploader | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""Exposes API methods to callers from the package name.""" | ||
|
||
from opentelemetry.instrumentation._blobupload.utils.simple_blob_uploader_adaptor import blob_uploader_from_simple_blob_uploader | ||
from opentelemetry.instrumentation._blobupload.utils.simple_blob_uploader import SimpleBlobUploader | ||
|
||
__all__ = [ | ||
blob_uploader_from_simple_blob_uploader, | ||
SimpleBlobUploader, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
opentelemetry-instrumentation/tests/_blobupload/api/test_blob.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#! /usr/bin/env python3 | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
sys.path.append("../../../src") | ||
|
||
import base64 | ||
import unittest | ||
|
||
|
||
from opentelemetry.instrumentation._blobupload.api import Blob | ||
|
||
|
||
class TestBlob(unittest.TestCase): | ||
|
||
def test_construction_with_just_bytes(self): | ||
data = 'some string'.encode() | ||
blob = Blob(data) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertIsNone(blob.content_type) | ||
self.assertIsNotNone(blob.labels) | ||
self.assertEqual(len(blob.labels), 0) | ||
|
||
def test_construction_with_bytes_and_content_type(self): | ||
data = 'some string'.encode() | ||
content_type = 'text/plain' | ||
blob = Blob(data, content_type=content_type) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertEqual(blob.content_type, content_type) | ||
self.assertIsNotNone(blob.labels) | ||
self.assertEqual(len(blob.labels), 0) | ||
|
||
def test_construction_with_bytes_and_labels(self): | ||
data = 'some string'.encode() | ||
labels = {'key1': 'value1', 'key2': 'value2'} | ||
blob = Blob(data, labels=labels) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertIsNone(blob.content_type) | ||
self.assert_labels_equal(blob.labels, labels) | ||
|
||
def test_construction_with_all_fields(self): | ||
data = 'some string'.encode() | ||
content_type = 'text/plain' | ||
labels = {'key1': 'value1', 'key2': 'value2'} | ||
blob = Blob(data, content_type=content_type, labels=labels) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertEqual(blob.content_type, content_type) | ||
self.assert_labels_equal(blob.labels, labels) | ||
|
||
def test_from_data_uri_without_labels(self): | ||
data = 'some string'.encode() | ||
content_type = 'text/plain' | ||
encoded_data = base64.b64encode(data).decode() | ||
uri = 'data:{};base64,{}'.format(content_type, encoded_data) | ||
blob = Blob.from_data_uri(uri) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertEqual(blob.content_type, content_type) | ||
self.assertIsNotNone(blob.labels) | ||
self.assertEqual(len(blob.labels), 0) | ||
|
||
def test_from_data_uri_with_labels(self): | ||
data = 'some string'.encode() | ||
content_type = 'text/plain' | ||
encoded_data = base64.b64encode(data).decode() | ||
uri = 'data:{};base64,{}'.format(content_type, encoded_data) | ||
labels = {'key1': 'value1', 'key2': 'value2'} | ||
blob = Blob.from_data_uri(uri, labels=labels) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertEqual(blob.content_type, content_type) | ||
self.assert_labels_equal(blob.labels, labels) | ||
|
||
def test_from_data_uri_with_valid_standard_base64(self): | ||
data = 'some string'.encode() | ||
content_type = 'text/plain' | ||
encoded_data = base64.standard_b64encode(data).decode() | ||
uri = 'data:{};base64,{}'.format(content_type, encoded_data) | ||
blob = Blob.from_data_uri(uri) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertEqual(blob.content_type, content_type) | ||
|
||
def test_from_data_uri_with_valid_websafe_base64(self): | ||
data = 'some string'.encode() | ||
content_type = 'text/plain' | ||
encoded_data = base64.urlsafe_b64encode(data).decode() | ||
uri = 'data:{};base64,{}'.format(content_type, encoded_data) | ||
blob = Blob.from_data_uri(uri) | ||
self.assertEqual(blob.raw_bytes, data) | ||
self.assertEqual(blob.content_type, content_type) | ||
|
||
def test_from_data_uri_with_non_data_uri_content(self): | ||
with self.assertRaisesRegex(ValueError, 'expected "data:" prefix'): | ||
Blob.from_data_uri('not a valid data uri') | ||
|
||
def test_from_data_uri_with_non_base64_content(self): | ||
with self.assertRaisesRegex(ValueError, 'expected ";base64," section'): | ||
Blob.from_data_uri('data:text/plain,validifpercentencoded') | ||
|
||
def assert_labels_equal(self, a, b): | ||
self.assertEqual(len(a), len(b), msg='Different sizes: {} vs {}; a={}, b={}'.format(len(a), len(b), a, b)) | ||
for k in a: | ||
self.assertTrue(k in b, msg='Key {} found in a but not b'.format(k)) | ||
va = a[k] | ||
vb = b[k] | ||
self.assertEqual(va, vb, msg='Values for key {} different for a vs b: {} vs {}'.format(k, va, vb)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this would be easier to extend if this was a
classmethod
that returnedcls(raw_bytes, content_type=content_type, labels=labels)
.Alternatively, if this class shouldn't be subclassed, it should be marked as final.