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
85 changes: 32 additions & 53 deletions src/sentry/testutils/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,30 +1138,21 @@ def store_group(self, group):
== 200
)

def store_span(self, span, is_eap=True):
self.store_spans([span], is_eap=is_eap)

def store_spans(self, spans, is_eap=True):
if is_eap:
files = {}
for i, span in enumerate(spans):
trace_item = span_to_trace_item(span)
files[f"item_{i}"] = trace_item.SerializeToString()
assert (
requests.post(
settings.SENTRY_SNUBA + EAP_ITEMS_INSERT_ENDPOINT,
files=files,
).status_code
== 200
)
else:
assert (
requests.post(
settings.SENTRY_SNUBA + "/tests/entities/spans/insert",
data=json.dumps(spans),
).status_code
== 200
)
def store_span(self, span):
self.store_spans([span])

def store_spans(self, spans):
files = {}
for i, span in enumerate(spans):
trace_item = span_to_trace_item(span)
files[f"item_{i}"] = trace_item.SerializeToString()
assert (
requests.post(
settings.SENTRY_SNUBA + EAP_ITEMS_INSERT_ENDPOINT,
files=files,
).status_code
== 200
)

def store_ourlogs(self, ourlogs):
files = {f"log_{i}": log.SerializeToString() for i, log in enumerate(ourlogs)}
Expand Down Expand Up @@ -1302,7 +1293,6 @@ def store_segment(
status: str | None = None,
environment: str | None = None,
organization_id: int = 1,
is_eap: bool = True,
):
if span_id is None:
span_id = self._random_span_id()
Expand Down Expand Up @@ -1355,7 +1345,7 @@ def store_segment(
if parent_span_id:
payload["parent_span_id"] = parent_span_id

self.store_span(payload, is_eap=is_eap)
self.store_span(payload)

def store_indexed_span(
self,
Expand All @@ -1376,7 +1366,6 @@ def store_indexed_span(
group: str = "00",
category: str | None = None,
organization_id: int = 1,
is_eap: bool = True,
):
if span_id is None:
span_id = self._random_span_id()
Expand Down Expand Up @@ -1427,7 +1416,7 @@ def store_indexed_span(
# We want to give the caller the possibility to store only a summary since the database does not deduplicate
# on the span_id which makes the assumptions of a unique span_id in the database invalid.
if not store_only_summary:
self.store_span(payload, is_eap=is_eap)
self.store_span(payload)


class BaseMetricsTestCase(SnubaTestCase):
Expand Down Expand Up @@ -2265,30 +2254,21 @@ def function_fingerprint(self, function):
hasher.update(function["function"].encode())
return int(hasher.hexdigest()[:8], 16)

def store_span(self, span, is_eap=True):
self.store_spans([span], is_eap=is_eap)
def store_span(self, span):
self.store_spans([span])

def store_spans(self, spans, is_eap=True):
if is_eap:
files = {}
for i, span in enumerate(spans):
trace_item = span_to_trace_item(span)
files[f"item_{i}"] = trace_item.SerializeToString()
assert (
requests.post(
settings.SENTRY_SNUBA + EAP_ITEMS_INSERT_ENDPOINT,
files=files,
).status_code
== 200
)
else:
assert (
requests.post(
settings.SENTRY_SNUBA + "/tests/entities/spans/insert",
data=json.dumps(spans),
).status_code
== 200
)
def store_spans(self, spans):
files = {}
for i, span in enumerate(spans):
trace_item = span_to_trace_item(span)
files[f"item_{i}"] = trace_item.SerializeToString()
assert (
requests.post(
settings.SENTRY_SNUBA + EAP_ITEMS_INSERT_ENDPOINT,
files=files,
).status_code
== 200
)


@pytest.mark.snuba
Expand Down Expand Up @@ -3682,7 +3662,6 @@ def create_event(
slow_db_performance_issue: bool = False,
start_timestamp: datetime | None = None,
store_event_kwargs: dict[str, Any] | None = None,
is_eap: bool = True,
) -> Event:
if not store_event_kwargs:
store_event_kwargs = {}
Expand Down Expand Up @@ -3762,7 +3741,7 @@ def create_event(
)
)
spans_to_store.append(self.convert_event_data_to_span(event))
self.store_spans(spans_to_store, is_eap=is_eap)
self.store_spans(spans_to_store)
return event

def convert_event_data_to_span(self, event: Event) -> dict[str, Any]:
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/test_explore_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_spans_table_loads_all_events(self, mock_now: MagicMock) -> None:
]
self.store_spans(
spans,
is_eap=True,
)

self.page.visit_explore_spans(self.organization.slug)
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/test_trace_view_from_explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def test_navigation(self, mock_now: MagicMock) -> None:
parent_span_id=None,
project_id=self.project.id,
milliseconds=3000,
is_eap=True,
)

