test_organization_events_span_indexed.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from tests.snuba.api.endpoints.test_organization_events import OrganizationEventsEndpointTestBase
  2. class OrganizationEventsSpanIndexedEndpointTest(OrganizationEventsEndpointTestBase):
  3. """Test the indexed spans dataset.
  4. To run this locally you may need to set the ENABLE_SPANS_CONSUMER flag to True in Snuba.
  5. A way to do this is
  6. 1. run: `sentry devservices down snuba`
  7. 2. clone snuba locally
  8. 3. run: `export ENABLE_SPANS_CONSUMER=True`
  9. 4. run snuba
  10. At this point tests should work locally
  11. Once span ingestion is on by default this will no longer need to be done
  12. """
  13. def setUp(self):
  14. super().setUp()
  15. self.features = {
  16. "organizations:starfish-view": True,
  17. }
  18. def test_simple(self):
  19. self.store_spans(
  20. [
  21. self.create_span({"description": "foo"}, start_ts=self.ten_mins_ago),
  22. self.create_span({"description": "bar"}, start_ts=self.ten_mins_ago),
  23. ]
  24. )
  25. response = self.do_request(
  26. {
  27. "field": ["description", "count()"],
  28. "query": "",
  29. "orderby": "description",
  30. "project": self.project.id,
  31. "dataset": "spansIndexed",
  32. }
  33. )
  34. assert response.status_code == 200, response.content
  35. data = response.data["data"]
  36. meta = response.data["meta"]
  37. assert len(data) == 2
  38. assert data[0]["description"] == "bar"
  39. assert data[1]["description"] == "foo"
  40. assert meta["dataset"] == "spansIndexed"
  41. def test_sentry_tags_vs_tags(self):
  42. self.store_spans(
  43. [
  44. self.create_span(
  45. {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
  46. ),
  47. ]
  48. )
  49. response = self.do_request(
  50. {
  51. "field": ["transaction.method", "count()"],
  52. "query": "",
  53. "orderby": "count()",
  54. "project": self.project.id,
  55. "dataset": "spansIndexed",
  56. }
  57. )
  58. assert response.status_code == 200, response.content
  59. data = response.data["data"]
  60. meta = response.data["meta"]
  61. assert len(data) == 1
  62. assert data[0]["transaction.method"] == "foo"
  63. assert meta["dataset"] == "spansIndexed"
  64. def test_sentry_tags_syntax(self):
  65. self.store_spans(
  66. [
  67. self.create_span(
  68. {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
  69. ),
  70. ]
  71. )
  72. response = self.do_request(
  73. {
  74. "field": ["sentry_tags[transaction.method]", "count()"],
  75. "query": "",
  76. "orderby": "count()",
  77. "project": self.project.id,
  78. "dataset": "spansIndexed",
  79. }
  80. )
  81. assert response.status_code == 200, response.content
  82. data = response.data["data"]
  83. meta = response.data["meta"]
  84. assert len(data) == 1
  85. assert data[0]["sentry_tags[transaction.method]"] == "foo"
  86. assert meta["dataset"] == "spansIndexed"