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
29 changes: 24 additions & 5 deletions src/sentry/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db.models.query import QuerySet
from django.utils import timezone

from sentry import features
from sentry.backup.scopes import RelocationScope
from sentry.constants import ALL_ACCESS_PROJECT_ID
from sentry.db.models import FlexibleForeignKey, Model, region_silo_model, sane_repr
Expand Down Expand Up @@ -409,7 +410,17 @@ class Meta:

def get_prebuilt_dashboards(organization, user) -> list[dict[str, Any]]:
error_events_type = DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.ERROR_EVENTS)
transaction_type = DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.TRANSACTION_LIKE)
is_transactions_deprecation_enabled = features.has(
"organizations:discover-saved-queries-deprecation",
organization=organization,
actor=user,
)
transaction_type = (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to update the query condition for the transaction widget to include is_segment:True or something? because otherwise it's aggregating spans and the counts would be for spans and not necessarily transactions

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh true good point! i'll update that

DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.SPANS)
if is_transactions_deprecation_enabled
else DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.TRANSACTION_LIKE)
)

return [
{
# This should match the general template in static/app/views/dashboardsV2/data.tsx
Expand Down Expand Up @@ -560,7 +571,9 @@ def get_prebuilt_dashboards(organization, user) -> list[dict[str, Any]]:
"fields": ["count()", "transaction"],
"aggregates": ["count()"],
"columns": ["transaction"],
"conditions": "",
"conditions": "is_transaction:true"
if is_transactions_deprecation_enabled
else "",
"orderby": "-count()",
},
],
Expand All @@ -576,7 +589,9 @@ def get_prebuilt_dashboards(organization, user) -> list[dict[str, Any]]:
"fields": ["user_misery(300)"],
"aggregates": ["user_misery(300)"],
"columns": [],
"conditions": "",
"conditions": "is_transaction:true"
if is_transactions_deprecation_enabled
else "",
"orderby": "",
},
],
Expand All @@ -592,7 +607,9 @@ def get_prebuilt_dashboards(organization, user) -> list[dict[str, Any]]:
"fields": ["transaction", "count()"],
"aggregates": ["count()"],
"columns": ["transaction"],
"conditions": "",
"conditions": "is_transaction:true"
if is_transactions_deprecation_enabled
else "",
"orderby": "-count()",
},
],
Expand Down Expand Up @@ -624,7 +641,9 @@ def get_prebuilt_dashboards(organization, user) -> list[dict[str, Any]]:
"fields": ["transaction", "user_misery(300)"],
"aggregates": ["user_misery(300)"],
"columns": ["transaction"],
"conditions": "",
"conditions": "is_transaction:true"
if is_transactions_deprecation_enabled
else "",
"orderby": "-user_misery(300)",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def test_get_prebuilt_dashboard(self) -> None:
assert response.status_code == 200
assert response.data["id"] == "default-overview"

def test_get_prebuilt_dashboard_with_transactions_deprecation_feature_flag(self) -> None:
with self.feature("organizations:discover-saved-queries-deprecation"):
response = self.do_request("get", self.url("default-overview"))
assert response.status_code == 200
assert response.data["widgets"][7]["widgetType"] == "spans"

def test_prebuilt_dashboard_with_discover_split_feature_flag(self) -> None:
response = self.do_request("get", self.url("default-overview"))
assert response.status_code == 200, response.data
Expand Down Expand Up @@ -2181,6 +2187,31 @@ def test_update_prebuilt_dashboard(self) -> None:
assert len(queries) == 1
assert DashboardTombstone.objects.filter(slug=slug).exists()

def test_update_prebuilt_dashboard_with_transactions_deprecation_feature_flag(self) -> None:
data = {
"title": "First dashboard",
"widgets": [
{
"title": "New title",
"displayType": "line",
"widgetType": "transaction-like",
"queries": [
{
"name": "transactions",
"fields": ["count()"],
"columns": [],
"aggregates": ["count()"],
"conditions": "event.type:transaction",
},
],
},
],
}
slug = "default-overview"
with self.feature("organizations:discover-saved-queries-deprecation"):
response = self.do_request("put", self.url(slug), data=data)
assert response.status_code == 400, response.data
Comment on lines +2212 to +2213
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, can we confirm if we actually do PUT against the default-overview dashboard? I would have thought that we should trigger a POST with the new dashboard to create something new because.. we can't update this, unless the code detects it and spits out a new dashboard 🤔

It might be a bug in the frontend then if we don't try to post. Which now that I think of feels like it could be the case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, I don't think this test is necessary because we shouldn't ever be trying to update this hardcoded dashboard

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so basically the way it works is when you go to update the default-overview dashboard it will delete the dashboard and create a new custom dashboard BUT that default overview dashboard will create a DashboardTombstone so that's what these PUT tests were testing. For this test in particular I was making sure it didn't accept the PUT with a transactions widget being passed in.


def test_update_unknown_prebuilt(self) -> None:
data = {
"title": "First dashboard",
Expand Down
Loading