# Visit explore spans table
Expand Down
1 change: 0 additions & 1 deletion tests/acceptance/test_trace_view_waterfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def test_trace_view_waterfall_loads(self, mock_now: MagicMock) -> None:
parent_span_id=None,
project_id=self.project.id,
milliseconds=3000,
is_eap=True,
)

# Visit the trace view and wait till waterfall loads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_no_conversations(self) -> None:
{"description": "test", "sentry_tags": {"status": "ok"}},
start_ts=now,
)
self.store_spans([span], is_eap=True)
self.store_spans([span])

query = {
"project": [self.project.id],
Expand Down Expand Up @@ -432,7 +432,7 @@ def test_pagination(self) -> None:
},
start_ts=now - timedelta(minutes=i),
)
self.store_spans([span], is_eap=True)
self.store_spans([span])

query = {
"project": [self.project.id],
Expand Down Expand Up @@ -470,7 +470,7 @@ def test_zero_values(self) -> None:
},
start_ts=now,
)
self.store_spans([span], is_eap=True)
self.store_spans([span])

query = {
"project": [self.project.id],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ def store_ai_span(
extra_data,
start_ts=timestamp,
)
self.store_spans([span], is_eap=True)
self.store_spans([span])
return span
4 changes: 2 additions & 2 deletions tests/sentry/api/endpoints/test_organization_insights_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _store_nextjs_function_spans(self) -> None:
start_ts=self.ten_mins_ago,
)
span["sentry_tags"]["op"] = "function.nextjs"
self.store_span(span, is_eap=True)
self.store_span(span)
spans.append(span)

def _store_unrelated_spans(self) -> None:
Expand All @@ -81,7 +81,7 @@ def _store_unrelated_spans(self) -> None:
start_ts=self.ten_mins_ago,
)
span["sentry_tags"]["op"] = "db"
self.store_span(span, is_eap=True)
self.store_span(span)
spans.append(span)

def test_get_nextjs_function_data(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def test_queries_profile_candidates_from_spans(
span = self.create_span(project=self.project, start_ts=self.ten_mins_ago, duration=1000)
span.update({"profile_id": profile_id})

self.store_span(span, is_eap=True)
self.store_span(span)

# this span has continuous profile with a matching chunk (to be mocked below)
profiler_id = uuid4().hex
Expand All @@ -732,7 +732,7 @@ def test_queries_profile_candidates_from_spans(
)
del span_2["profile_id"]

self.store_span(span_2, is_eap=True)
self.store_span(span_2)

# not able to write profile chunks to the table yet so mock it's response here
# so that the span with a continuous profile looks like it has a profile chunk
Expand Down
14 changes: 1 addition & 13 deletions tests/sentry/api/endpoints/test_organization_spans_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_tags_list_str(self) -> None:
duration=100,
exclusive_time=100,
tags={tag: tag},
is_eap=True,
)

for features in [
Expand Down Expand Up @@ -110,7 +109,6 @@ def test_tags_list_nums(self) -> None:
duration=100,
exclusive_time=100,
measurements={tag: 0},
is_eap=True,
)

for features in [
Expand Down Expand Up @@ -154,7 +152,7 @@ def test_boolean_attributes(self) -> None:
"is_feature_enabled": False,
"is_production": True,
}
self.store_spans([span1, span2], is_eap=True)
self.store_spans([span1, span2])

response = self.do_request(
query={"dataset": "spans", "type": "boolean"},
Expand Down Expand Up @@ -220,7 +218,6 @@ def test_tags_keys(self) -> None:
duration=100,
exclusive_time=100,
tags={"tag": tag},
is_eap=True,
)

response = self.do_request("tag")
Expand Down Expand Up @@ -266,7 +263,6 @@ def test_transaction_keys_autocomplete(self) -> None:
transaction=transaction,
duration=100,
exclusive_time=100,
is_eap=True,
)

