test_performance_summary.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.assistant 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. @patch("django.utils.timezone.now")
  55. def test_view_details_from_summary(self, mock_now):
  56. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  57. event = make_event(
  58. load_data(
  59. "transaction", timestamp=before_now(minutes=3), trace="a" * 32, span_id="ab" * 8
  60. )
  61. )
  62. self.store_event(data=event, project_id=self.project.id)
  63. with self.feature(FEATURES):
  64. self.browser.get(self.path)
  65. self.page.wait_until_loaded()
  66. # View the first event details.
  67. self.browser.element('[data-test-id="view-id"]').click()
  68. self.page.wait_until_loaded()
  69. @patch("django.utils.timezone.now")
  70. def test_tags_page(self, mock_now):
  71. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  72. tags_path = "/organizations/{}/performance/summary/tags/?{}".format(
  73. self.org.slug,
  74. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  75. )
  76. # Create a transaction
  77. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  78. event = make_event(event_data)
  79. self.store_event(data=event, project_id=self.project.id)
  80. with self.feature(FEATURES):
  81. self.browser.get(tags_path)
  82. self.page.wait_until_loaded()
  83. @patch("django.utils.timezone.now")
  84. def test_transaction_vitals(self, mock_now):
  85. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  86. vitals_path = "/organizations/{}/performance/summary/vitals/?{}".format(
  87. self.org.slug,
  88. urlencode({"transaction": "/country_by_code/", "project": self.project.id}),
  89. )
  90. # Create a transaction
  91. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  92. # only frontend pageload transactions can be shown on the vitals tab
  93. event_data["contexts"]["trace"]["op"] = "pageload"
  94. event_data["measurements"]["fp"]["value"] = 5000
  95. event = make_event(event_data)
  96. self.store_event(data=event, project_id=self.project.id)
  97. with self.feature(FEATURES):
  98. self.browser.get(vitals_path)
  99. self.page.wait_until_loaded()
  100. @patch("django.utils.timezone.now")
  101. def test_transaction_vitals_filtering(self, mock_now):
  102. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  103. vitals_path = "/organizations/{}/performance/summary/vitals/?{}".format(
  104. self.org.slug,
  105. urlencode(
  106. {
  107. "transaction": "/country_by_code/",
  108. "project": self.project.id,
  109. "dataFilter": "exclude_outliers",
  110. }
  111. ),
  112. )
  113. # Create transactions
  114. for seconds in range(3):
  115. event_data = load_data("transaction", timestamp=before_now(minutes=3))
  116. event_data["contexts"]["trace"]["op"] = "pageload"
  117. event_data["contexts"]["trace"]["id"] = ("c" * 31) + hex(seconds)[2:]
  118. event_data["event_id"] = ("c" * 31) + hex(seconds)[2:]
  119. event_data["measurements"]["fp"]["value"] = seconds * 10
  120. event_data["measurements"]["fcp"]["value"] = seconds * 10
  121. event_data["measurements"]["lcp"]["value"] = seconds * 10
  122. event_data["measurements"]["fid"]["value"] = seconds * 10
  123. event_data["measurements"]["cls"]["value"] = seconds / 10.0
  124. self.store_event(data=event_data, project_id=self.project.id)
  125. # add anchor point
  126. event_data = load_data("transaction", timestamp=before_now(minutes=2))
  127. event_data["contexts"]["trace"]["op"] = "pageload"
  128. event_data["contexts"]["trace"]["id"] = "a" * 32
  129. event_data["event_id"] = "a" * 32
  130. event_data["measurements"]["fp"]["value"] = 3000
  131. event_data["measurements"]["fcp"]["value"] = 3000
  132. event_data["measurements"]["lcp"]["value"] = 3000
  133. event_data["measurements"]["fid"]["value"] = 3000
  134. event_data["measurements"]["cls"]["value"] = 0.3
  135. self.store_event(data=event_data, project_id=self.project.id)
  136. # add outlier
  137. event_data = load_data("transaction", timestamp=before_now(minutes=2))
  138. event_data["contexts"]["trace"]["op"] = "pageload"
  139. event_data["contexts"]["trace"]["id"] = "b" * 32
  140. event_data["event_id"] = "b" * 32
  141. event_data["measurements"]["fp"]["value"] = 3000000000
  142. event_data["measurements"]["fcp"]["value"] = 3000000000
  143. event_data["measurements"]["lcp"]["value"] = 3000000000
  144. event_data["measurements"]["fid"]["value"] = 3000000000
  145. event_data["measurements"]["cls"]["value"] = 3000000000
  146. self.store_event(data=event_data, project_id=self.project.id)
  147. with self.feature(FEATURES):
  148. self.browser.get(vitals_path)
  149. self.page.wait_until_loaded()
  150. self.browser.element(xpath="//button//span[contains(text(), 'Exclude')]").click()
  151. self.browser.element(xpath="//p[contains(text(), 'Include')]").click()
  152. self.page.wait_until_loaded()
  153. @patch("django.utils.timezone.now")
  154. def test_transaction_threshold_modal(self, mock_now):
  155. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  156. # Create a transaction
  157. event = make_event(load_data("transaction", timestamp=before_now(minutes=3)))
  158. self.store_event(data=event, project_id=self.project.id)
  159. self.store_event(
  160. data={
  161. "transaction": "/country_by_code/",
  162. "message": "This is bad",
  163. "event_id": "b" * 32,
  164. "timestamp": iso_format(before_now(minutes=3)),
  165. },
  166. project_id=self.project.id,
  167. )
  168. with self.feature(FEATURES):
  169. self.browser.get(self.path)
  170. self.page.wait_until_loaded()
  171. self.browser.click('[data-test-id="set-transaction-threshold"]')