Browse Source

feat(dashboard) Add more queries to the default dashboard (#22690)

Add a few more widgets and queries to the default dashboard that let us
replicate the existing default dashboard.
Mark Story 4 years ago
parent
commit
943ca9df5b

+ 3 - 1
src/sentry/api/endpoints/organization_dashboards.py

@@ -39,7 +39,9 @@ class OrganizationDashboardsEndpoint(OrganizationEndpoint):
             serialized = []
             for item in results:
                 if isinstance(item, dict):
-                    serialized.append(item)
+                    cloned = item.copy()
+                    del cloned["widgets"]
+                    serialized.append(cloned)
                 else:
                     serialized.append(serialize(item, request.user, serializer=list_serializer))
             return serialized

+ 37 - 1
src/sentry/models/dashboard.py

@@ -78,6 +78,8 @@ PREBUILT_DASHBOARDS = {
         {
             "id": "default-overview",
             "title": "Dashboard",
+            "dateCreated": "",
+            "createdBy": "",
             "widgets": [
                 {
                     "title": "Events",
@@ -90,7 +92,41 @@ PREBUILT_DASHBOARDS = {
                             "fields": ["count()"],
                         }
                     ],
-                }
+                },
+                {
+                    "title": "Affected Users",
+                    "displayType": "line",
+                    "interval": "5m",
+                    "queries": [
+                        {
+                            "name": "Known Users",
+                            "conditions": "has:user.email",
+                            "fields": ["count_unique(user.email)"],
+                        },
+                        {
+                            "name": "Anonymous Users",
+                            "conditions": "!has:user.email",
+                            "fields": ["count()"],
+                        },
+                    ],
+                },
+                {
+                    "title": "Handled vs. Unhandled",
+                    "displayType": "line",
+                    "interval": "5m",
+                    "queries": [
+                        {
+                            "name": "Handled",
+                            "conditions": "error.handled:true",
+                            "fields": ["count()"],
+                        },
+                        {
+                            "name": "Unhandled",
+                            "conditions": "error.handled:false",
+                            "fields": ["count()"],
+                        },
+                    ],
+                },
             ],
         }
     ]

+ 1 - 0
tests/sentry/api/endpoints/test_organization_dashboards.py

@@ -25,6 +25,7 @@ class OrganizationDashboardsTest(OrganizationDashboardWidgetTestCase):
         assert data["id"] == six.text_type(dashboard.id)
         assert data["title"] == dashboard.title
         assert data["createdBy"] == six.text_type(dashboard.created_by.id)
+        assert "widgets" not in data
 
     def test_get(self):
         response = self.client.get(self.url)