-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(objectstore): Add proxying logic to endpoint #104045
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
87ba4c6
wip
lcian 9758721
improve
lcian 8c11c9c
:hammer_and_wrench: Sync API Urls to TypeScirpt
getsantry[bot] fea546f
wip
lcian 775c572
improve
lcian 7683493
improve
lcian e9f335a
improve
lcian 66ebac5
improve
lcian 79e719c
upgrade client
lcian 3d2fd59
improve
lcian e0b02dd
mypy
lcian 30f97e8
Merge branch 'master' into lcian/feat/objectstore-endpoint
lcian e7fa993
temporarily disable part of test
lcian 3b1a5ea
fix
lcian 65ff5f6
improve
lcian aa82965
improve
lcian f740ef9
improve
lcian 37203b7
improve
lcian 9eba556
improve
lcian 71c1119
improve
lcian 77152d0
Merge branch 'master' into lcian/feat/objectstore-endpoint
lcian ec029ac
improve
lcian f1d40e1
improve
lcian b564309
refactor a bit
lcian 9c06fd9
fix problem
lcian dc8a27c
improve
lcian e4f989b
improve
lcian 13b8854
improve
lcian eb3cefa
ssrf
lcian f69d8b0
improve
lcian 7e90176
work with granian
lcian ad18506
improve
lcian 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
100 changes: 90 additions & 10 deletions
100
tests/sentry/objectstore/endpoints/test_organization.py
This file contains hidden or 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,23 +1,103 @@ | ||
| from sentry.testutils.cases import APITestCase | ||
| import pytest | ||
| import requests | ||
| from django.urls import reverse | ||
| from objectstore_client import Client, RequestError, Session, Usecase | ||
| from pytest_django.live_server_helper import LiveServer | ||
|
|
||
| from sentry.testutils.cases import TransactionTestCase | ||
| from sentry.testutils.helpers.features import with_feature | ||
| from sentry.testutils.silo import region_silo_test | ||
| from sentry.testutils.skips import requires_objectstore | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def local_live_server(request: pytest.FixtureRequest, live_server: LiveServer) -> None: | ||
| if hasattr(request, "cls"): | ||
| request.cls.live_server = live_server | ||
| request.node.live_server = live_server | ||
|
|
||
|
|
||
| @region_silo_test | ||
| class OrganizationObjectstoreEndpointTest(APITestCase): | ||
| @requires_objectstore | ||
| @pytest.mark.usefixtures("local_live_server") | ||
| class OrganizationObjectstoreEndpointTest(TransactionTestCase): | ||
| endpoint = "sentry-api-0-organization-objectstore" | ||
| live_server: LiveServer | ||
|
|
||
| def setUp(self) -> None: | ||
| super().setUp() | ||
| self.login_as(user=self.user) | ||
| self.organization = self.create_organization(owner=self.user) | ||
| self.api_key = self.create_api_key( | ||
| organization=self.organization, | ||
| scope_list=["org:admin"], | ||
| ) | ||
|
|
||
| def test_feature_flag_disabled(self): | ||
| """Without feature flag, returns 404""" | ||
| response = self.get_response(self.organization.slug) | ||
| assert response.status_code == 404 | ||
| def get_endpoint_url(self) -> str: | ||
| path = reverse( | ||
| self.endpoint, | ||
| kwargs={ | ||
| "organization_id_or_slug": self.organization.id, | ||
| "path": "", | ||
| }, | ||
| ) | ||
| return f"{self.live_server.url}{path}" | ||
|
|
||
| def get_auth_headers(self) -> dict[str, str]: | ||
| auth_header = self.create_basic_auth_header(self.api_key.key) | ||
| return {"Authorization": auth_header.decode()} | ||
|
|
||
| def get_session(self) -> Session: | ||
| client = Client( | ||
| self.get_endpoint_url(), connection_kwargs={"headers": self.get_auth_headers()} | ||
| ) | ||
| session = client.session(Usecase("test"), org=self.organization.id) | ||
| return session | ||
|
|
||
| @with_feature("organizations:objectstore-endpoint") | ||
| def test_feature_flag_enabled(self): | ||
| """With feature flag, endpoint is accessible""" | ||
| response = self.get_response(self.organization.slug) | ||
| assert response.status_code == 200 | ||
| def test_health(self): | ||
| url = self.get_endpoint_url() + "health" | ||
| res = requests.get(url, headers=self.get_auth_headers()) | ||
| res.raise_for_status() | ||
|
|
||
| @with_feature("organizations:objectstore-endpoint") | ||
| def test_full_cycle(self): | ||
| session = self.get_session() | ||
|
|
||
| object_key = session.put(b"test data") | ||
| assert object_key is not None | ||
|
|
||
| retrieved = session.get(object_key) | ||
| assert retrieved.payload.read() == b"test data" | ||
|
|
||
| new_key = session.put(b"new data", key=object_key) | ||
| assert new_key == object_key | ||
|
|
||
| retrieved = session.get(object_key) | ||
| assert retrieved.payload.read() == b"new data" | ||
|
|
||
| session.delete(object_key) | ||
|
|
||
| with pytest.raises(RequestError): | ||
| session.get(object_key) | ||
|
|
||
| @with_feature("organizations:objectstore-endpoint") | ||
| def test_uncompressed(self): | ||
| session = self.get_session() | ||
|
|
||
| object_key = session.put(b"test data", compression="none") | ||
| assert object_key is not None | ||
|
|
||
| retrieved = session.get(object_key) | ||
| assert retrieved.payload.read() == b"test data" | ||
|
|
||
| @with_feature("organizations:objectstore-endpoint") | ||
| def test_large_payload(self): | ||
| session = self.get_session() | ||
| data = b"A" * 1_000_000 | ||
|
|
||
| object_key = session.put(data) | ||
| assert object_key is not None | ||
|
|
||
| retrieved = session.get(object_key) | ||
| assert retrieved.payload.read() == data | ||
lcian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.