key = "transaction"
Expand Down Expand Up @@ -314,7 +310,6 @@ def test_transaction_keys_autocomplete_substring(self) -> None:
transaction=transaction,
duration=100,
exclusive_time=100,
is_eap=True,
)

key = "transaction"
Expand Down Expand Up @@ -354,7 +349,6 @@ def test_transaction_keys_autocomplete_substring_with_asterisk(self) -> None:
transaction=transaction,
duration=100,
exclusive_time=100,
is_eap=True,
)

key = "transaction"
Expand Down Expand Up @@ -395,7 +389,6 @@ def test_tags_keys_autocomplete(self) -> None:
duration=100,
exclusive_time=100,
tags={"tag": tag},
is_eap=True,
)

key = "tag"
Expand Down Expand Up @@ -444,7 +437,6 @@ def test_tags_keys_autocomplete_substring(self) -> None:
duration=100,
exclusive_time=100,
tags={"tag": tag},
is_eap=True,
)

key = "tag"
Expand Down Expand Up @@ -485,7 +477,6 @@ def test_tags_keys_autocomplete_substring_with_asterisks(self) -> None:
duration=100,
exclusive_time=100,
tags={"tag": tag},
is_eap=True,
)

key = "tag"
Expand Down Expand Up @@ -526,7 +517,6 @@ def test_tags_keys_autocomplete_noop(self) -> None:
duration=100,
exclusive_time=100,
tags={"tag": tag},
is_eap=True,
)

for key in [
Expand Down Expand Up @@ -678,7 +668,6 @@ def test_tags_keys_autocomplete_span_status(self) -> None:
timestamp=timestamp,
transaction="foo",
status=status,
is_eap=True,
)

response = self.do_request("span.status")
Expand Down Expand Up @@ -797,7 +786,6 @@ def test_invalid_query(self, mock_executor: mock.MagicMock) -> None:
duration=100,
exclusive_time=100,
tags={"tag": "foo"},
is_eap=True,
)

response = self.do_request("tag")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class OrganizationSpansFieldsStatsEndpointTest(BaseSpansTestCase, APITestCase):
is_eap = True
view = "sentry-api-0-organization-spans-fields-stats"

def setUp(self) -> None:
Expand Down Expand Up @@ -55,7 +54,6 @@ def _generate_one_span(self, tags=None):
duration=100,
exclusive_time=100,
tags=tags,
is_eap=self.is_eap,
)

def test_no_project(self) -> None:
Expand Down
5 changes: 0 additions & 5 deletions tests/sentry/api/endpoints/test_organization_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

class OrganizationTracesEndpointTest(BaseSpansTestCase, APITestCase):
view = "sentry-api-0-organization-traces"
is_eap: bool = True

def setUp(self) -> None:
super().setUp()
Expand Down Expand Up @@ -76,7 +75,6 @@ def double_write_segment(
timestamp=timestamp,
duration=duration,
organization_id=project.organization.id,
is_eap=True,
environment=data.get("environment"),
**kwargs,
)
Expand Down Expand Up @@ -165,7 +163,6 @@ def create_mock_traces(self):
duration=1_000,
exclusive_time=1_000,
op="http.client",
is_eap=True,
)

timestamps.append(now - timedelta(days=1, minutes=19, seconds=40))
Expand All @@ -181,7 +178,6 @@ def create_mock_traces(self):
duration=3_000,
exclusive_time=3_000,
op="db.sql",
is_eap=self.is_eap,
)

timestamps.append(now - timedelta(days=1, minutes=19, seconds=45))
Expand All @@ -197,7 +193,6 @@ def create_mock_traces(self):
duration=3,
exclusive_time=3,
op="db.sql",
is_eap=True,
)

timestamps.append(now - timedelta(days=2, minutes=30))
Expand Down
Loading
Loading