test_performance_span_summary.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from datetime import timedelta, timezone
  2. from unittest.mock import patch
  3. from urllib.parse import urlencode
  4. import pytest
  5. from fixtures.page_objects.base import BasePage
  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 = {
  11. "organizations:performance-span-histogram-view": True,
  12. "organizations:performance-view": True,
  13. }
  14. @no_silo_test(stable=True)
  15. class PerformanceSpanSummaryTest(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/spans/{}/?{}".format(
  26. self.org.slug,
  27. "django.middleware:" + "cd" * 8,
  28. urlencode({"project": self.project.id, "transaction": "root transaction"}),
  29. )
  30. self.page = BasePage(self.browser)
  31. self.min_ago = before_now(minutes=1).replace(microsecond=0)
  32. def create_event(self, **kwargs):
  33. if "span_id" not in kwargs:
  34. kwargs["span_id"] = "a" * 16
  35. if "start_timestamp" not in kwargs:
  36. kwargs["start_timestamp"] = self.min_ago
  37. if "timestamp" not in kwargs:
  38. kwargs["timestamp"] = self.min_ago + timedelta(seconds=8)
  39. if "trace_context" not in kwargs:
  40. kwargs["trace_context"] = {
  41. "op": "http.server",
  42. "hash": "ab" * 8,
  43. "exclusive_time": 4.0,
  44. }
  45. if "spans" not in kwargs:
  46. kwargs["spans"] = [
  47. {
  48. "same_process_as_parent": True,
  49. "parent_span_id": "a" * 16,
  50. "span_id": x * 16,
  51. "start_timestamp": iso_format(self.min_ago + timedelta(seconds=1)),
  52. "timestamp": iso_format(self.min_ago + timedelta(seconds=4)),
  53. "op": "django.middleware",
  54. "description": "middleware span",
  55. "hash": "cd" * 8,
  56. "exclusive_time": 3.0,
  57. }
  58. for x in ["b", "c"]
  59. ] + [
  60. {
  61. "same_process_as_parent": True,
  62. "parent_span_id": "a" * 16,
  63. "span_id": x * 16,
  64. "start_timestamp": iso_format(self.min_ago + timedelta(seconds=4)),
  65. "timestamp": iso_format(self.min_ago + timedelta(seconds=5)),
  66. "op": "django.middleware",
  67. "description": "middleware span",
  68. "hash": "cd" * 8,
  69. "exclusive_time": 1.0,
  70. }
  71. for x in ["d", "e", "f"]
  72. ]
  73. data = load_data("transaction", **kwargs)
  74. data["transaction"] = "root transaction"
  75. data["event_id"] = "c" * 32
  76. data["contexts"]["trace"]["trace_id"] = "a" * 32
  77. return self.store_event(data, project_id=self.project.id)
  78. @pytest.mark.skip(reason="Has been flaky lately.")
  79. @patch("django.utils.timezone.now")
  80. def test_with_data(self, mock_now):
  81. mock_now.return_value = before_now().replace(tzinfo=timezone.utc)
  82. self.create_event()
  83. with self.feature(FEATURES):
  84. self.browser.get(self.path)
  85. self.page.wait_until_loaded()
  86. # Wait again for loaders inside the table
  87. self.page.wait_until_loaded()