Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/sentry/objectstore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from sentry import options as options_store
from sentry.objectstore.service import Client, ClientBuilder

__all__ = ["attachments", "Client", "ClientBuilder"]

options = options_store.get("objectstore.config")
attachments = ClientBuilder(options["base_url"], "attachments", options)
attachments = ClientBuilder("attachments")
9 changes: 5 additions & 4 deletions src/sentry/objectstore/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ class GetResult(NamedTuple):
class ClientBuilder:
def __init__(
self,
objectstore_base_url: str,
usecase: str,
options: dict | None = None,
propagate_traces: bool = False,
):
self._base_url = objectstore_base_url
self._usecase = usecase
self._options = options
self._default_compression: Compression = "zstd"
self._propagate_traces = propagate_traces
_ = options

def _make_client(self, scope: str) -> Client:
pool = urllib3.connectionpool.connection_from_url(self._base_url)
from sentry import options as options_store

options = self._options or options_store.get("objectstore.config")
pool = urllib3.connectionpool.connection_from_url(options["base_url"])
return Client(pool, self._default_compression, self._usecase, scope, self._propagate_traces)

def default_compression(self, default_compression: Compression) -> Self:
Expand Down
57 changes: 1 addition & 56 deletions tests/sentry/deletions/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from sentry import deletions, nodestore
from sentry.deletions.tasks.groups import delete_groups_for_project
from sentry.issues.grouptype import FeedbackGroup, GroupCategory
from sentry.issues.grouptype import GroupCategory
from sentry.issues.issue_occurrence import IssueOccurrence
from sentry.models.eventattachment import EventAttachment
from sentry.models.group import Group
Expand Down Expand Up @@ -383,61 +383,6 @@ def select_rows(
def tenant_ids(self) -> dict[str, str]:
return {"referrer": self.referrer, "organization_id": self.organization.id}

def test_simple_issue_platform(self) -> None:
# Adding this query here to make sure that the cache is not being used
assert self.select_error_events(self.project.id) is None
assert self.select_issue_platform_events(self.project.id) is None

# Create initial error event and occurrence related to it; two different groups will exist
event = self.store_event(data={}, project_id=self.project.id)
# XXX: We need a different way of creating occurrences which will insert into the nodestore
occurrence_event, issue_platform_group = self.create_occurrence(
event, type_id=FeedbackGroup.type_id
)

# Assertions after creation
assert occurrence_event.id != event.event_id
assert event.group_id != issue_platform_group.id
assert event.group.issue_category == GroupCategory.ERROR
assert issue_platform_group.issue_category == GroupCategory.FEEDBACK
assert issue_platform_group.type == FeedbackGroup.type_id

# Assert that the error event has been inserted in the nodestore & Snuba
event_node_id = Event.generate_node_id(event.project_id, event.event_id)
assert nodestore.backend.get(event_node_id)
expected_error = {"event_id": event.event_id, "group_id": event.group_id}
assert self.select_error_events(self.project.id) == expected_error

# Assert that the occurrence event has been inserted in the nodestore & Snuba
# occurrence_node_id = Event.generate_node_id(
# occurrence_event.project_id, occurrence_event.id
# )
# assert nodestore.backend.get(occurrence_node_id)
expected_occurrence_event = {
"event_id": occurrence_event.event_id,
"group_id": issue_platform_group.id,
"occurrence_id": occurrence_event.id,
}
assert self.select_issue_platform_events(self.project.id) == expected_occurrence_event

# This will delete the group and the events from the node store and Snuba
with self.tasks():
delete_groups_for_project(
object_ids=[issue_platform_group.id],
transaction_id=uuid4().hex,
project_id=self.project.id,
)

# The original error event and group still exist
assert Group.objects.filter(id=event.group_id).exists()
assert nodestore.backend.get(event_node_id)
assert self.select_error_events(self.project.id) == expected_error

# The Issue Platform group and occurrence have been deleted
assert not Group.objects.filter(id=issue_platform_group.id).exists()
# assert not nodestore.backend.get(occurrence_node_id)
assert self.select_issue_platform_events(self.project.id) is None

@mock.patch("sentry.deletions.tasks.nodestore.bulk_snuba_queries")
def test_issue_platform_batching(self, mock_bulk_snuba_queries: mock.Mock) -> None:
# Patch max_rows_to_delete to a small value for testing
Expand Down
8 changes: 4 additions & 4 deletions tests/sentry/objectstore/test_objectstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Testserver:

def test_object_url() -> None:
server = Testserver()
client = ClientBuilder(server.url, "test").for_project(123, 456)
client = ClientBuilder("test", {"base_url": server.url}).for_project(123, 456)

assert (
client.object_url("foo")
Expand All @@ -24,7 +24,7 @@ def test_object_url() -> None:

def test_stores_uncompressed() -> None:
server = Testserver()
client = ClientBuilder(server.url, "test").for_organization(12345)
client = ClientBuilder("test", {"base_url": server.url}).for_organization(12345)

body = b"oh hai!"
stored_id = client.put(body, "foo", compression="none")
Expand All @@ -38,7 +38,7 @@ def test_stores_uncompressed() -> None:

def test_uses_zstd_by_default() -> None:
server = Testserver()
client = ClientBuilder(server.url, "test").for_organization(12345)
client = ClientBuilder("test", {"base_url": server.url}).for_organization(12345)

body = b"oh hai!"
stored_id = client.put(body, "foo")
Expand All @@ -59,7 +59,7 @@ def test_uses_zstd_by_default() -> None:

def test_deletes_stored_stuff() -> None:
server = Testserver()
client = ClientBuilder(server.url, "test").for_organization(12345)
client = ClientBuilder("test", {"base_url": server.url}).for_organization(12345)

body = b"oh hai!"
stored_id = client.put(body, "foo")
Expand Down
Loading