Repository: getsentry/sentry

Issue:
Return only MRIs of stored metrics



Discussion:

Resolving patch:
diff --git a/src/sentry/snuba/metrics/datasource.py b/src/sentry/snuba/metrics/datasource.py
--- a/src/sentry/snuba/metrics/datasource.py
+++ b/src/sentry/snuba/metrics/datasource.py
@@ -42,7 +42,6 @@
 from sentry.snuba.metrics.naming_layer.mri import (
     MRI_SCHEMA_REGEX,
     get_available_operations,
-    get_known_mris,
     is_custom_measurement,
     parse_mri,
 )
@@ -150,9 +149,8 @@ def get_metrics_meta(projects: Sequence[Project], use_case_id: UseCaseID) -> Seq
     metas = []
 
     stored_mris = get_stored_mris(projects, use_case_id) if projects else []
-    unique_mris = set(get_known_mris(use_case_id) + stored_mris)
 
-    for mri in sorted(unique_mris):
+    for mri in stored_mris:
         parsed_mri = parse_mri(mri)
 
         # TODO(ogi): check how is this possible
diff --git a/src/sentry/snuba/metrics/naming_layer/mri.py b/src/sentry/snuba/metrics/naming_layer/mri.py
--- a/src/sentry/snuba/metrics/naming_layer/mri.py
+++ b/src/sentry/snuba/metrics/naming_layer/mri.py
@@ -24,7 +24,6 @@
     "MRI_EXPRESSION_REGEX",
     "parse_mri",
     "get_available_operations",
-    "get_known_mris",
 )
 
 import re
@@ -32,7 +31,6 @@
 from enum import Enum
 from typing import List, Optional
 
-from sentry.sentry_metrics.use_case_id_registry import UseCaseID
 from sentry.snuba.metrics.utils import AVAILABLE_GENERIC_OPERATIONS, AVAILABLE_OPERATIONS, OP_REGEX
 
 NAMESPACE_REGEX = r"(transactions|errors|issues|sessions|alerts|custom|spans)"
@@ -208,12 +206,3 @@ def get_available_operations(parsed_mri: ParsedMRI) -> List[str]:
     else:
         entity_key = f"generic_metrics_{entity_name_suffixes[parsed_mri.entity]}"
         return AVAILABLE_GENERIC_OPERATIONS[entity_key]
-
-
-def get_known_mris(use_case_id: UseCaseID) -> List[str]:
-    if use_case_id is UseCaseID.SESSIONS:
-        return [m.value for m in SessionMRI]
-    elif use_case_id is UseCaseID.TRANSACTIONS:
-        return [m.value for m in TransactionMRI]
-    else:
-        return []


Test patch:
diff --git a/tests/sentry/api/endpoints/test_organization_metrics.py b/tests/sentry/api/endpoints/test_organization_metrics.py
--- a/tests/sentry/api/endpoints/test_organization_metrics.py
+++ b/tests/sentry/api/endpoints/test_organization_metrics.py
@@ -11,7 +11,11 @@
 from sentry.snuba.metrics.fields import DERIVED_METRICS, SingularEntityDerivedMetric
 from sentry.snuba.metrics.fields.snql import complement, division_float
 from sentry.snuba.metrics.naming_layer.mri import SessionMRI
-from sentry.testutils.cases import APITestCase, OrganizationMetricMetaIntegrationTestCase
+from sentry.testutils.cases import (
+    APITestCase,
+    MetricsAPIBaseTestCase,
+    OrganizationMetricMetaIntegrationTestCase,
+)
 from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
 from sentry.testutils.skips import requires_snuba
 
@@ -84,6 +88,10 @@ class OrganizationMetricsMetaTest(OrganizationMetricMetaIntegrationTestCase):
 
     endpoint = "sentry-api-0-organization-metrics-index"
 
+    @property
+    def now(self):
+        return MetricsAPIBaseTestCase.MOCK_DATETIME
+
     def setUp(self):
         super().setUp()
         self.proj2 = self.create_project(organization=self.organization)
@@ -93,14 +101,8 @@ def test_metrics_meta_sessions(self):
         response = self.get_success_response(
             self.organization.slug, project=[self.project.id], useCase=["sessions"]
         )
-
+        # TODO(ogi): make proper assertions here
         assert type(response.data) == list
-        assert len(response.data) > 0
-
-        for metric in response.data:
-            assert "name" in metric
-            assert "mri" in metric
-            assert type(metric["operations"]) == list
 
     def test_metrics_meta_transactions(self):
         response = self.get_success_response(
@@ -108,7 +110,6 @@ def test_metrics_meta_transactions(self):
         )
 
         assert type(response.data) == list
-        assert len(response.data) == 46
 
     def test_metrics_meta_invalid_use_case(self):
         response = self.get_error_response(