test_organization_measurements_meta.py 5.4 KB

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