Skip to content

Commit

Permalink
Revert "feat(metrics-extraction): Allow cut over to stateful extracti…
Browse files Browse the repository at this point in the history
…on (#61838)"

This reverts commit 477f506.

Co-authored-by: IanWoodard <17186604+IanWoodard@users.noreply.github.com>
  • Loading branch information
getsentry-bot and IanWoodard committed Dec 15, 2023
1 parent b3bf93d commit 17b7a79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 52 deletions.
6 changes: 0 additions & 6 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -1797,12 +1797,6 @@
default=100,
flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
)
# Use database backed stateful extraction state
register(
"on_demand_metrics.widgets.use_stateful_extraction",
default=False,
flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
)

# Relocation
register(
Expand Down
58 changes: 13 additions & 45 deletions src/sentry/relay/config/metric_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,17 @@ def _get_widget_metric_specs(
widget_queries = DashboardWidgetQuery.objects.filter(
widget__dashboard__organization=project.organization,
widget__widget_type=DashboardWidgetTypes.DISCOVER,
).prefetch_related("dashboardwidgetqueryondemand_set")
)

metrics.incr(
"on_demand_metrics.widgets_to_process", amount=len(widget_queries), sample_rate=1.0
)

specs: List[HashedMetricSpec] = []
specs = []
with metrics.timer("on_demand_metrics.widget_spec_convert"):
for widget in widget_queries:
widget_specs = convert_widget_query_to_metric(project, widget, prefilling)
specs.extend(widget_specs)

can_widget_use_stateful_extraction = _can_widget_use_stateful_extraction(
widget, widget_specs
)
if options.get("on_demand_metrics.widgets.use_stateful_extraction"):
if not can_widget_use_stateful_extraction:
return []

# TODO: Remove this cardinality check after above option is enabled permanently.
if widget_specs and not _is_widget_query_low_cardinality(widget, project):
# High cardinality widgets don't have metrics specs created
return []
for result in convert_widget_query_to_metric(project, widget, prefilling, True):
specs.append(result)

max_widget_specs = options.get("on_demand.max_widget_specs") or _MAX_ON_DEMAND_WIDGETS
if len(specs) > max_widget_specs:
Expand Down Expand Up @@ -287,7 +275,7 @@ def _convert_snuba_query_to_metric(


def convert_widget_query_to_metric(
project: Project, widget_query: DashboardWidgetQuery, prefilling: bool
project: Project, widget_query: DashboardWidgetQuery, prefilling: bool, check_cardinality: bool
) -> Sequence[HashedMetricSpec]:
"""
Converts a passed metrics widget query to one or more MetricSpecs.
Expand Down Expand Up @@ -330,35 +318,15 @@ def convert_widget_query_to_metric(
)
metrics_specs.append(result)

return metrics_specs


def _can_widget_use_stateful_extraction(
widget_query: DashboardWidgetQuery, metrics_specs: Sequence[HashedMetricSpec]
):
spec_hashes = [hashed_spec[0] for hashed_spec in metrics_specs]
on_demand_entries = widget_query.dashboardwidgetqueryondemand_set.all()

if len(on_demand_entries) != 1:
# There should only be one on demand entry
sentry_sdk.capture_message(
f"Wrong number of relations ({len(on_demand_entries)}) for widget_query: {widget_query.id}"
)
metrics.incr("on_demand_metrics.on_demand_spec.failed_on_demand_relations", sample_rate=1.0)
return False

on_demand_entry = on_demand_entries[0]
on_demand_hashes = on_demand_entry.spec_hashes

if set(spec_hashes) != set(on_demand_hashes):
# Spec hashes should match. TODO:This can be removed after the existing cardinality check in this task is removed.
sentry_sdk.capture_message(
f"Hashes don't match ({spec_hashes}) ({on_demand_hashes}) for widget_query: {widget_query.id}"
)
metrics.incr("on_demand_metrics.on_demand_spec.failed_on_demand_hashes", sample_rate=1.0)
return False
if (
metrics_specs
and check_cardinality
and not _is_widget_query_low_cardinality(widget_query, project)
):
# High cardinality widgets don't have metrics specs created
return []

return True
return metrics_specs


def _get_widget_cardinality_query_ttl():
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/tasks/on_demand_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _get_widget_on_demand_specs(
if not project_for_query:
return []

widget_specs = convert_widget_query_to_metric(project_for_query, widget_query, True)
widget_specs = convert_widget_query_to_metric(project_for_query, widget_query, True, False)

return widget_specs

Expand Down

0 comments on commit 17b7a79

Please sign in to comment.