Repository: getsentry/sentry

Issue:
UX for equations limitations
### Problem
We have can't support equations with on-demand metrics. We can't remove the feature because some customers are using it (mainly because equations are used in the “Errors by Browser as Percentage” from the Frontend Template), so we need to continue to provide some functionality.

### Proposed solution
- Fall back to indexed events data when using equations
- Inform customers during widget creation
- Mark the widgets using equations in a distinctive way (e.g. warning sign with explanatory tooltip).


Discussion:
- Use the warning icon with tooltip because the customer can still proceed
- mark saved widget with warning sign as well

Resolving patch:
diff --git a/src/sentry/api/helpers/group_index/index.py b/src/sentry/api/helpers/group_index/index.py
--- a/src/sentry/api/helpers/group_index/index.py
+++ b/src/sentry/api/helpers/group_index/index.py
@@ -80,8 +80,14 @@ def build_query_params_from_request(
             query_kwargs["cursor"] = Cursor.from_string(request.GET.get("cursor"))
         except ValueError:
             raise ParseError(detail="Invalid cursor parameter.")
+
     has_query = request.GET.get("query")
-    query = request.GET.get("query", "is:unresolved").strip()
+    query = request.GET.get("query", None)
+    if query is None:
+        query = _get_default_query(organization)
+
+    query = query.strip()
+
     if request.GET.get("savedSearch") == "0" and request.user and not has_query:
         saved_searches = (
             SavedSearch.objects
@@ -312,3 +318,10 @@ def get_first_last_release_info(
         item if item is not None else {"version": version}
         for item, version in zip(serialized_releases, versions)
     ]
+
+
+def _get_default_query(organization: Organization) -> str:
+    if features.has("organizations:issue-priority-ui", organization):
+        return "is:unresolved issue.priority:[high, medium]"
+
+    return "is:unresolved"
diff --git a/src/sentry/issues/endpoints/organization_group_index.py b/src/sentry/issues/endpoints/organization_group_index.py
--- a/src/sentry/issues/endpoints/organization_group_index.py
+++ b/src/sentry/issues/endpoints/organization_group_index.py
@@ -354,9 +354,9 @@ def get(self, request: Request, organization) -> Response:
             serializer(
                 start=start,
                 end=end,
-                search_filters=query_kwargs["search_filters"]
-                if "search_filters" in query_kwargs
-                else None,
+                search_filters=(
+                    query_kwargs["search_filters"] if "search_filters" in query_kwargs else None
+                ),
                 organization_id=organization.id,
             ),
             request=request,


Test patch:
diff --git a/tests/snuba/api/endpoints/test_organization_events_meta.py b/tests/snuba/api/endpoints/test_organization_events_meta.py
--- a/tests/snuba/api/endpoints/test_organization_events_meta.py
+++ b/tests/snuba/api/endpoints/test_organization_events_meta.py
@@ -8,6 +8,7 @@
 from sentry.issues.grouptype import ProfileFileIOGroupType
 from sentry.testutils.cases import APITestCase, SnubaTestCase
 from sentry.testutils.helpers.datetime import before_now, iso_format
+from sentry.testutils.helpers.features import with_feature
 from sentry.testutils.silo import region_silo_test
 from tests.sentry.issues.test_utils import SearchIssueTestMixin
 
@@ -76,6 +77,15 @@ def test_invalid_query(self):
 
         assert response.status_code == 400, response.content
 
+    @with_feature("organizations:issue-priority-ui")
+    def test_invalid_query_priority(self):
+        with self.feature(self.features):
+            response = self.client.get(
+                self.url, {"query": "is:unresolved priority:[high, medium]"}, format="json"
+            )
+
+        assert response.status_code == 400, response.content
+
     def test_no_projects(self):
         no_project_org = self.create_organization(owner=self.user)
 
diff --git a/tests/snuba/api/endpoints/test_organization_group_index.py b/tests/snuba/api/endpoints/test_organization_group_index.py
--- a/tests/snuba/api/endpoints/test_organization_group_index.py
+++ b/tests/snuba/api/endpoints/test_organization_group_index.py
@@ -52,7 +52,7 @@
 from sentry.testutils.helpers.features import with_feature
 from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
 from sentry.types.activity import ActivityType
-from sentry.types.group import GroupSubStatus
+from sentry.types.group import GroupSubStatus, PriorityLevel
 from sentry.utils import json
 
 
@@ -1924,6 +1924,47 @@ def test_filter_not_unresolved(self):
         assert response.status_code == 200
         assert [int(r["id"]) for r in response.data] == [event.group.id]
 
+    def test_default_search(self):
+        event1 = self.store_event(
+            data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
+            project_id=self.project.id,
+        )
+        event2 = self.store_event(
+            data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-2"]},
+            project_id=self.project.id,
+        )
+        event2.group.update(status=GroupStatus.RESOLVED, substatus=None)
+
+        self.login_as(user=self.user)
+        response = self.get_response(sort_by="date", limit=10, expand="inbox", collapse="stats")
+        assert response.status_code == 200
+        assert [int(r["id"]) for r in response.data] == [event1.group.id]
+
+    @with_feature("organizations:issue-priority-ui")
+    def test_default_search_with_priority(self):
+        event1 = self.store_event(
+            data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
+            project_id=self.project.id,
+        )
+        event1.group.update(priority=PriorityLevel.HIGH)
+        event2 = self.store_event(
+            data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-3"]},
+            project_id=self.project.id,
+        )
+        event2.group.update(
+            priority=PriorityLevel.HIGH, status=GroupStatus.RESOLVED, substatus=None
+        )
+        event3 = self.store_event(
+            data={"timestamp": iso_format(before_now(seconds=400)), "fingerprint": ["group-2"]},
+            project_id=self.project.id,
+        )
+        event3.group.update(priority=PriorityLevel.LOW)
+
+        self.login_as(user=self.user)
+        response = self.get_response(sort_by="date", limit=10, expand="inbox", collapse="stats")
+        assert response.status_code == 200
+        assert [int(r["id"]) for r in response.data] == [event1.group.id]
+
     def test_collapse_stats(self):
         event = self.store_event(
             data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},