Просмотр исходного кода

feat(snql): Enable snql on the data export (#30702)

- Going to be behind the discover feature flag
William Mak 3 лет назад
Родитель
Сommit
9407a8521e

+ 1 - 0
src/sentry/data_export/endpoints/data_export.py

@@ -84,6 +84,7 @@ class DataExportQuerySerializer(serializers.Serializer):
                 del query_info["statsPeriodEnd"]
             query_info["start"] = start.isoformat()
             query_info["end"] = end.isoformat()
+            query_info["use_snql"] = features.has("organizations:discover-use-snql", organization)
 
             # validate the query string by trying to parse it
             processor = DiscoverProcessor(

+ 3 - 1
src/sentry/data_export/processors/discover.py

@@ -44,6 +44,7 @@ class DiscoverProcessor:
             query=discover_query["query"],
             params=self.params,
             sort=discover_query.get("sort"),
+            use_snql=discover_query.get("use_snql", False),
         )
 
     @staticmethod
@@ -75,7 +76,7 @@ class DiscoverProcessor:
         return environment_names
 
     @staticmethod
-    def get_data_fn(fields, equations, query, params, sort):
+    def get_data_fn(fields, equations, query, params, sort, use_snql=False):
         def data_fn(offset, limit):
             return discover.query(
                 selected_columns=fields,
@@ -89,6 +90,7 @@ class DiscoverProcessor:
                 auto_fields=True,
                 auto_aggregations=True,
                 use_aggregate_conditions=True,
+                use_snql=use_snql,
             )
 
         return data_fn

+ 13 - 0
tests/sentry/data_export/processors/test_discover.py

@@ -16,6 +16,7 @@ class DiscoverProcessorTest(TestCase, SnubaTestCase):
             "project": [self.project1.id, self.project2.id],
             "field": ["count(id)", "fake(field)", "issue"],
             "query": "",
+            "use_snql": False,
         }
 
     def test_get_projects(self):
@@ -58,3 +59,15 @@ class DiscoverProcessorTest(TestCase, SnubaTestCase):
         assert new_result_list[0] != result_list
         assert new_result_list[0]["count(id) / fake(field)"] == 5
         assert new_result_list[0]["count(id) / 2"] == 8
+
+
+class DiscoverProcessorTestWithSnql(DiscoverProcessorTest):
+    def setUp(self):
+        super().setUp()
+        self.discover_query = {
+            "statsPeriod": "14d",
+            "project": [self.project1.id, self.project2.id],
+            "field": ["count(id)", "fake(field)", "issue"],
+            "query": "",
+            "use_snql": True,
+        }