test_organization_measurements_meta.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from datetime import timedelta
  2. from django.urls import reverse
  3. from sentry.testutils import MetricsEnhancedPerformanceTestCase
  4. from sentry.testutils.helpers.datetime import before_now
  5. class OrganizationMeasurementsMetaEndpoint(MetricsEnhancedPerformanceTestCase):
  6. endpoint = "sentry-api-0-organization-measurements-meta"
  7. METRIC_STRINGS = [
  8. "d:transactions/measurements.something_custom@millisecond",
  9. ]
  10. def setUp(self):
  11. super().setUp()
  12. self.login_as(user=self.user)
  13. self.day_ago = before_now(days=1).replace(hour=10, minute=0, second=0, microsecond=0)
  14. self.DEFAULT_METRIC_TIMESTAMP = self.day_ago
  15. self.url = reverse(
  16. self.endpoint, kwargs={"organization_slug": self.project.organization.slug}
  17. )
  18. self.features = {"organizations:performance-use-metrics": True}
  19. def do_request(self, data, url=None, features=None):
  20. if features is None:
  21. features = {"organizations:discover-basic": True}
  22. features.update(self.features)
  23. with self.feature(features):
  24. return self.client.get(self.url if url is None else url, data=data, format="json")
  25. def test_simple(self):
  26. self.store_metric(
  27. 1,
  28. metric="measurements.something_custom",
  29. internal_metric="d:transactions/measurements.something_custom@millisecond",
  30. entity="metrics_distributions",
  31. timestamp=self.day_ago + timedelta(hours=1, minutes=0),
  32. )
  33. response = self.do_request(
  34. {
  35. "project": self.project.id,
  36. "statsPeriod": "14d",
  37. }
  38. )
  39. assert response.status_code == 200, response.content
  40. assert response.data == {
  41. "measurements.something_custom": {
  42. "functions": [
  43. "apdex",
  44. "avg",
  45. "p50",
  46. "p75",
  47. "p90",
  48. "p95",
  49. "p99",
  50. "p100",
  51. "max",
  52. "min",
  53. "sum",
  54. "percentile",
  55. ],
  56. }
  57. }
  58. def test_metric_outside_query_daterange(self):
  59. self.store_metric(
  60. 1,
  61. metric="measurements.something_custom",
  62. internal_metric="d:transactions/measurements.something_custom@millisecond",
  63. entity="metrics_distributions",
  64. timestamp=self.day_ago - timedelta(days=15, 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 == {}