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
18 changes: 7 additions & 11 deletions src/sentry/dashboards/endpoints/organization_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@

import sentry_sdk
from django.db import IntegrityError, router, transaction
from django.db.models import (
Case,
Exists,
F,
IntegerField,
OrderBy,
OuterRef,
Subquery,
Value,
When,
)
from django.db.models import Case, Exists, F, IntegerField, OrderBy, OuterRef, Subquery, Value, When
from drf_spectacular.utils import extend_schema
from rest_framework import status
from rest_framework.request import Request
Expand Down Expand Up @@ -104,6 +94,7 @@
title: Required[str]
hidden: bool
pre_favorited: bool
required_feature_flags: list[str]


# Prebuilt dashboards store minimal fields in the database. The actual dashboard and widget settings are
Expand Down Expand Up @@ -240,6 +231,7 @@
{
"prebuilt_id": PrebuiltDashboardId.NODE_RUNTIME_METRICS,
"title": "Node.js Runtime Metrics",
"required_feature_flags": ["organizations:tracemetrics-enabled"],
},
]

Expand All @@ -260,10 +252,14 @@
if should_sync_all_registered_prebuilt_dashboards:
return all_prebuilt_dashboards
return [
dashboard
for dashboard in all_prebuilt_dashboards
Comment thread
narsaynorath marked this conversation as resolved.
if dashboard["prebuilt_id"] in enabled_prebuilt_dashboard_ids
and all(
features.has(feature, organization)
for feature in dashboard.get("required_feature_flags", [])
)
]

Check warning on line 262 in src/sentry/dashboards/endpoints/organization_dashboards.py

View check run for this annotation

@sentry/warden / warden: sentry-backend-bugs

required_feature_flags skipped when sync-all is enabled

When `organizations:dashboards-sync-all-registered-prebuilt-dashboards` is on, `get_enabled_prebuilt_dashboards` returns every prebuilt dashboard and never applies `required_feature_flags`, so Node.js Runtime Metrics still syncs for orgs without `tracemetrics-enabled`. Apply the feature-flag filter on both return paths.


def sync_prebuilt_dashboards(organization: Organization) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,13 @@ def test_hidden_prebuilt_dashboards_included_with_show_hidden_filter(self) -> No
assert PrebuiltDashboardId.BACKEND_QUERIES_SUMMARY in prebuilt_ids_in_response

def test_node_runtime_metrics_prebuilt_dashboard_sync(self) -> None:
"""The Node.js Runtime Metrics prebuilt dashboard syncs when enabled via options."""
with self.feature("organizations:dashboards-prebuilt-insights-dashboards"):
"""The Node.js Runtime Metrics dashboard syncs when metrics and its option are enabled."""
with self.feature(
[
"organizations:dashboards-prebuilt-insights-dashboards",
"organizations:tracemetrics-enabled",
]
):
with override_options(
{"dashboards.prebuilt-dashboard-ids": [PrebuiltDashboardId.NODE_RUNTIME_METRICS]}
):
Expand All @@ -2437,6 +2442,23 @@ def test_node_runtime_metrics_prebuilt_dashboard_sync(self) -> None:
]
assert len(prebuilt_in_response) == 1

def test_node_runtime_metrics_prebuilt_dashboard_not_synced_without_metrics(self) -> None:
with self.feature("organizations:dashboards-prebuilt-insights-dashboards"):
with override_options(
{"dashboards.prebuilt-dashboard-ids": [PrebuiltDashboardId.NODE_RUNTIME_METRICS]}
):
response = self.do_request("get", self.url)
assert response.status_code == 200

assert not Dashboard.objects.filter(
organization=self.organization,
prebuilt_id=PrebuiltDashboardId.NODE_RUNTIME_METRICS,
).exists()
assert all(
dashboard.get("prebuiltId") != PrebuiltDashboardId.NODE_RUNTIME_METRICS
for dashboard in response.data
)

def test_endpoint_creates_pre_favorited_prebuilt_dashboards(self) -> None:
assert (
DashboardFavoriteUser.objects.filter(
Expand Down
Loading