Browse Source

fix(functions): ProfileFunctionsMetrics missing query source arg (#76267)

Fixes SENTRY-3DPV
Tony Xiao 7 months ago
parent
commit
143cfacf55

+ 3 - 1
src/sentry/snuba/profile_functions_metrics.py

@@ -13,6 +13,7 @@ from sentry.search.events.types import EventsResponse, ParamsType, QueryBuilderC
 from sentry.snuba import discover
 from sentry.snuba.dataset import Dataset
 from sentry.snuba.metrics.extraction import MetricSpecType
+from sentry.snuba.query_sources import QuerySource
 from sentry.utils.snuba import SnubaTSResult
 
 logger = logging.getLogger(__name__)
@@ -89,6 +90,7 @@ def timeseries_query(
     on_demand_metrics_enabled: bool = False,
     on_demand_metrics_type: MetricSpecType | None = None,
     groupby: Column | None = None,
+    query_source: QuerySource | None = None,
 ) -> SnubaTSResult:
     """
     High-level API for doing arbitrary user timeseries queries against events.
@@ -112,7 +114,7 @@ def timeseries_query(
             use_metrics_layer=use_metrics_layer,
         ),
     )
-    result = metrics_query.run_query(referrer)
+    result = metrics_query.run_query(referrer, query_source=query_source)
 
     result = metrics_query.process_results(result)
     result["data"] = (

+ 1 - 1
tests/snuba/api/endpoints/test_organization_events_profile_functions_metrics.py

@@ -11,7 +11,7 @@ pytestmark = pytest.mark.sentry_metrics
 FUNCTION_DURATION_MRI = "d:profiles/function.duration@millisecond"
 
 
-class OrganizationEventsMetricsEnhancedPerformanceEndpointTest(MetricsEnhancedPerformanceTestCase):
+class OrganizationEventsProfileFunctionsMetricsEndpointTest(MetricsEnhancedPerformanceTestCase):
     viewname = "sentry-api-0-organization-events"
 
     # Poor intentionally omitted for test_measurement_rating_that_does_not_exist

+ 47 - 0
tests/snuba/api/endpoints/test_organization_events_stats_profile_functions_metrics.py

@@ -0,0 +1,47 @@
+import pytest
+from django.urls import reverse
+
+from sentry.testutils.cases import MetricsEnhancedPerformanceTestCase
+from sentry.testutils.helpers.datetime import before_now
+
+pytestmark = pytest.mark.sentry_metrics
+
+
+class OrganizationEventsStatsProfileFunctionsMetricsEndpointTest(
+    MetricsEnhancedPerformanceTestCase
+):
+    viewname = "sentry-api-0-organization-events-stats"
+
+    def setUp(self):
+        super().setUp()
+        self.three_days_ago = before_now(days=3)
+        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(
+            self.viewname,
+            kwargs={"organization_id_or_slug": self.organization.slug},
+        )
+        with self.feature(features):
+            return self.client.get(url, query, format="json")
+
+    def test_basic(self):
+        self.store_profile_functions_metric(
+            1,
+            timestamp=self.three_days_ago,
+        )
+
+        query = {
+            "dataset": "profileFunctionsMetrics",
+            "statsPeriod": "7d",
+            "yAxis": ["count()", "p95(function.duration)"],
+            "interval": "1d",
+            "excludeOther": 1,
+        }
+
+        response = self.do_request(query)
+        assert response.status_code == 200, response.content