test_performance_summary.py 8.1 KB

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