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

ref(discover): map project to project.id in discover (#69703)

The frontend field renderer expects the field to be called `project`,
https://github.com/getsentry/sentry/blob/5eed07ecb584cf297ceacd5697bc6a2469908343/static/app/utils/discover/fieldRenderers.tsx#L507

but this isn't a span_metrics field so currently we query for
`project.id`, but this results in us duplicating table cells like here

https://github.com/getsentry/sentry/blob/91712ae955a0dd1c16f16f08c516389570b033d7/static/app/views/performance/http/projectIdCell.tsx#L9
instead of relying on the existing field renderers.

We can avoid this entirely by remapping `project` => `project.slug`

@wmak any side effects from this that you can think of?

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Dominik Buszowiecki 10 месяцев назад
Родитель
Сommit
5972bb96b7

+ 6 - 0
src/sentry/search/events/datasets/spans_metrics.py

@@ -43,6 +43,12 @@ class SpansMetricsDatasetConfig(DatasetConfig):
             constants.DEVICE_CLASS_ALIAS: lambda alias: field_aliases.resolve_device_class(
                 self.builder, alias
             ),
+            constants.PROJECT_ALIAS: lambda alias: field_aliases.resolve_project_slug_alias(
+                self.builder, alias
+            ),
+            constants.PROJECT_NAME_ALIAS: lambda alias: field_aliases.resolve_project_slug_alias(
+                self.builder, alias
+            ),
         }
 
     def resolve_metric(self, value: str) -> int:

+ 33 - 0
tests/snuba/api/endpoints/test_organization_events_span_metrics.py

@@ -1479,6 +1479,39 @@ class OrganizationEventsMetricsEnhancedPerformanceEndpointTest(MetricsEnhancedPe
             {"count_op(queue.submit.celery)": 1, "count_op(queue.task.celery)": 1},
         ]
 
+    def test_project_mapping(self):
+        self.store_span_metric(
+            1,
+            internal_metric=constants.SELF_TIME_LIGHT,
+            timestamp=self.six_min_ago,
+            tags={},
+        )
+
+        # More events occur after the timestamp
+        for _ in range(3):
+            self.store_span_metric(
+                3,
+                internal_metric=constants.SELF_TIME_LIGHT,
+                timestamp=self.min_ago,
+                tags={},
+            )
+
+        response = self.do_request(
+            {
+                "field": ["project", "project.name", "count()"],
+                "query": "",
+                "project": self.project.id,
+                "dataset": "spansMetrics",
+                "statsPeriod": "1h",
+            }
+        )
+
+        assert response.status_code == 200, response.content
+        data = response.data["data"]
+
+        assert data[0]["project"] == self.project.slug
+        assert data[0]["project.name"] == self.project.slug
+
     def test_slow_frames_gauge_metric(self):
         self.store_span_metric(
             {