Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/sentry/discover/compare_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
)
from sentry.models.dashboard import Dashboard
from sentry.models.dashboard_widget import DashboardWidget, DashboardWidgetQuery
from sentry.models.environment import Environment
from sentry.models.organization import Organization
from sentry.models.project import Project
from sentry.organizations.absolute_url import generate_organization_url
from sentry.search.eap.types import EAPResponse, SearchResolverConfig
from sentry.search.events.filter import to_list
from sentry.search.events.types import EventsResponse, SnubaParams
from sentry.snuba import metrics_enhanced_performance, spans_rpc

Expand Down Expand Up @@ -143,7 +145,17 @@ def compare_tables_for_dashboard_widget_queries(
equations = [equation for equation in _get_equation_list(widget_query.fields or []) if equation]
query = widget_query.conditions

environments = dashboard.filters.get("environment", []) if dashboard.filters is not None else []
environment_names: str | list[str] = (
dashboard.filters.get("environment", []) if dashboard.filters else []
)
if environment_names:
environments = list(
Environment.objects.filter(
name__in=to_list(environment_names), organization_id=organization.id
)
)
else:
environments = []

snuba_params = SnubaParams(
environments=environments,
Expand Down
34 changes: 34 additions & 0 deletions tests/sentry/discover/test_compare_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ def setUp(self):
self.dashboard_2 = self.create_dashboard(
organization=self.organization, filters={"environment": []}
)
self.environment = self.create_environment(
organization=self.organization, project=self.project
)
self.dashboard_3 = self.create_dashboard(
organization=self.organization, filters={"environment": [self.environment.name]}
)
self.dashboard.projects.set([self.project])
self.dashboard_2.projects.set([])
self.dashboard_3.projects.set([self.project])

self.successful_widget_2 = DashboardWidget.objects.create(
dashboard=self.dashboard_2,
Expand Down Expand Up @@ -147,6 +154,25 @@ def setUp(self):
fields=["count()", "http.status_code"],
)

self.widget_with_environment_filter = DashboardWidget.objects.create(
dashboard=self.dashboard_3,
title="Test Erroring Widget",
order=6,
display_type=DashboardWidgetDisplayTypes.TABLE,
widget_type=DashboardWidgetTypes.TRANSACTION_LIKE,
)

self.widget_with_environment_filter_query = DashboardWidgetQuery.objects.create(
widget=self.widget_with_environment_filter,
name="Test Widget Query With Environment Filter",
order=6,
fields=["transaction", "count()"],
conditions="!event.type:error",
orderby="-count()",
aggregates=["count()"],
columns=["transaction"],
)

self.triple_write_segment(
project=self.project,
trace_id=uuid4().hex,
Expand Down Expand Up @@ -328,3 +354,11 @@ def test_compare_widget_query_with_no_project(self):
)
assert comparison_result["passed"] is True
assert comparison_result["mismatches"] == []

def test_compare_widget_query_that_errors_out(self):
comparison_result = compare_tables_for_dashboard_widget_queries(
self.widget_with_environment_filter_query
)
assert comparison_result["passed"] is False
# assert that both queries don't fail due to the environment filter
assert comparison_result["reason"] != CompareTableResult.BOTH_FAILED
Loading