Repository: getsentry/sentry

Issue:
Ensure extraction vs displaying are separately controlled
We want to only enable metrics extraction without the UI showing it.


Discussion:
If the flag [organizations:on-demand-metrics-extraction](https://flagr.getsentry.net/#/flags/410) and alerts are created that require on-demand extraction it will work (only some business and enterprise AM2 plans):
https://github.com/getsentry/sentry/blob/c6797f05fcf35aa96608f7d20916e06561481e30/tests/sentry/relay/config/test_metric_extraction.py#L84-L151

if the flag ["organizations:on-demand-metrics-extraction-experimental"](https://flagr.getsentry.net/#/flags/437) is enabled (some internal organizations and some users) then we start extracting when widgets are created or updated (example test):
https://github.com/getsentry/sentry/blob/c6797f05fcf35aa96608f7d20916e06561481e30/tests/sentry/relay/config/test_metric_extraction.py#L163-L177

Resolving patch:
diff --git a/src/sentry/conf/server.py b/src/sentry/conf/server.py
--- a/src/sentry/conf/server.py
+++ b/src/sentry/conf/server.py
@@ -1507,6 +1507,8 @@ def custom_parameter_sort(parameter: dict) -> tuple[str, int]:
     "organizations:more-slow-alerts": False,
     # Extract on demand metrics
     "organizations:on-demand-metrics-extraction": False,
+    # Extract on demand metrics (widget extraction)
+    "organizations:on-demand-metrics-extraction-widgets": False,
     # Extract on demand metrics (experimental features)
     "organizations:on-demand-metrics-extraction-experimental": False,
     # Display on demand metrics related UI elements
diff --git a/src/sentry/features/__init__.py b/src/sentry/features/__init__.py
--- a/src/sentry/features/__init__.py
+++ b/src/sentry/features/__init__.py
@@ -112,6 +112,7 @@
 default_manager.add("organizations:metrics-extraction", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:more-slow-alerts", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:on-demand-metrics-extraction", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
+default_manager.add("organizations:on-demand-metrics-extraction-widgets", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:on-demand-metrics-extraction-experimental", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:on-demand-metrics-ui", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:minute-resolution-sessions", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
diff --git a/src/sentry/relay/config/metric_extraction.py b/src/sentry/relay/config/metric_extraction.py
--- a/src/sentry/relay/config/metric_extraction.py
+++ b/src/sentry/relay/config/metric_extraction.py
@@ -75,6 +75,7 @@ def get_metric_extraction_config(project: Project) -> Optional[MetricExtractionC
 def on_demand_metrics_feature_flags(organization: Organization) -> Set[str]:
     feature_names = [
         "organizations:on-demand-metrics-extraction",
+        "organizations:on-demand-metrics-extraction-widgets",  # Controls extraction for widgets
         "organizations:on-demand-metrics-extraction-experimental",
         "organizations:on-demand-metrics-prefill",
     ]
@@ -150,7 +151,7 @@ def _get_widget_metric_specs(
 ) -> List[HashedMetricSpec]:
     if not (
         "organizations:on-demand-metrics-extraction" in enabled_features
-        and "organizations:on-demand-metrics-extraction-experimental" in enabled_features
+        and "organizations:on-demand-metrics-extraction-widgets" in enabled_features
     ):
         return []
 


Test patch:
diff --git a/tests/sentry/relay/config/test_metric_extraction.py b/tests/sentry/relay/config/test_metric_extraction.py
--- a/tests/sentry/relay/config/test_metric_extraction.py
+++ b/tests/sentry/relay/config/test_metric_extraction.py
@@ -21,7 +21,7 @@
 from sentry.testutils.pytest.fixtures import django_db_all
 
 ON_DEMAND_METRICS = "organizations:on-demand-metrics-extraction"
-ON_DEMAND_METRICS_WIDGETS = "organizations:on-demand-metrics-extraction-experimental"
+ON_DEMAND_METRICS_WIDGETS = "organizations:on-demand-metrics-extraction-widgets"
 ON_DEMAND_METRICS_PREFILL = "organizations:on-demand-metrics-prefill"