test_performance_summary.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. from datetime import timezone
  2. from unittest.mock import patch
  3. from urllib.parse import urlencode
  4. from fixtures.page_objects.transaction_summary import TransactionSummaryPage
  5. from sentry.models import AssistantActivity
  6. from sentry.testutils.cases import AcceptanceTestCase, SnubaTestCase
  7. from sentry.testutils.helpers.datetime import before_now, iso_format
  8. from sentry.testutils.silo import no_silo_test
  9. from sentry.utils.samples import load_data
  10. FEATURES = {"organizations:performance-view": True}
  11. def make_event(event_data):
  12. event_data["event_id"] = "c" * 32
  13. event_data["contexts"]["trace"]["trace_id"] = "a" * 32
  14. return event_data
  15. @no_silo_test(stable=True)
  16. class PerformanceSummaryTest(AcceptanceTestCase, SnubaTestCase):
  17. def setUp(self):
  18. super().setUp()
  19. self.org = self.create_organization(owner=self.user, name="Rowdy Tiger")
  20. self.team = self.create_team(
  21. organization=self.org, name="Mariachi Band", members=[self.user]
  22. )
  23. self.project = self.create_project(organization=self.org, teams=[self.team], name="Bengal")
  24. self.group = self.create_group(project=self.project)
  25. self.login_as(self.user)
  26. self.path = "/organizations/{}/performance/summary/?{}".format(
  27. self.org.slug,
  28. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  29. )
  30. AssistantActivity.objects.create(
  31. user=self.user, guide_id=20, viewed_ts=before_now(minutes=1)
  32. )
  33. self.page = TransactionSummaryPage(self.browser)
  34. @patch("django.utils.timezone.now")
  35. def test_with_data(self, mock_now):
  36. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  37. # Create a transaction
  38. event = make_event(load_data("transaction", timestamp=before_now(minutes=3)))
  39. self.store_event(data=event, project_id=self.project.id)
  40. self.store_event(
  41. data={
  42. "transaction": "/country_by_code/",
  43. "message": "This is bad",
  44. "event_id": "b" * 32,
  45. "timestamp": iso_format(before_now(minutes=1)),
  46. },
  47. project_id=self.project.id,
  48. )
  49. with self.feature(FEATURES):
  50. self.browser.get(self.path)
  51. self.page.wait_until_loaded()
  52. # We have to wait for this again because there are loaders inside of the table
  53. self.page.wait_until_loaded()
  54. self.browser.snapshot("performance summary - with data")
  55. @patch("django.utils.timezone.now")
  56. def test_view_details_from_summary(self, mock_now):
  57. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  58. event = make_event(
  59. load_data(
  60. "transaction", timestamp=before_now(minutes=3), trace="a" * 32, span_id="ab" * 8
  61. )
  62. )
  63. self.store_event(data=event, project_id=self.project.id)
  64. with self.feature(FEATURES):
  65. self.browser.get(self.path)
  66. self.page.wait_until_loaded()
  67. # View the first event details.
  68. self.browser.element('[data-test-id="view-id"]').click()
  69. self.page.wait_until_loaded()
  70. self.browser.snapshot("performance event details")
  71. @patch("django.utils.timezone.now")
  72. def test_tags_page(self, mock_now):
  73. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  74. tags_path = "/organizations/{}/performance/summary/tags/?{}".format(
  75. self.org.slug,
  76. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  77. )
  78. # Create a transaction
  79. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  80. event = make_event(event_data)
  81. self.store_event(data=event, project_id=self.project.id)
  82. with self.feature(FEATURES):
  83. self.browser.get(tags_path)
  84. self.page.wait_until_loaded()
  85. self.browser.snapshot("transaction summary tags page")
  86. @patch("django.utils.timezone.now")
  87. def test_transaction_vitals(self, mock_now):
  88. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  89. vitals_path = "/organizations/{}/performance/summary/vitals/?{}".format(
  90. self.org.slug,
  91. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  92. )
  93. # Create a transaction
  94. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  95. # only frontend pageload transactions can be shown on the vitals tab
  96. event_data["contexts"]["trace"]["op"] = "pageload"
  97. event_data["measurements"]["fp"]["value"] = 5000
  98. event = make_event(event_data)
  99. self.store_event(data=event, project_id=self.project.id)
  100. with self.feature(FEATURES):
  101. self.browser.get(vitals_path)
  102. self.page.wait_until_loaded()
  103. self.browser.snapshot("real user monitoring")
  104. @patch("django.utils.timezone.now")
  105. def test_transaction_vitals_filtering(self, mock_now):
  106. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  107. vitals_path = "/organizations/{}/performance/summary/vitals/?{}".format(
  108. self.org.slug,
  109. urlencode(
  110. {
  111. "transaction": "/country_by_code/",
  112. "project": self.project.id,
  113. "dataFilter": "exclude_outliers",
  114. }
  115. ),
  116. )
  117. # Create transactions
  118. for seconds in range(3):
  119. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  120. event_data["contexts"]["trace"]["op"] = "pageload"
  121. event_data["contexts"]["trace"]["id"] = ("c" * 31) + hex(seconds)[2:]
  122. event_data["event_id"] = ("c" * 31) + hex(seconds)[2:]
  123. event_data["measurements"]["fp"]["value"] = seconds * 10
  124. event_data["measurements"]["fcp"]["value"] = seconds * 10
  125. event_data["measurements"]["lcp"]["value"] = seconds * 10
  126. event_data["measurements"]["fid"]["value"] = seconds * 10
  127. event_data["measurements"]["cls"]["value"] = seconds / 10.0
  128. self.store_event(data=event_data, project_id=self.project.id)
  129. # add anchor point
  130. event_data = load_data("transaction", timestamp=before_now(minutes=2))
  131. event_data["contexts"]["trace"]["op"] = "pageload"
  132. event_data["contexts"]["trace"]["id"] = "a" * 32
  133. event_data["event_id"] = "a" * 32
  134. event_data["measurements"]["fp"]["value"] = 3000
  135. event_data["measurements"]["fcp"]["value"] = 3000
  136. event_data["measurements"]["lcp"]["value"] = 3000
  137. event_data["measurements"]["fid"]["value"] = 3000
  138. event_data["measurements"]["cls"]["value"] = 0.3
  139. self.store_event(data=event_data, project_id=self.project.id)
  140. # add outlier
  141. event_data = load_data("transaction", timestamp=before_now(minutes=2))
  142. event_data["contexts"]["trace"]["op"] = "pageload"
  143. event_data["contexts"]["trace"]["id"] = "b" * 32
  144. event_data["event_id"] = "b" * 32
  145. event_data["measurements"]["fp"]["value"] = 3000000000
  146. event_data["measurements"]["fcp"]["value"] = 3000000000
  147. event_data["measurements"]["lcp"]["value"] = 3000000000
  148. event_data["measurements"]["fid"]["value"] = 3000000000
  149. event_data["measurements"]["cls"]["value"] = 3000000000
  150. self.store_event(data=event_data, project_id=self.project.id)
  151. with self.feature(FEATURES):
  152. self.browser.get(vitals_path)
  153. self.page.wait_until_loaded()
  154. self.browser.snapshot("real user monitoring - exclude outliers")
  155. self.browser.element(xpath="//button//span[contains(text(), 'Exclude')]").click()
  156. self.browser.element(xpath="//p[contains(text(), 'Include')]").click()
  157. self.page.wait_until_loaded()
  158. self.browser.snapshot("real user monitoring - view all data")
  159. @patch("django.utils.timezone.now")
  160. def test_transaction_threshold_modal(self, mock_now):
  161. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  162. # Create a transaction
  163. event = make_event(load_data("transaction", timestamp=before_now(minutes=3)))
  164. self.store_event(data=event, project_id=self.project.id)
  165. self.store_event(
  166. data={
  167. "transaction": "/country_by_code/",
  168. "message": "This is bad",
  169. "event_id": "b" * 32,
  170. "timestamp": iso_format(before_now(minutes=3)),
  171. },
  172. project_id=self.project.id,
  173. )
  174. with self.feature(FEATURES):
  175. self.browser.get(self.path)
  176. self.page.wait_until_loaded()
  177. self.browser.click('[data-test-id="set-transaction-threshold"]')
  178. self.browser.snapshot("transaction threshold modal")