test_organization_measurements_meta.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_metric_outside_query_daterange(self):
  66. self.store_transaction_metric(
  67. 1,
  68. metric="measurements.something_custom",
  69. internal_metric="d:transactions/measurements.something_custom@millisecond",
  70. entity="metrics_distributions",
  71. timestamp=self.day_ago - timedelta(days=15, 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 == {}