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
3 changes: 3 additions & 0 deletions src/sentry/api/endpoints/organization_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def data_fn(offset, limit):
auto_fields=True,
auto_aggregations=True,
use_aggregate_conditions=True,
use_snql=features.has(
"organizations:discover-use-snql", organization, actor=request.user
),
)

with self.handle_query_errors():
Expand Down
29 changes: 21 additions & 8 deletions tests/snuba/api/endpoints/test_organization_events_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ def setUp(self):
self.min_ago = iso_format(before_now(minutes=1))
self.two_min_ago = iso_format(before_now(minutes=2))
self.transaction_data = load_data("transaction", timestamp=before_now(minutes=1))
self.features = {}

def do_request(self, query, features=None):
if features is None:
features = {"organizations:discover-basic": True}
features.update(self.features)
self.login_as(user=self.user)
url = reverse(
"sentry-api-0-organization-eventsv2",
Expand Down Expand Up @@ -133,8 +135,10 @@ def test_invalid_search_terms(self):
)

@mock.patch("sentry.snuba.discover.raw_query")
def test_handling_snuba_errors(self, mock_query):
@mock.patch("sentry.snuba.discover.raw_snql_query")
def test_handling_snuba_errors(self, mock_snql_query, mock_query):
mock_query.side_effect = RateLimitExceeded("test")
mock_snql_query.side_effect = RateLimitExceeded("test")

project = self.create_project()

Expand All @@ -148,13 +152,15 @@ def test_handling_snuba_errors(self, mock_query):
assert response.data["detail"] == TIMEOUT_ERROR_MESSAGE

mock_query.side_effect = QueryExecutionError("test")
mock_snql_query.side_effect = QueryExecutionError("test")

query = {"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]}
response = self.do_request(query)
assert response.status_code == 500, response.content
assert response.data["detail"] == "Internal error. Your query failed to run."

mock_query.side_effect = QueryIllegalTypeOfArgument("test")
mock_snql_query.side_effect = QueryIllegalTypeOfArgument("test")

query = {"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]}
response = self.do_request(query)
Expand Down Expand Up @@ -1412,6 +1418,7 @@ def test_user_misery_alias_field_with_project_threshold(self):
"transaction",
"user_misery()",
],
"orderby": "user_misery()",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this test never flakey somehow? But 👍 to making the result more deterministic.

"query": "event.type:transaction",
"project": [project.id],
}
Expand All @@ -1422,8 +1429,8 @@ def test_user_misery_alias_field_with_project_threshold(self):
assert len(response.data["data"]) == 3
data = response.data["data"]
assert abs(data[0]["user_misery"] - 0.04916) < 0.0001
assert abs(data[1]["user_misery"] - 0.06586) < 0.0001
assert abs(data[2]["user_misery"] - 0.05751) < 0.0001
assert abs(data[1]["user_misery"] - 0.05751) < 0.0001
assert abs(data[2]["user_misery"] - 0.06586) < 0.0001
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on using pytest.approx going forwards?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, we can update in a future PR cc @shruthilayaj (as a btw not saying you're the one who has to do it)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh nice, good to know 👍


query["query"] = "event.type:transaction user_misery():>0.050"

Expand All @@ -1434,8 +1441,8 @@ def test_user_misery_alias_field_with_project_threshold(self):
assert response.status_code == 200, response.content
assert len(response.data["data"]) == 2
data = response.data["data"]
assert abs(data[0]["user_misery"] - 0.06586) < 0.0001
assert abs(data[1]["user_misery"] - 0.05751) < 0.0001
assert abs(data[0]["user_misery"] - 0.05751) < 0.0001
assert abs(data[1]["user_misery"] - 0.06586) < 0.0001

def test_user_misery_alias_field_with_transaction_threshold(self):
project = self.create_project()
Expand Down Expand Up @@ -3166,14 +3173,14 @@ def test_deleted_issue_in_results(self):
event2.group.delete()

features = {"organizations:discover-basic": True, "organizations:global-views": True}
query = {"field": ["issue", "count()"], "sort": "issue"}
query = {"field": ["issue", "count()"], "sort": "count()"}
response = self.do_request(query, features=features)

assert response.status_code == 200, response.content
data = response.data["data"]
assert len(data) == 2
assert data[0]["issue"] == event1.group.qualified_short_id
assert data[1]["issue"] == "unknown"
assert data[0]["issue"] == "unknown"
assert data[1]["issue"] == event1.group.qualified_short_id

def test_last_seen_negative_duration(self):
project = self.create_project()
Expand Down Expand Up @@ -4473,3 +4480,9 @@ def test_mobile_measurements(self):
assert meta["p75_measurements_stall_percentage"] == "percentage"
assert meta["percentile_measurements_frames_slow_rate_0_5"] == "percentage"
assert meta["percentile_measurements_stall_percentage_0_5"] == "percentage"


class OrganizationEventsV2EndpointTestWithSnql(OrganizationEventsV2EndpointTest):
def setUp(self):
super().setUp()
self.features["organizations:discover-use-snql"] = True