test_organization_measurements_meta.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. from datetime import timedelta
  2. import pytest
  3. from django.urls import reverse
  4. from sentry.testutils.cases import MetricsEnhancedPerformanceTestCase
  5. from sentry.testutils.helpers.datetime import before_now
  6. pytestmark = pytest.mark.sentry_metrics
  7. class OrganizationMeasurementsMetaEndpoint(MetricsEnhancedPerformanceTestCase):
  8. endpoint = "sentry-api-0-organization-measurements-meta"
  9. METRIC_STRINGS = [
  10. "d:transactions/measurements.something_custom@millisecond",
  11. ]
  12. features = {"organizations:discover-basic": True}
  13. def setUp(self):
  14. super().setUp()
  15. self.login_as(user=self.user)
  16. self.day_ago = before_now(days=1).replace(hour=10, minute=0, second=0, microsecond=0)
  17. self.DEFAULT_METRIC_TIMESTAMP = self.day_ago
  18. self.url = reverse(
  19. self.endpoint, kwargs={"organization_id_or_slug": self.project.organization.slug}
  20. )
  21. self.features = {"organizations:performance-use-metrics": True}
  22. def test_simple(self):
  23. self.store_transaction_metric(
  24. 1,
  25. metric="measurements.something_custom",
  26. internal_metric="d:transactions/measurements.something_custom@millisecond",
  27. entity="metrics_distributions",
  28. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  29. )
  30. response = self.do_request(
  31. {
  32. "project": self.project.id,
  33. "statsPeriod": "14d",
  34. }
  35. )
  36. assert response.status_code == 200, response.content
  37. assert response.data == {
  38. "measurements.something_custom": {
  39. "functions": [
  40. "apdex",
  41. "avg",
  42. "p50",
  43. "p75",
  44. "p90",
  45. "p95",
  46. "p99",
  47. "p100",
  48. "max",
  49. "min",
  50. "sum",
  51. "percentile",
  52. "http_error_count",
  53. "http_error_rate",
  54. ],
  55. "unit": "millisecond",
  56. }
  57. }
  58. def test_measurements_with_numbers_in_name(self):
  59. self.store_transaction_metric(
  60. 1,
  61. metric="measurements.something_custom",
  62. internal_metric="d:transactions/measurements.1234567890.abcdef@millisecond",
  63. entity="metrics_distributions",
  64. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  65. )
  66. response = self.do_request(
  67. {
  68. "project": self.project.id,
  69. "statsPeriod": "14d",
  70. }
  71. )
  72. assert response.status_code == 200, response.content
  73. assert response.data == {
  74. "measurements.1234567890.abcdef": {
  75. "functions": [
  76. "apdex",
  77. "avg",
  78. "p50",
  79. "p75",
  80. "p90",
  81. "p95",
  82. "p99",
  83. "p100",
  84. "max",
  85. "min",
  86. "sum",
  87. "percentile",
  88. "http_error_count",
  89. "http_error_rate",
  90. ],
  91. "unit": "millisecond",
  92. }
  93. }
  94. def test_measurements_with_lots_of_periods(self):
  95. self.store_transaction_metric(
  96. 1,
  97. metric="measurements.something_custom",
  98. internal_metric="d:transactions/measurements.a.b.c.d.e.f.g@millisecond",
  99. entity="metrics_distributions",
  100. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  101. )
  102. response = self.do_request(
  103. {
  104. "project": self.project.id,
  105. "statsPeriod": "14d",
  106. }
  107. )
  108. assert response.status_code == 200, response.content
  109. assert response.data == {
  110. "measurements.a.b.c.d.e.f.g": {
  111. "functions": [
  112. "apdex",
  113. "avg",
  114. "p50",
  115. "p75",
  116. "p90",
  117. "p95",
  118. "p99",
  119. "p100",
  120. "max",
  121. "min",
  122. "sum",
  123. "percentile",
  124. "http_error_count",
  125. "http_error_rate",
  126. ],
  127. "unit": "millisecond",
  128. }
  129. }
  130. def test_metric_outside_query_daterange(self):
  131. self.store_transaction_metric(
  132. 1,
  133. metric="measurements.something_custom",
  134. internal_metric="d:transactions/measurements.something_custom@millisecond",
  135. entity="metrics_distributions",
  136. timestamp=self.day_ago - timedelta(days=15, minutes=0),
  137. )
  138. response = self.do_request(
  139. {
  140. "project": self.project.id,
  141. "statsPeriod": "14d",
  142. }
  143. )
  144. assert response.status_code == 200, response.content
  145. assert response.data == {}