test_organization_events_stats.py 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570
  1. import uuid
  2. from datetime import timedelta
  3. from unittest import mock
  4. from uuid import uuid4
  5. import pytest
  6. from dateutil.parser import parse as parse_date
  7. from django.urls import reverse
  8. from pytz import utc
  9. from snuba_sdk.column import Column
  10. from snuba_sdk.conditions import Condition, Op
  11. from snuba_sdk.function import Function
  12. from sentry.constants import MAX_TOP_EVENTS
  13. from sentry.issues.grouptype import ProfileFileIOGroupType
  14. from sentry.models.transaction_threshold import ProjectTransactionThreshold, TransactionMetric
  15. from sentry.snuba.discover import OTHER_KEY
  16. from sentry.testutils import APITestCase, SnubaTestCase
  17. from sentry.testutils.helpers.datetime import before_now, iso_format
  18. from sentry.testutils.silo import region_silo_test
  19. from sentry.utils.samples import load_data
  20. from tests.sentry.issues.test_utils import SearchIssueTestMixin
  21. pytestmark = pytest.mark.sentry_metrics
  22. @region_silo_test
  23. class OrganizationEventsStatsEndpointTest(APITestCase, SnubaTestCase, SearchIssueTestMixin):
  24. endpoint = "sentry-api-0-organization-events-stats"
  25. def setUp(self):
  26. super().setUp()
  27. self.login_as(user=self.user)
  28. self.authed_user = self.user
  29. self.day_ago = before_now(days=1).replace(hour=10, minute=0, second=0, microsecond=0)
  30. self.project = self.create_project()
  31. self.project2 = self.create_project()
  32. self.user = self.create_user()
  33. self.user2 = self.create_user()
  34. self.store_event(
  35. data={
  36. "event_id": "a" * 32,
  37. "message": "very bad",
  38. "timestamp": iso_format(self.day_ago + timedelta(minutes=1)),
  39. "fingerprint": ["group1"],
  40. "tags": {"sentry:user": self.user.email},
  41. },
  42. project_id=self.project.id,
  43. )
  44. self.store_event(
  45. data={
  46. "event_id": "b" * 32,
  47. "message": "oh my",
  48. "timestamp": iso_format(self.day_ago + timedelta(hours=1, minutes=1)),
  49. "fingerprint": ["group2"],
  50. "tags": {"sentry:user": self.user2.email},
  51. },
  52. project_id=self.project2.id,
  53. )
  54. self.store_event(
  55. data={
  56. "event_id": "c" * 32,
  57. "message": "very bad",
  58. "timestamp": iso_format(self.day_ago + timedelta(hours=1, minutes=2)),
  59. "fingerprint": ["group2"],
  60. "tags": {"sentry:user": self.user2.email},
  61. },
  62. project_id=self.project2.id,
  63. )
  64. self.url = reverse(
  65. "sentry-api-0-organization-events-stats",
  66. kwargs={"organization_slug": self.project.organization.slug},
  67. )
  68. self.features = {}
  69. def do_request(self, data, url=None, features=None):
  70. if features is None:
  71. features = {"organizations:discover-basic": True}
  72. features.update(self.features)
  73. with self.feature(features):
  74. return self.client.get(self.url if url is None else url, data=data, format="json")
  75. def test_simple(self):
  76. response = self.do_request(
  77. {
  78. "start": iso_format(self.day_ago),
  79. "end": iso_format(self.day_ago + timedelta(hours=2)),
  80. "interval": "1h",
  81. },
  82. )
  83. assert response.status_code == 200, response.content
  84. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 1}], [{"count": 2}]]
  85. def test_generic_issue(self):
  86. _, _, group_info = self.store_search_issue(
  87. self.project.id,
  88. self.user.id,
  89. [f"{ProfileFileIOGroupType.type_id}-group1"],
  90. "prod",
  91. self.day_ago.replace(tzinfo=utc),
  92. )
  93. self.store_search_issue(
  94. self.project.id,
  95. self.user.id,
  96. [f"{ProfileFileIOGroupType.type_id}-group1"],
  97. "prod",
  98. self.day_ago.replace(tzinfo=utc) + timedelta(hours=1, minutes=1),
  99. )
  100. self.store_search_issue(
  101. self.project.id,
  102. self.user.id,
  103. [f"{ProfileFileIOGroupType.type_id}-group1"],
  104. "prod",
  105. self.day_ago.replace(tzinfo=utc) + timedelta(hours=1, minutes=2),
  106. )
  107. with self.feature(
  108. [
  109. "organizations:profiling",
  110. ]
  111. ):
  112. response = self.do_request(
  113. {
  114. "start": iso_format(self.day_ago),
  115. "end": iso_format(self.day_ago + timedelta(hours=2)),
  116. "interval": "1h",
  117. "query": f"issue:{group_info.group.qualified_short_id}",
  118. "dataset": "issuePlatform",
  119. },
  120. )
  121. assert response.status_code == 200, response.content
  122. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 1}], [{"count": 2}]]
  123. def test_generic_issue_calculated_interval(self):
  124. """Test that a 4h interval returns the correct generic event stats.
  125. This follows a different code path than 1h or 1d as the IssuePlatformTimeSeriesQueryBuilder
  126. does some calculation to create the time column."""
  127. _, _, group_info = self.store_search_issue(
  128. self.project.id,
  129. self.user.id,
  130. [f"{ProfileFileIOGroupType.type_id}-group1"],
  131. "prod",
  132. self.day_ago.replace(tzinfo=utc) + timedelta(minutes=1),
  133. )
  134. self.store_search_issue(
  135. self.project.id,
  136. self.user.id,
  137. [f"{ProfileFileIOGroupType.type_id}-group1"],
  138. "prod",
  139. self.day_ago.replace(tzinfo=utc) + timedelta(minutes=1),
  140. )
  141. self.store_search_issue(
  142. self.project.id,
  143. self.user.id,
  144. [f"{ProfileFileIOGroupType.type_id}-group1"],
  145. "prod",
  146. self.day_ago.replace(tzinfo=utc) + timedelta(minutes=2),
  147. )
  148. with self.feature(
  149. [
  150. "organizations:profiling",
  151. ]
  152. ):
  153. response = self.do_request(
  154. {
  155. "start": iso_format(self.day_ago),
  156. "end": iso_format(self.day_ago + timedelta(hours=4)),
  157. "interval": "4h",
  158. "query": f"issue:{group_info.group.qualified_short_id}",
  159. "dataset": "issuePlatform",
  160. },
  161. )
  162. assert response.status_code == 200, response.content
  163. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 3}], [{"count": 0}]]
  164. def test_misaligned_last_bucket(self):
  165. response = self.do_request(
  166. data={
  167. "start": iso_format(self.day_ago - timedelta(minutes=30)),
  168. "end": iso_format(self.day_ago + timedelta(hours=1, minutes=30)),
  169. "interval": "1h",
  170. "partial": "1",
  171. },
  172. )
  173. assert response.status_code == 200, response.content
  174. assert [attrs for time, attrs in response.data["data"]] == [
  175. [{"count": 0}],
  176. [{"count": 1}],
  177. [{"count": 2}],
  178. ]
  179. def test_no_projects(self):
  180. org = self.create_organization(owner=self.user)
  181. self.login_as(user=self.user)
  182. url = reverse(
  183. "sentry-api-0-organization-events-stats", kwargs={"organization_slug": org.slug}
  184. )
  185. response = self.do_request({}, url)
  186. assert response.status_code == 200, response.content
  187. assert len(response.data["data"]) == 0
  188. def test_user_count(self):
  189. self.store_event(
  190. data={
  191. "event_id": "d" * 32,
  192. "message": "something",
  193. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  194. "tags": {"sentry:user": self.user2.email},
  195. "fingerprint": ["group2"],
  196. },
  197. project_id=self.project2.id,
  198. )
  199. response = self.do_request(
  200. data={
  201. "start": iso_format(self.day_ago),
  202. "end": iso_format(self.day_ago + timedelta(hours=2)),
  203. "interval": "1h",
  204. "yAxis": "user_count",
  205. },
  206. )
  207. assert response.status_code == 200, response.content
  208. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 2}], [{"count": 1}]]
  209. def test_discover2_backwards_compatibility(self):
  210. response = self.do_request(
  211. data={
  212. "project": self.project.id,
  213. "start": iso_format(self.day_ago),
  214. "end": iso_format(self.day_ago + timedelta(hours=2)),
  215. "interval": "1h",
  216. "yAxis": "user_count",
  217. },
  218. )
  219. assert response.status_code == 200, response.content
  220. assert len(response.data["data"]) > 0
  221. response = self.do_request(
  222. data={
  223. "project": self.project.id,
  224. "start": iso_format(self.day_ago),
  225. "end": iso_format(self.day_ago + timedelta(hours=2)),
  226. "interval": "1h",
  227. "yAxis": "event_count",
  228. },
  229. )
  230. assert response.status_code == 200, response.content
  231. assert len(response.data["data"]) > 0
  232. def test_with_event_count_flag(self):
  233. response = self.do_request(
  234. data={
  235. "start": iso_format(self.day_ago),
  236. "end": iso_format(self.day_ago + timedelta(hours=2)),
  237. "interval": "1h",
  238. "yAxis": "event_count",
  239. },
  240. )
  241. assert response.status_code == 200, response.content
  242. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 1}], [{"count": 2}]]
  243. def test_performance_view_feature(self):
  244. response = self.do_request(
  245. data={
  246. "end": iso_format(before_now()),
  247. "start": iso_format(before_now(hours=2)),
  248. "query": "project_id:1",
  249. "interval": "30m",
  250. "yAxis": "count()",
  251. },
  252. features={
  253. "organizations:performance-view": True,
  254. "organizations:discover-basic": False,
  255. },
  256. )
  257. assert response.status_code == 200, response.content
  258. def test_apdex_divide_by_zero(self):
  259. ProjectTransactionThreshold.objects.create(
  260. project=self.project,
  261. organization=self.project.organization,
  262. threshold=600,
  263. metric=TransactionMetric.LCP.value,
  264. )
  265. # Shouldn't count towards apdex
  266. data = load_data(
  267. "transaction",
  268. start_timestamp=self.day_ago + timedelta(minutes=(1)),
  269. timestamp=self.day_ago + timedelta(minutes=(3)),
  270. )
  271. data["transaction"] = "/apdex/new/"
  272. data["user"] = {"email": "1@example.com"}
  273. data["measurements"] = {}
  274. self.store_event(data, project_id=self.project.id)
  275. response = self.do_request(
  276. data={
  277. "start": iso_format(self.day_ago),
  278. "end": iso_format(self.day_ago + timedelta(hours=2)),
  279. "interval": "1h",
  280. "yAxis": "apdex()",
  281. "project": [self.project.id],
  282. },
  283. )
  284. assert response.status_code == 200, response.content
  285. assert len(response.data["data"]) == 2
  286. data = response.data["data"]
  287. # 0 transactions with LCP 0/0
  288. assert [attrs for time, attrs in response.data["data"]] == [
  289. [{"count": 0}],
  290. [{"count": 0}],
  291. ]
  292. def test_aggregate_function_apdex(self):
  293. project1 = self.create_project()
  294. project2 = self.create_project()
  295. events = [
  296. ("one", 400, project1.id),
  297. ("one", 400, project1.id),
  298. ("two", 3000, project2.id),
  299. ("two", 1000, project2.id),
  300. ("three", 3000, project2.id),
  301. ]
  302. for idx, event in enumerate(events):
  303. data = load_data(
  304. "transaction",
  305. start_timestamp=self.day_ago + timedelta(minutes=(1 + idx)),
  306. timestamp=self.day_ago + timedelta(minutes=(1 + idx), milliseconds=event[1]),
  307. )
  308. data["event_id"] = f"{idx}" * 32
  309. data["transaction"] = f"/apdex/new/{event[0]}"
  310. data["user"] = {"email": f"{idx}@example.com"}
  311. self.store_event(data, project_id=event[2])
  312. response = self.do_request(
  313. data={
  314. "start": iso_format(self.day_ago),
  315. "end": iso_format(self.day_ago + timedelta(hours=2)),
  316. "interval": "1h",
  317. "yAxis": "apdex()",
  318. },
  319. )
  320. assert response.status_code == 200, response.content
  321. assert [attrs for time, attrs in response.data["data"]] == [
  322. [{"count": 0.3}],
  323. [{"count": 0}],
  324. ]
  325. ProjectTransactionThreshold.objects.create(
  326. project=project1,
  327. organization=project1.organization,
  328. threshold=100,
  329. metric=TransactionMetric.DURATION.value,
  330. )
  331. ProjectTransactionThreshold.objects.create(
  332. project=project2,
  333. organization=project1.organization,
  334. threshold=100,
  335. metric=TransactionMetric.DURATION.value,
  336. )
  337. response = self.do_request(
  338. data={
  339. "start": iso_format(self.day_ago),
  340. "end": iso_format(self.day_ago + timedelta(hours=2)),
  341. "interval": "1h",
  342. "yAxis": "apdex()",
  343. },
  344. )
  345. assert response.status_code == 200, response.content
  346. assert [attrs for time, attrs in response.data["data"]] == [
  347. [{"count": 0.2}],
  348. [{"count": 0}],
  349. ]
  350. response = self.do_request(
  351. data={
  352. "start": iso_format(self.day_ago),
  353. "end": iso_format(self.day_ago + timedelta(hours=2)),
  354. "interval": "1h",
  355. "yAxis": ["user_count", "apdex()"],
  356. },
  357. )
  358. assert response.status_code == 200, response.content
  359. assert response.data["user_count"]["order"] == 0
  360. assert [attrs for time, attrs in response.data["user_count"]["data"]] == [
  361. [{"count": 5}],
  362. [{"count": 0}],
  363. ]
  364. assert response.data["apdex()"]["order"] == 1
  365. assert [attrs for time, attrs in response.data["apdex()"]["data"]] == [
  366. [{"count": 0.2}],
  367. [{"count": 0}],
  368. ]
  369. def test_aggregate_function_count(self):
  370. response = self.do_request(
  371. data={
  372. "start": iso_format(self.day_ago),
  373. "end": iso_format(self.day_ago + timedelta(hours=2)),
  374. "interval": "1h",
  375. "yAxis": "count()",
  376. },
  377. )
  378. assert response.status_code == 200, response.content
  379. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 1}], [{"count": 2}]]
  380. def test_invalid_aggregate(self):
  381. response = self.do_request(
  382. data={
  383. "start": iso_format(self.day_ago),
  384. "end": iso_format(self.day_ago + timedelta(hours=2)),
  385. "interval": "1h",
  386. "yAxis": "rubbish",
  387. },
  388. )
  389. assert response.status_code == 400, response.content
  390. def test_aggregate_function_user_count(self):
  391. response = self.do_request(
  392. data={
  393. "start": iso_format(self.day_ago),
  394. "end": iso_format(self.day_ago + timedelta(hours=2)),
  395. "interval": "1h",
  396. "yAxis": "count_unique(user)",
  397. },
  398. )
  399. assert response.status_code == 200, response.content
  400. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 1}], [{"count": 1}]]
  401. def test_aggregate_invalid(self):
  402. response = self.do_request(
  403. data={
  404. "start": iso_format(self.day_ago),
  405. "end": iso_format(self.day_ago + timedelta(hours=2)),
  406. "interval": "1h",
  407. "yAxis": "nope(lol)",
  408. },
  409. )
  410. assert response.status_code == 400, response.content
  411. def test_throughput_epm_hour_rollup(self):
  412. project = self.create_project()
  413. # Each of these denotes how many events to create in each hour
  414. event_counts = [6, 0, 6, 3, 0, 3]
  415. for hour, count in enumerate(event_counts):
  416. for minute in range(count):
  417. self.store_event(
  418. data={
  419. "event_id": str(uuid.uuid1()),
  420. "message": "very bad",
  421. "timestamp": iso_format(
  422. self.day_ago + timedelta(hours=hour, minutes=minute)
  423. ),
  424. "fingerprint": ["group1"],
  425. "tags": {"sentry:user": self.user.email},
  426. },
  427. project_id=project.id,
  428. )
  429. for axis in ["epm()", "tpm()"]:
  430. response = self.do_request(
  431. data={
  432. "start": iso_format(self.day_ago),
  433. "end": iso_format(self.day_ago + timedelta(hours=6)),
  434. "interval": "1h",
  435. "yAxis": axis,
  436. "project": project.id,
  437. },
  438. )
  439. assert response.status_code == 200, response.content
  440. data = response.data["data"]
  441. assert len(data) == 6
  442. rows = data[0:6]
  443. for test in zip(event_counts, rows):
  444. assert test[1][1][0]["count"] == test[0] / (3600.0 / 60.0)
  445. def test_throughput_epm_day_rollup(self):
  446. project = self.create_project()
  447. # Each of these denotes how many events to create in each minute
  448. event_counts = [6, 0, 6, 3, 0, 3]
  449. for hour, count in enumerate(event_counts):
  450. for minute in range(count):
  451. self.store_event(
  452. data={
  453. "event_id": str(uuid.uuid1()),
  454. "message": "very bad",
  455. "timestamp": iso_format(
  456. self.day_ago + timedelta(hours=hour, minutes=minute)
  457. ),
  458. "fingerprint": ["group1"],
  459. "tags": {"sentry:user": self.user.email},
  460. },
  461. project_id=project.id,
  462. )
  463. for axis in ["epm()", "tpm()"]:
  464. response = self.do_request(
  465. data={
  466. "start": iso_format(self.day_ago),
  467. "end": iso_format(self.day_ago + timedelta(hours=24)),
  468. "interval": "24h",
  469. "yAxis": axis,
  470. "project": project.id,
  471. },
  472. )
  473. assert response.status_code == 200, response.content
  474. data = response.data["data"]
  475. assert len(data) == 2
  476. assert data[0][1][0]["count"] == sum(event_counts) / (86400.0 / 60.0)
  477. def test_throughput_eps_minute_rollup(self):
  478. project = self.create_project()
  479. # Each of these denotes how many events to create in each minute
  480. event_counts = [6, 0, 6, 3, 0, 3]
  481. for minute, count in enumerate(event_counts):
  482. for second in range(count):
  483. self.store_event(
  484. data={
  485. "event_id": str(uuid.uuid1()),
  486. "message": "very bad",
  487. "timestamp": iso_format(
  488. self.day_ago + timedelta(minutes=minute, seconds=second)
  489. ),
  490. "fingerprint": ["group1"],
  491. "tags": {"sentry:user": self.user.email},
  492. },
  493. project_id=project.id,
  494. )
  495. for axis in ["eps()", "tps()"]:
  496. response = self.do_request(
  497. data={
  498. "start": iso_format(self.day_ago),
  499. "end": iso_format(self.day_ago + timedelta(minutes=6)),
  500. "interval": "1m",
  501. "yAxis": axis,
  502. "project": project.id,
  503. },
  504. )
  505. assert response.status_code == 200, response.content
  506. data = response.data["data"]
  507. assert len(data) == 6
  508. rows = data[0:6]
  509. for test in zip(event_counts, rows):
  510. assert test[1][1][0]["count"] == test[0] / 60.0
  511. def test_throughput_eps_no_rollup(self):
  512. project = self.create_project()
  513. # Each of these denotes how many events to create in each minute
  514. event_counts = [6, 0, 6, 3, 0, 3]
  515. for minute, count in enumerate(event_counts):
  516. for second in range(count):
  517. self.store_event(
  518. data={
  519. "event_id": str(uuid.uuid1()),
  520. "message": "very bad",
  521. "timestamp": iso_format(
  522. self.day_ago + timedelta(minutes=minute, seconds=second)
  523. ),
  524. "fingerprint": ["group1"],
  525. "tags": {"sentry:user": self.user.email},
  526. },
  527. project_id=project.id,
  528. )
  529. response = self.do_request(
  530. data={
  531. "start": iso_format(self.day_ago),
  532. "end": iso_format(self.day_ago + timedelta(minutes=1)),
  533. "interval": "1s",
  534. "yAxis": "eps()",
  535. "project": project.id,
  536. },
  537. )
  538. assert response.status_code == 200, response.content
  539. data = response.data["data"]
  540. # expect 60 data points between time span of 0 and 60 seconds
  541. assert len(data) == 60
  542. rows = data[0:6]
  543. for row in rows:
  544. assert row[1][0]["count"] == 1
  545. def test_transaction_events(self):
  546. prototype = {
  547. "type": "transaction",
  548. "transaction": "api.issue.delete",
  549. "spans": [],
  550. "contexts": {"trace": {"op": "foobar", "trace_id": "a" * 32, "span_id": "a" * 16}},
  551. "tags": {"important": "yes"},
  552. }
  553. fixtures = (
  554. ("d" * 32, before_now(minutes=32)),
  555. ("e" * 32, before_now(hours=1, minutes=2)),
  556. ("f" * 32, before_now(hours=1, minutes=35)),
  557. )
  558. for fixture in fixtures:
  559. data = prototype.copy()
  560. data["event_id"] = fixture[0]
  561. data["timestamp"] = iso_format(fixture[1])
  562. data["start_timestamp"] = iso_format(fixture[1] - timedelta(seconds=1))
  563. self.store_event(data=data, project_id=self.project.id)
  564. response = self.do_request(
  565. data={
  566. "project": self.project.id,
  567. "end": iso_format(before_now()),
  568. "start": iso_format(before_now(hours=2)),
  569. "query": "event.type:transaction",
  570. "interval": "30m",
  571. "yAxis": "count()",
  572. },
  573. )
  574. assert response.status_code == 200, response.content
  575. items = [item for time, item in response.data["data"] if item]
  576. # We could get more results depending on where the 30 min
  577. # windows land.
  578. assert len(items) >= 3
  579. def test_project_id_query_filter(self):
  580. response = self.do_request(
  581. data={
  582. "end": iso_format(before_now()),
  583. "start": iso_format(before_now(hours=2)),
  584. "query": "project_id:1",
  585. "interval": "30m",
  586. "yAxis": "count()",
  587. },
  588. )
  589. assert response.status_code == 200
  590. def test_latest_release_query_filter(self):
  591. response = self.do_request(
  592. data={
  593. "project": self.project.id,
  594. "end": iso_format(before_now()),
  595. "start": iso_format(before_now(hours=2)),
  596. "query": "release:latest",
  597. "interval": "30m",
  598. "yAxis": "count()",
  599. },
  600. )
  601. assert response.status_code == 200
  602. def test_conditional_filter(self):
  603. response = self.do_request(
  604. data={
  605. "start": iso_format(self.day_ago),
  606. "end": iso_format(self.day_ago + timedelta(hours=2)),
  607. "query": "id:{} OR id:{}".format("a" * 32, "b" * 32),
  608. "interval": "30m",
  609. "yAxis": "count()",
  610. },
  611. )
  612. assert response.status_code == 200, response.content
  613. data = response.data["data"]
  614. assert len(data) == 4
  615. assert data[0][1][0]["count"] == 1
  616. assert data[2][1][0]["count"] == 1
  617. def test_simple_multiple_yaxis(self):
  618. response = self.do_request(
  619. data={
  620. "start": iso_format(self.day_ago),
  621. "end": iso_format(self.day_ago + timedelta(hours=2)),
  622. "interval": "1h",
  623. "yAxis": ["user_count", "event_count"],
  624. },
  625. )
  626. assert response.status_code == 200, response.content
  627. assert response.data["user_count"]["order"] == 0
  628. assert [attrs for time, attrs in response.data["user_count"]["data"]] == [
  629. [{"count": 1}],
  630. [{"count": 1}],
  631. ]
  632. assert response.data["event_count"]["order"] == 1
  633. assert [attrs for time, attrs in response.data["event_count"]["data"]] == [
  634. [{"count": 1}],
  635. [{"count": 2}],
  636. ]
  637. def test_equation_yaxis(self):
  638. response = self.do_request(
  639. data={
  640. "start": iso_format(self.day_ago),
  641. "end": iso_format(self.day_ago + timedelta(hours=2)),
  642. "interval": "1h",
  643. "yAxis": ["equation|count() / 100"],
  644. },
  645. )
  646. assert response.status_code == 200, response.content
  647. assert len(response.data["data"]) == 2
  648. assert [attrs for time, attrs in response.data["data"]] == [
  649. [{"count": 0.01}],
  650. [{"count": 0.02}],
  651. ]
  652. def test_equation_mixed_multi_yaxis(self):
  653. response = self.do_request(
  654. data={
  655. "start": iso_format(self.day_ago),
  656. "end": iso_format(self.day_ago + timedelta(hours=2)),
  657. "interval": "1h",
  658. "yAxis": ["count()", "equation|count() * 100"],
  659. },
  660. )
  661. assert response.status_code == 200, response.content
  662. assert response.data["count()"]["order"] == 0
  663. assert [attrs for time, attrs in response.data["count()"]["data"]] == [
  664. [{"count": 1}],
  665. [{"count": 2}],
  666. ]
  667. assert response.data["equation|count() * 100"]["order"] == 1
  668. assert [attrs for time, attrs in response.data["equation|count() * 100"]["data"]] == [
  669. [{"count": 100}],
  670. [{"count": 200}],
  671. ]
  672. def test_equation_multi_yaxis(self):
  673. response = self.do_request(
  674. data={
  675. "start": iso_format(self.day_ago),
  676. "end": iso_format(self.day_ago + timedelta(hours=2)),
  677. "interval": "1h",
  678. "yAxis": ["equation|count() / 100", "equation|count() * 100"],
  679. },
  680. )
  681. assert response.status_code == 200, response.content
  682. assert response.data["equation|count() / 100"]["order"] == 0
  683. assert [attrs for time, attrs in response.data["equation|count() / 100"]["data"]] == [
  684. [{"count": 0.01}],
  685. [{"count": 0.02}],
  686. ]
  687. assert response.data["equation|count() * 100"]["order"] == 1
  688. assert [attrs for time, attrs in response.data["equation|count() * 100"]["data"]] == [
  689. [{"count": 100}],
  690. [{"count": 200}],
  691. ]
  692. def test_large_interval_no_drop_values(self):
  693. self.store_event(
  694. data={
  695. "event_id": "d" * 32,
  696. "message": "not good",
  697. "timestamp": iso_format(self.day_ago - timedelta(minutes=10)),
  698. "fingerprint": ["group3"],
  699. },
  700. project_id=self.project.id,
  701. )
  702. response = self.do_request(
  703. data={
  704. "project": self.project.id,
  705. "end": iso_format(self.day_ago),
  706. "start": iso_format(self.day_ago - timedelta(hours=24)),
  707. "query": 'message:"not good"',
  708. "interval": "1d",
  709. "yAxis": "count()",
  710. },
  711. )
  712. assert response.status_code == 200
  713. assert [attrs for time, attrs in response.data["data"]] == [[{"count": 0}], [{"count": 1}]]
  714. @mock.patch("sentry.snuba.discover.timeseries_query", return_value={})
  715. def test_multiple_yaxis_only_one_query(self, mock_query):
  716. self.do_request(
  717. data={
  718. "project": self.project.id,
  719. "start": iso_format(self.day_ago),
  720. "end": iso_format(self.day_ago + timedelta(hours=2)),
  721. "interval": "1h",
  722. "yAxis": ["user_count", "event_count", "epm()", "eps()"],
  723. },
  724. )
  725. assert mock_query.call_count == 1
  726. @mock.patch("sentry.snuba.discover.bulk_snql_query", return_value=[{"data": []}])
  727. def test_invalid_interval(self, mock_query):
  728. self.do_request(
  729. data={
  730. "end": iso_format(before_now()),
  731. "start": iso_format(before_now(hours=24)),
  732. "query": "",
  733. "interval": "1s",
  734. "yAxis": "count()",
  735. },
  736. )
  737. assert mock_query.call_count == 1
  738. # Should've reset to the default for 24h
  739. assert mock_query.mock_calls[0].args[0][0].query.granularity.granularity == 300
  740. self.do_request(
  741. data={
  742. "end": iso_format(before_now()),
  743. "start": iso_format(before_now(hours=24)),
  744. "query": "",
  745. "interval": "0d",
  746. "yAxis": "count()",
  747. },
  748. )
  749. assert mock_query.call_count == 2
  750. # Should've reset to the default for 24h
  751. assert mock_query.mock_calls[1].args[0][0].query.granularity.granularity == 300
  752. def test_out_of_retention(self):
  753. with self.options({"system.event-retention-days": 10}):
  754. response = self.do_request(
  755. data={
  756. "start": iso_format(before_now(days=20)),
  757. "end": iso_format(before_now(days=15)),
  758. "query": "",
  759. "interval": "30m",
  760. "yAxis": "count()",
  761. },
  762. )
  763. assert response.status_code == 400
  764. @mock.patch("sentry.utils.snuba.quantize_time")
  765. def test_quantize_dates(self, mock_quantize):
  766. mock_quantize.return_value = before_now(days=1).replace(tzinfo=utc)
  767. # Don't quantize short time periods
  768. self.do_request(
  769. data={"statsPeriod": "1h", "query": "", "interval": "30m", "yAxis": "count()"},
  770. )
  771. # Don't quantize absolute date periods
  772. self.do_request(
  773. data={
  774. "start": iso_format(before_now(days=20)),
  775. "end": iso_format(before_now(days=15)),
  776. "query": "",
  777. "interval": "30m",
  778. "yAxis": "count()",
  779. },
  780. )
  781. assert len(mock_quantize.mock_calls) == 0
  782. # Quantize long date periods
  783. self.do_request(
  784. data={"statsPeriod": "90d", "query": "", "interval": "30m", "yAxis": "count()"},
  785. )
  786. assert len(mock_quantize.mock_calls) == 2
  787. def test_with_zerofill(self):
  788. response = self.do_request(
  789. data={
  790. "start": iso_format(self.day_ago),
  791. "end": iso_format(self.day_ago + timedelta(hours=2)),
  792. "interval": "30m",
  793. },
  794. )
  795. assert response.status_code == 200, response.content
  796. assert [attrs for time, attrs in response.data["data"]] == [
  797. [{"count": 1}],
  798. [{"count": 0}],
  799. [{"count": 2}],
  800. [{"count": 0}],
  801. ]
  802. def test_without_zerofill(self):
  803. start = iso_format(self.day_ago)
  804. end = iso_format(self.day_ago + timedelta(hours=2))
  805. response = self.do_request(
  806. data={
  807. "start": start,
  808. "end": end,
  809. "interval": "30m",
  810. "withoutZerofill": "1",
  811. },
  812. features={
  813. "organizations:performance-chart-interpolation": True,
  814. "organizations:discover-basic": True,
  815. },
  816. )
  817. assert response.status_code == 200, response.content
  818. assert [attrs for time, attrs in response.data["data"]] == [
  819. [{"count": 1}],
  820. [{"count": 2}],
  821. ]
  822. assert response.data["start"] == parse_date(start).timestamp()
  823. assert response.data["end"] == parse_date(end).timestamp()
  824. def test_comparison(self):
  825. self.store_event(
  826. data={
  827. "timestamp": iso_format(self.day_ago + timedelta(days=-1, minutes=1)),
  828. },
  829. project_id=self.project.id,
  830. )
  831. self.store_event(
  832. data={
  833. "timestamp": iso_format(self.day_ago + timedelta(days=-1, minutes=2)),
  834. },
  835. project_id=self.project.id,
  836. )
  837. self.store_event(
  838. data={
  839. "timestamp": iso_format(self.day_ago + timedelta(days=-1, hours=1, minutes=1)),
  840. },
  841. project_id=self.project2.id,
  842. )
  843. response = self.do_request(
  844. data={
  845. "start": iso_format(self.day_ago),
  846. "end": iso_format(self.day_ago + timedelta(hours=2)),
  847. "interval": "1h",
  848. "comparisonDelta": int(timedelta(days=1).total_seconds()),
  849. }
  850. )
  851. assert response.status_code == 200, response.content
  852. assert [attrs for time, attrs in response.data["data"]] == [
  853. [{"count": 1, "comparisonCount": 2}],
  854. [{"count": 2, "comparisonCount": 1}],
  855. ]
  856. def test_comparison_invalid(self):
  857. response = self.do_request(
  858. data={
  859. "start": iso_format(self.day_ago),
  860. "end": iso_format(self.day_ago + timedelta(hours=2)),
  861. "interval": "1h",
  862. "comparisonDelta": "17h",
  863. },
  864. )
  865. assert response.status_code == 400, response.content
  866. assert response.data["detail"] == "comparisonDelta must be an integer"
  867. start = before_now(days=85)
  868. end = start + timedelta(days=7)
  869. with self.options({"system.event-retention-days": 90}):
  870. response = self.do_request(
  871. data={
  872. "start": iso_format(start),
  873. "end": iso_format(end),
  874. "interval": "1h",
  875. "comparisonDelta": int(timedelta(days=7).total_seconds()),
  876. }
  877. )
  878. assert response.status_code == 400, response.content
  879. assert response.data["detail"] == "Comparison period is outside retention window"
  880. def test_equations_divide_by_zero(self):
  881. response = self.do_request(
  882. data={
  883. "start": iso_format(self.day_ago),
  884. "end": iso_format(self.day_ago + timedelta(hours=2)),
  885. "interval": "1h",
  886. # force a 0 in the denominator by doing 1 - 1
  887. # since a 0 literal is illegal as the denominator
  888. "yAxis": ["equation|count() / (1-1)"],
  889. },
  890. )
  891. assert response.status_code == 200, response.content
  892. assert len(response.data["data"]) == 2
  893. assert [attrs for time, attrs in response.data["data"]] == [
  894. [{"count": None}],
  895. [{"count": None}],
  896. ]
  897. @mock.patch("sentry.search.events.builder.discover.raw_snql_query")
  898. def test_profiles_dataset_simple(self, mock_snql_query):
  899. mock_snql_query.side_effect = [{"meta": {}, "data": []}]
  900. query = {
  901. "yAxis": [
  902. "count()",
  903. "p75()",
  904. "p95()",
  905. "p99()",
  906. "p75(profile.duration)",
  907. "p95(profile.duration)",
  908. "p99(profile.duration)",
  909. ],
  910. "project": [self.project.id],
  911. "dataset": "profiles",
  912. }
  913. response = self.do_request(query, features={"organizations:profiling": True})
  914. assert response.status_code == 200, response.content
  915. def test_tag_with_conflicting_function_alias_simple(self):
  916. for _ in range(7):
  917. self.store_event(
  918. data={
  919. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  920. "tags": {"count": "9001"},
  921. },
  922. project_id=self.project2.id,
  923. )
  924. # Query for count and count()
  925. data = {
  926. "start": iso_format(self.day_ago),
  927. "end": iso_format(self.day_ago + timedelta(minutes=3)),
  928. "interval": "1h",
  929. "yAxis": "count()",
  930. "orderby": ["-count()"],
  931. "field": ["count()", "count"],
  932. "partial": 1,
  933. }
  934. response = self.client.get(self.url, data, format="json")
  935. assert response.status_code == 200
  936. # Expect a count of 8 because one event from setUp
  937. assert response.data["data"][0][1] == [{"count": 8}]
  938. data["query"] = "count:9001"
  939. response = self.client.get(self.url, data, format="json")
  940. assert response.status_code == 200
  941. assert response.data["data"][0][1] == [{"count": 7}]
  942. data["query"] = "count:abc"
  943. response = self.client.get(self.url, data, format="json")
  944. assert response.status_code == 200
  945. assert all([interval[1][0]["count"] == 0 for interval in response.data["data"]])
  946. def test_group_id_tag_simple(self):
  947. event_data = {
  948. "data": {
  949. "message": "poof",
  950. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  951. "user": {"email": self.user.email},
  952. "tags": {"group_id": "testing"},
  953. "fingerprint": ["group1"],
  954. },
  955. "project": self.project2,
  956. "count": 7,
  957. }
  958. for i in range(event_data["count"]):
  959. event_data["data"]["event_id"] = f"a{i}" * 16
  960. self.store_event(event_data["data"], project_id=event_data["project"].id)
  961. data = {
  962. "start": iso_format(self.day_ago),
  963. "end": iso_format(self.day_ago + timedelta(hours=2)),
  964. "interval": "1h",
  965. "yAxis": "count()",
  966. "orderby": ["-count()"],
  967. "field": ["count()", "group_id"],
  968. "partial": 1,
  969. }
  970. response = self.client.get(self.url, data, format="json")
  971. assert response.status_code == 200
  972. assert response.data["data"][0][1] == [{"count": 8}]
  973. data["query"] = "group_id:testing"
  974. response = self.client.get(self.url, data, format="json")
  975. assert response.status_code == 200
  976. assert response.data["data"][0][1] == [{"count": 7}]
  977. data["query"] = "group_id:abc"
  978. response = self.client.get(self.url, data, format="json")
  979. assert response.status_code == 200
  980. assert all([interval[1][0]["count"] == 0 for interval in response.data["data"]])
  981. @region_silo_test
  982. class OrganizationEventsStatsTopNEvents(APITestCase, SnubaTestCase):
  983. def setUp(self):
  984. super().setUp()
  985. self.login_as(user=self.user)
  986. self.day_ago = before_now(days=1).replace(hour=10, minute=0, second=0, microsecond=0)
  987. self.project = self.create_project()
  988. self.project2 = self.create_project()
  989. self.user2 = self.create_user()
  990. transaction_data = load_data("transaction")
  991. transaction_data["start_timestamp"] = iso_format(self.day_ago + timedelta(minutes=2))
  992. transaction_data["timestamp"] = iso_format(self.day_ago + timedelta(minutes=4))
  993. transaction_data["tags"] = {"shared-tag": "yup"}
  994. self.event_data = [
  995. {
  996. "data": {
  997. "message": "poof",
  998. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  999. "user": {"email": self.user.email},
  1000. "tags": {"shared-tag": "yup"},
  1001. "fingerprint": ["group1"],
  1002. },
  1003. "project": self.project2,
  1004. "count": 7,
  1005. },
  1006. {
  1007. "data": {
  1008. "message": "voof",
  1009. "timestamp": iso_format(self.day_ago + timedelta(hours=1, minutes=2)),
  1010. "fingerprint": ["group2"],
  1011. "user": {"email": self.user2.email},
  1012. "tags": {"shared-tag": "yup"},
  1013. },
  1014. "project": self.project2,
  1015. "count": 6,
  1016. },
  1017. {
  1018. "data": {
  1019. "message": "very bad",
  1020. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1021. "fingerprint": ["group3"],
  1022. "user": {"email": "foo@example.com"},
  1023. "tags": {"shared-tag": "yup"},
  1024. },
  1025. "project": self.project,
  1026. "count": 5,
  1027. },
  1028. {
  1029. "data": {
  1030. "message": "oh no",
  1031. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1032. "fingerprint": ["group4"],
  1033. "user": {"email": "bar@example.com"},
  1034. "tags": {"shared-tag": "yup"},
  1035. },
  1036. "project": self.project,
  1037. "count": 4,
  1038. },
  1039. {"data": transaction_data, "project": self.project, "count": 3},
  1040. # Not in the top 5
  1041. {
  1042. "data": {
  1043. "message": "sorta bad",
  1044. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1045. "fingerprint": ["group5"],
  1046. "user": {"email": "bar@example.com"},
  1047. "tags": {"shared-tag": "yup"},
  1048. },
  1049. "project": self.project,
  1050. "count": 2,
  1051. },
  1052. {
  1053. "data": {
  1054. "message": "not so bad",
  1055. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1056. "fingerprint": ["group6"],
  1057. "user": {"email": "bar@example.com"},
  1058. "tags": {"shared-tag": "yup"},
  1059. },
  1060. "project": self.project,
  1061. "count": 1,
  1062. },
  1063. ]
  1064. self.events = []
  1065. for index, event_data in enumerate(self.event_data):
  1066. data = event_data["data"].copy()
  1067. event = {}
  1068. for i in range(event_data["count"]):
  1069. data["event_id"] = f"{index}{i}" * 16
  1070. event = self.store_event(data, project_id=event_data["project"].id)
  1071. self.events.append(event)
  1072. self.transaction = self.events[4]
  1073. self.enabled_features = {
  1074. "organizations:discover-basic": True,
  1075. }
  1076. self.url = reverse(
  1077. "sentry-api-0-organization-events-stats",
  1078. kwargs={"organization_slug": self.project.organization.slug},
  1079. )
  1080. def test_no_top_events_with_project_field(self):
  1081. project = self.create_project()
  1082. with self.feature(self.enabled_features):
  1083. response = self.client.get(
  1084. self.url,
  1085. data={
  1086. # make sure to query the project with 0 events
  1087. "project": project.id,
  1088. "start": iso_format(self.day_ago),
  1089. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1090. "interval": "1h",
  1091. "yAxis": "count()",
  1092. "orderby": ["-count()"],
  1093. "field": ["count()", "project"],
  1094. "topEvents": 5,
  1095. },
  1096. format="json",
  1097. )
  1098. assert response.status_code == 200, response.content
  1099. # When there are no top events, we do not return an empty dict.
  1100. # Instead, we return a single zero-filled series for an empty graph.
  1101. data = response.data["data"]
  1102. assert [attrs for time, attrs in data] == [[{"count": 0}], [{"count": 0}]]
  1103. def test_no_top_events(self):
  1104. project = self.create_project()
  1105. with self.feature(self.enabled_features):
  1106. response = self.client.get(
  1107. self.url,
  1108. data={
  1109. # make sure to query the project with 0 events
  1110. "project": project.id,
  1111. "start": iso_format(self.day_ago),
  1112. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1113. "interval": "1h",
  1114. "yAxis": "count()",
  1115. "orderby": ["-count()"],
  1116. "field": ["count()", "message", "user.email"],
  1117. "topEvents": 5,
  1118. },
  1119. format="json",
  1120. )
  1121. data = response.data["data"]
  1122. assert response.status_code == 200, response.content
  1123. # When there are no top events, we do not return an empty dict.
  1124. # Instead, we return a single zero-filled series for an empty graph.
  1125. assert [attrs for time, attrs in data] == [[{"count": 0}], [{"count": 0}]]
  1126. def test_no_top_events_with_multi_axis(self):
  1127. project = self.create_project()
  1128. with self.feature(self.enabled_features):
  1129. response = self.client.get(
  1130. self.url,
  1131. data={
  1132. # make sure to query the project with 0 events
  1133. "project": project.id,
  1134. "start": iso_format(self.day_ago),
  1135. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1136. "interval": "1h",
  1137. "yAxis": ["count()", "count_unique(user)"],
  1138. "orderby": ["-count()"],
  1139. "field": ["count()", "count_unique(user)", "message", "user.email"],
  1140. "topEvents": 5,
  1141. },
  1142. format="json",
  1143. )
  1144. assert response.status_code == 200
  1145. data = response.data[""]
  1146. assert [attrs for time, attrs in data["count()"]["data"]] == [
  1147. [{"count": 0}],
  1148. [{"count": 0}],
  1149. ]
  1150. assert [attrs for time, attrs in data["count_unique(user)"]["data"]] == [
  1151. [{"count": 0}],
  1152. [{"count": 0}],
  1153. ]
  1154. def test_simple_top_events(self):
  1155. with self.feature(self.enabled_features):
  1156. response = self.client.get(
  1157. self.url,
  1158. data={
  1159. "start": iso_format(self.day_ago),
  1160. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1161. "interval": "1h",
  1162. "yAxis": "count()",
  1163. "orderby": ["-count()"],
  1164. "field": ["count()", "message", "user.email"],
  1165. "topEvents": 5,
  1166. },
  1167. format="json",
  1168. )
  1169. data = response.data
  1170. assert response.status_code == 200, response.content
  1171. assert len(data) == 6
  1172. for index, event in enumerate(self.events[:5]):
  1173. message = event.message or event.transaction
  1174. results = data[
  1175. ",".join([message, self.event_data[index]["data"]["user"].get("email", "None")])
  1176. ]
  1177. assert results["order"] == index
  1178. assert [{"count": self.event_data[index]["count"]}] in [
  1179. attrs for _, attrs in results["data"]
  1180. ]
  1181. other = data["Other"]
  1182. assert other["order"] == 5
  1183. assert [{"count": 3}] in [attrs for _, attrs in other["data"]]
  1184. def test_tag_with_conflicting_function_alias_simple(self):
  1185. event_data = {
  1186. "data": {
  1187. "message": "poof",
  1188. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1189. "user": {"email": self.user.email},
  1190. "tags": {"count": "9001"},
  1191. "fingerprint": ["group1"],
  1192. },
  1193. "project": self.project2,
  1194. "count": 7,
  1195. }
  1196. for i in range(event_data["count"]):
  1197. event_data["data"]["event_id"] = f"a{i}" * 16
  1198. self.store_event(event_data["data"], project_id=event_data["project"].id)
  1199. # Query for count and count()
  1200. data = {
  1201. "start": iso_format(self.day_ago),
  1202. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1203. "interval": "1h",
  1204. "yAxis": "count()",
  1205. "orderby": ["-count()"],
  1206. "field": ["count()", "count"],
  1207. "topEvents": 5,
  1208. "partial": 1,
  1209. }
  1210. with self.feature(self.enabled_features):
  1211. response = self.client.get(self.url, data, format="json")
  1212. assert response.status_code == 200
  1213. assert response.data["9001"]["data"][0][1] == [{"count": 7}]
  1214. data["query"] = "count:9001"
  1215. with self.feature(self.enabled_features):
  1216. response = self.client.get(self.url, data, format="json")
  1217. assert response.status_code == 200
  1218. assert response.data["9001"]["data"][0][1] == [{"count": 7}]
  1219. data["query"] = "count:abc"
  1220. with self.feature(self.enabled_features):
  1221. response = self.client.get(self.url, data, format="json")
  1222. assert response.status_code == 200
  1223. assert all([interval[1][0]["count"] == 0 for interval in response.data["data"]])
  1224. @pytest.mark.xfail(
  1225. reason="The response.data[Other] returns 15 locally and returns 16 or 15 remotely."
  1226. )
  1227. def test_tag_with_conflicting_function_alias_with_other_single_grouping(self):
  1228. event_data = [
  1229. {
  1230. "data": {
  1231. "message": "poof",
  1232. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1233. "user": {"email": self.user.email},
  1234. "tags": {"count": "9001"},
  1235. "fingerprint": ["group1"],
  1236. },
  1237. "project": self.project2,
  1238. "count": 7,
  1239. },
  1240. {
  1241. "data": {
  1242. "message": "poof2",
  1243. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1244. "user": {"email": self.user.email},
  1245. "tags": {"count": "abc"},
  1246. "fingerprint": ["group1"],
  1247. },
  1248. "project": self.project2,
  1249. "count": 3,
  1250. },
  1251. ]
  1252. for index, event in enumerate(event_data):
  1253. for i in range(event["count"]):
  1254. event["data"]["event_id"] = f"{index}{i}" * 16
  1255. self.store_event(event["data"], project_id=event["project"].id)
  1256. # Query for count and count()
  1257. data = {
  1258. "start": iso_format(self.day_ago),
  1259. "end": iso_format(self.day_ago + timedelta(hours=1)),
  1260. "interval": "1h",
  1261. "yAxis": "count()",
  1262. "orderby": ["-count"],
  1263. "field": ["count()", "count"],
  1264. "topEvents": 2,
  1265. "partial": 1,
  1266. }
  1267. with self.feature(self.enabled_features):
  1268. response = self.client.get(self.url, data, format="json")
  1269. assert response.status_code == 200
  1270. assert response.data["9001"]["data"][0][1] == [{"count": 7}]
  1271. assert response.data["abc"]["data"][0][1] == [{"count": 3}]
  1272. assert response.data["Other"]["data"][0][1] == [{"count": 16}]
  1273. def test_tag_with_conflicting_function_alias_with_other_multiple_groupings(self):
  1274. event_data = [
  1275. {
  1276. "data": {
  1277. "message": "abc",
  1278. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1279. "user": {"email": self.user.email},
  1280. "tags": {"count": "2"},
  1281. "fingerprint": ["group1"],
  1282. },
  1283. "project": self.project2,
  1284. "count": 3,
  1285. },
  1286. {
  1287. "data": {
  1288. "message": "def",
  1289. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1290. "user": {"email": self.user.email},
  1291. "tags": {"count": "9001"},
  1292. "fingerprint": ["group1"],
  1293. },
  1294. "project": self.project2,
  1295. "count": 7,
  1296. },
  1297. ]
  1298. for index, event in enumerate(event_data):
  1299. for i in range(event["count"]):
  1300. event["data"]["event_id"] = f"{index}{i}" * 16
  1301. self.store_event(event["data"], project_id=event["project"].id)
  1302. # Query for count and count()
  1303. data = {
  1304. "start": iso_format(self.day_ago),
  1305. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1306. "interval": "2d",
  1307. "yAxis": "count()",
  1308. "orderby": ["-count"],
  1309. "field": ["count()", "count", "message"],
  1310. "topEvents": 2,
  1311. "partial": 1,
  1312. }
  1313. with self.feature(self.enabled_features):
  1314. response = self.client.get(self.url, data, format="json")
  1315. assert response.status_code == 200
  1316. assert response.data["abc,2"]["data"][0][1] == [{"count": 3}]
  1317. assert response.data["def,9001"]["data"][0][1] == [{"count": 7}]
  1318. assert response.data["Other"]["data"][0][1] == [{"count": 25}]
  1319. def test_group_id_tag_simple(self):
  1320. event_data = {
  1321. "data": {
  1322. "message": "poof",
  1323. "timestamp": iso_format(self.day_ago + timedelta(minutes=2)),
  1324. "user": {"email": self.user.email},
  1325. "tags": {"group_id": "the tag"},
  1326. "fingerprint": ["group1"],
  1327. },
  1328. "project": self.project2,
  1329. "count": 7,
  1330. }
  1331. for i in range(event_data["count"]):
  1332. event_data["data"]["event_id"] = f"a{i}" * 16
  1333. self.store_event(event_data["data"], project_id=event_data["project"].id)
  1334. data = {
  1335. "start": iso_format(self.day_ago),
  1336. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1337. "interval": "1h",
  1338. "yAxis": "count()",
  1339. "orderby": ["-count()"],
  1340. "field": ["count()", "group_id"],
  1341. "topEvents": 5,
  1342. "partial": 1,
  1343. }
  1344. with self.feature(self.enabled_features):
  1345. response = self.client.get(self.url, data, format="json")
  1346. assert response.status_code == 200, response.content
  1347. assert response.data["the tag"]["data"][0][1] == [{"count": 7}]
  1348. data["query"] = 'group_id:"the tag"'
  1349. with self.feature(self.enabled_features):
  1350. response = self.client.get(self.url, data, format="json")
  1351. assert response.status_code == 200
  1352. assert response.data["the tag"]["data"][0][1] == [{"count": 7}]
  1353. data["query"] = "group_id:abc"
  1354. with self.feature(self.enabled_features):
  1355. response = self.client.get(self.url, data, format="json")
  1356. assert response.status_code == 200
  1357. assert all([interval[1][0]["count"] == 0 for interval in response.data["data"]])
  1358. def test_top_events_limits(self):
  1359. data = {
  1360. "start": iso_format(self.day_ago),
  1361. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1362. "interval": "1h",
  1363. "yAxis": "count()",
  1364. "orderby": ["-count()"],
  1365. "field": ["count()", "message", "user.email"],
  1366. }
  1367. with self.feature(self.enabled_features):
  1368. data["topEvents"] = MAX_TOP_EVENTS + 1
  1369. response = self.client.get(self.url, data, format="json")
  1370. assert response.status_code == 400
  1371. data["topEvents"] = 0
  1372. response = self.client.get(self.url, data, format="json")
  1373. assert response.status_code == 400
  1374. data["topEvents"] = "a"
  1375. response = self.client.get(self.url, data, format="json")
  1376. assert response.status_code == 400
  1377. def test_top_events_with_projects(self):
  1378. with self.feature(self.enabled_features):
  1379. response = self.client.get(
  1380. self.url,
  1381. data={
  1382. "start": iso_format(self.day_ago),
  1383. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1384. "interval": "1h",
  1385. "yAxis": "count()",
  1386. "orderby": ["-count()"],
  1387. "field": ["count()", "message", "project"],
  1388. "topEvents": 5,
  1389. },
  1390. format="json",
  1391. )
  1392. data = response.data
  1393. assert response.status_code == 200, response.content
  1394. assert len(data) == 6
  1395. for index, event in enumerate(self.events[:5]):
  1396. message = event.message or event.transaction
  1397. results = data[",".join([message, event.project.slug])]
  1398. assert results["order"] == index
  1399. assert [{"count": self.event_data[index]["count"]}] in [
  1400. attrs for time, attrs in results["data"]
  1401. ]
  1402. other = data["Other"]
  1403. assert other["order"] == 5
  1404. assert [{"count": 3}] in [attrs for _, attrs in other["data"]]
  1405. def test_top_events_with_issue(self):
  1406. # delete a group to make sure if this happens the value becomes unknown
  1407. event_group = self.events[0].group
  1408. event_group.delete()
  1409. with self.feature(self.enabled_features):
  1410. response = self.client.get(
  1411. self.url,
  1412. data={
  1413. "start": iso_format(self.day_ago),
  1414. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1415. "interval": "1h",
  1416. "yAxis": "count()",
  1417. "orderby": ["-count()"],
  1418. "field": ["count()", "message", "issue"],
  1419. "topEvents": 5,
  1420. "query": "!event.type:transaction",
  1421. },
  1422. format="json",
  1423. )
  1424. data = response.data
  1425. assert response.status_code == 200, response.content
  1426. assert len(data) == 6
  1427. for index, event in enumerate(self.events[:4]):
  1428. message = event.message
  1429. # Because we deleted the group for event 0
  1430. if index == 0 or event.group is None:
  1431. issue = "unknown"
  1432. else:
  1433. issue = event.group.qualified_short_id
  1434. results = data[",".join([issue, message])]
  1435. assert results["order"] == index
  1436. assert [{"count": self.event_data[index]["count"]}] in [
  1437. attrs for time, attrs in results["data"]
  1438. ]
  1439. other = data["Other"]
  1440. assert other["order"] == 5
  1441. assert [{"count": 1}] in [attrs for _, attrs in other["data"]]
  1442. def test_top_events_with_transaction_status(self):
  1443. with self.feature(self.enabled_features):
  1444. response = self.client.get(
  1445. self.url,
  1446. data={
  1447. "start": iso_format(self.day_ago),
  1448. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1449. "interval": "1h",
  1450. "yAxis": "count()",
  1451. "orderby": ["-count()"],
  1452. "field": ["count()", "transaction.status"],
  1453. "topEvents": 5,
  1454. },
  1455. format="json",
  1456. )
  1457. data = response.data
  1458. assert response.status_code == 200, response.content
  1459. assert len(data) == 1
  1460. assert "ok" in data
  1461. @mock.patch("sentry.models.GroupManager.get_issues_mapping")
  1462. def test_top_events_with_unknown_issue(self, mock_issues_mapping):
  1463. event = self.events[0]
  1464. event_data = self.event_data[0]
  1465. # ensure that the issue mapping returns None for the issue
  1466. mock_issues_mapping.return_value = {event.group.id: None}
  1467. with self.feature(self.enabled_features):
  1468. response = self.client.get(
  1469. self.url,
  1470. data={
  1471. "start": iso_format(self.day_ago),
  1472. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1473. "interval": "1h",
  1474. "yAxis": "count()",
  1475. "orderby": ["-count()"],
  1476. "field": ["count()", "issue"],
  1477. "topEvents": 5,
  1478. # narrow the search to just one issue
  1479. "query": f"issue.id:{event.group.id}",
  1480. },
  1481. format="json",
  1482. )
  1483. assert response.status_code == 200, response.content
  1484. data = response.data
  1485. assert len(data) == 1
  1486. results = data["unknown"]
  1487. assert results["order"] == 0
  1488. assert [{"count": event_data["count"]}] in [attrs for time, attrs in results["data"]]
  1489. @mock.patch(
  1490. "sentry.search.events.builder.discover.raw_snql_query",
  1491. side_effect=[{"data": [{"issue.id": 1}], "meta": []}, {"data": [], "meta": []}],
  1492. )
  1493. def test_top_events_with_issue_check_query_conditions(self, mock_query):
  1494. """ "Intentionally separate from test_top_events_with_issue
  1495. This is to test against a bug where the condition for issues wasn't included and we'd be missing data for
  1496. the interval since we'd cap out the max rows. This was not caught by the previous test since the results
  1497. would still be correct given the smaller interval & lack of data
  1498. """
  1499. with self.feature(self.enabled_features):
  1500. self.client.get(
  1501. self.url,
  1502. data={
  1503. "start": iso_format(self.day_ago),
  1504. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1505. "interval": "1h",
  1506. "yAxis": "count()",
  1507. "orderby": ["-count()"],
  1508. "field": ["count()", "message", "issue"],
  1509. "topEvents": 5,
  1510. "query": "!event.type:transaction",
  1511. },
  1512. format="json",
  1513. )
  1514. assert (
  1515. Condition(Function("coalesce", [Column("group_id"), 0], "issue.id"), Op.IN, [1])
  1516. in mock_query.mock_calls[1].args[0].query.where
  1517. )
  1518. def test_top_events_with_functions(self):
  1519. with self.feature(self.enabled_features):
  1520. response = self.client.get(
  1521. self.url,
  1522. data={
  1523. "start": iso_format(self.day_ago),
  1524. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1525. "interval": "1h",
  1526. "yAxis": "count()",
  1527. "orderby": ["-p99()"],
  1528. "field": ["transaction", "avg(transaction.duration)", "p99()"],
  1529. "topEvents": 5,
  1530. },
  1531. format="json",
  1532. )
  1533. data = response.data
  1534. assert response.status_code == 200, response.content
  1535. assert len(data) == 1
  1536. results = data[self.transaction.transaction]
  1537. assert results["order"] == 0
  1538. assert [attrs for time, attrs in results["data"]] == [[{"count": 3}], [{"count": 0}]]
  1539. def test_top_events_with_functions_on_different_transactions(self):
  1540. """Transaction2 has less events, but takes longer so order should be self.transaction then transaction2"""
  1541. transaction_data = load_data("transaction")
  1542. transaction_data["start_timestamp"] = iso_format(self.day_ago + timedelta(minutes=2))
  1543. transaction_data["timestamp"] = iso_format(self.day_ago + timedelta(minutes=6))
  1544. transaction_data["transaction"] = "/foo_bar/"
  1545. transaction2 = self.store_event(transaction_data, project_id=self.project.id)
  1546. with self.feature(self.enabled_features):
  1547. response = self.client.get(
  1548. self.url,
  1549. data={
  1550. "start": iso_format(self.day_ago),
  1551. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1552. "interval": "1h",
  1553. "yAxis": "count()",
  1554. "orderby": ["-p99()"],
  1555. "field": ["transaction", "avg(transaction.duration)", "p99()"],
  1556. "topEvents": 5,
  1557. },
  1558. format="json",
  1559. )
  1560. data = response.data
  1561. assert response.status_code == 200, response.content
  1562. assert len(data) == 2
  1563. results = data[self.transaction.transaction]
  1564. assert results["order"] == 1
  1565. assert [attrs for time, attrs in results["data"]] == [[{"count": 3}], [{"count": 0}]]
  1566. results = data[transaction2.transaction]
  1567. assert results["order"] == 0
  1568. assert [attrs for time, attrs in results["data"]] == [[{"count": 1}], [{"count": 0}]]
  1569. def test_top_events_with_query(self):
  1570. transaction_data = load_data("transaction")
  1571. transaction_data["start_timestamp"] = iso_format(self.day_ago + timedelta(minutes=2))
  1572. transaction_data["timestamp"] = iso_format(self.day_ago + timedelta(minutes=6))
  1573. transaction_data["transaction"] = "/foo_bar/"
  1574. self.store_event(transaction_data, project_id=self.project.id)
  1575. with self.feature(self.enabled_features):
  1576. response = self.client.get(
  1577. self.url,
  1578. data={
  1579. "start": iso_format(self.day_ago),
  1580. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1581. "interval": "1h",
  1582. "yAxis": "count()",
  1583. "orderby": ["-p99()"],
  1584. "query": "transaction:/foo_bar/",
  1585. "field": ["transaction", "avg(transaction.duration)", "p99()"],
  1586. "topEvents": 5,
  1587. },
  1588. format="json",
  1589. )
  1590. data = response.data
  1591. assert response.status_code == 200, response.content
  1592. assert len(data) == 1
  1593. transaction2_data = data["/foo_bar/"]
  1594. assert transaction2_data["order"] == 0
  1595. assert [attrs for time, attrs in transaction2_data["data"]] == [
  1596. [{"count": 1}],
  1597. [{"count": 0}],
  1598. ]
  1599. def test_top_events_with_negated_condition(self):
  1600. with self.feature(self.enabled_features):
  1601. response = self.client.get(
  1602. self.url,
  1603. data={
  1604. "start": iso_format(self.day_ago),
  1605. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1606. "interval": "1h",
  1607. "yAxis": "count()",
  1608. "orderby": ["-count()"],
  1609. "query": f"!message:{self.events[0].message}",
  1610. "field": ["message", "count()"],
  1611. "topEvents": 5,
  1612. },
  1613. format="json",
  1614. )
  1615. data = response.data
  1616. assert response.status_code == 200, response.content
  1617. assert len(data) == 6
  1618. for index, event in enumerate(self.events[1:5]):
  1619. message = event.message or event.transaction
  1620. results = data[message]
  1621. assert results["order"] == index
  1622. assert [{"count": self.event_data[index + 1]["count"]}] in [
  1623. attrs for _, attrs in results["data"]
  1624. ]
  1625. other = data["Other"]
  1626. assert other["order"] == 5
  1627. assert [{"count": 1}] in [attrs for _, attrs in other["data"]]
  1628. def test_top_events_with_epm(self):
  1629. with self.feature(self.enabled_features):
  1630. response = self.client.get(
  1631. self.url,
  1632. data={
  1633. "start": iso_format(self.day_ago),
  1634. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1635. "interval": "1h",
  1636. "yAxis": "epm()",
  1637. "orderby": ["-count()"],
  1638. "field": ["message", "user.email", "count()"],
  1639. "topEvents": 5,
  1640. },
  1641. format="json",
  1642. )
  1643. data = response.data
  1644. assert response.status_code == 200, response.content
  1645. assert len(data) == 6
  1646. for index, event in enumerate(self.events[:5]):
  1647. message = event.message or event.transaction
  1648. results = data[
  1649. ",".join([message, self.event_data[index]["data"]["user"].get("email", "None")])
  1650. ]
  1651. assert results["order"] == index
  1652. assert [{"count": self.event_data[index]["count"] / (3600.0 / 60.0)}] in [
  1653. attrs for time, attrs in results["data"]
  1654. ]
  1655. other = data["Other"]
  1656. assert other["order"] == 5
  1657. assert [{"count": 0.05}] in [attrs for _, attrs in other["data"]]
  1658. def test_top_events_with_multiple_yaxis(self):
  1659. with self.feature(self.enabled_features):
  1660. response = self.client.get(
  1661. self.url,
  1662. data={
  1663. "start": iso_format(self.day_ago),
  1664. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1665. "interval": "1h",
  1666. "yAxis": ["epm()", "count()"],
  1667. "orderby": ["-count()"],
  1668. "field": ["message", "user.email", "count()"],
  1669. "topEvents": 5,
  1670. },
  1671. format="json",
  1672. )
  1673. data = response.data
  1674. assert response.status_code == 200, response.content
  1675. assert len(data) == 6
  1676. for index, event in enumerate(self.events[:5]):
  1677. message = event.message or event.transaction
  1678. results = data[
  1679. ",".join([message, self.event_data[index]["data"]["user"].get("email", "None")])
  1680. ]
  1681. assert results["order"] == index
  1682. assert results["epm()"]["order"] == 0
  1683. assert results["count()"]["order"] == 1
  1684. assert [{"count": self.event_data[index]["count"] / (3600.0 / 60.0)}] in [
  1685. attrs for time, attrs in results["epm()"]["data"]
  1686. ]
  1687. assert [{"count": self.event_data[index]["count"]}] in [
  1688. attrs for time, attrs in results["count()"]["data"]
  1689. ]
  1690. other = data["Other"]
  1691. assert other["order"] == 5
  1692. assert other["epm()"]["order"] == 0
  1693. assert other["count()"]["order"] == 1
  1694. assert [{"count": 0.05}] in [attrs for _, attrs in other["epm()"]["data"]]
  1695. assert [{"count": 3}] in [attrs for _, attrs in other["count()"]["data"]]
  1696. def test_top_events_with_boolean(self):
  1697. with self.feature(self.enabled_features):
  1698. response = self.client.get(
  1699. self.url,
  1700. data={
  1701. "start": iso_format(self.day_ago),
  1702. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1703. "interval": "1h",
  1704. "yAxis": "count()",
  1705. "orderby": ["-count()"],
  1706. "field": ["count()", "message", "device.charging"],
  1707. "topEvents": 5,
  1708. },
  1709. format="json",
  1710. )
  1711. data = response.data
  1712. assert response.status_code == 200, response.content
  1713. assert len(data) == 6
  1714. for index, event in enumerate(self.events[:5]):
  1715. message = event.message or event.transaction
  1716. results = data[",".join(["False", message])]
  1717. assert results["order"] == index
  1718. assert [{"count": self.event_data[index]["count"]}] in [
  1719. attrs for time, attrs in results["data"]
  1720. ]
  1721. other = data["Other"]
  1722. assert other["order"] == 5
  1723. assert [{"count": 3}] in [attrs for _, attrs in other["data"]]
  1724. def test_top_events_with_error_unhandled(self):
  1725. self.login_as(user=self.user)
  1726. project = self.create_project()
  1727. prototype = load_data("android-ndk")
  1728. prototype["event_id"] = "f" * 32
  1729. prototype["message"] = "not handled"
  1730. prototype["exception"]["values"][0]["value"] = "not handled"
  1731. prototype["exception"]["values"][0]["mechanism"]["handled"] = False
  1732. prototype["timestamp"] = iso_format(self.day_ago + timedelta(minutes=2))
  1733. self.store_event(data=prototype, project_id=project.id)
  1734. with self.feature(self.enabled_features):
  1735. response = self.client.get(
  1736. self.url,
  1737. data={
  1738. "start": iso_format(self.day_ago),
  1739. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1740. "interval": "1h",
  1741. "yAxis": "count()",
  1742. "orderby": ["-count()"],
  1743. "field": ["count()", "error.unhandled"],
  1744. "topEvents": 5,
  1745. },
  1746. format="json",
  1747. )
  1748. data = response.data
  1749. assert response.status_code == 200, response.content
  1750. assert len(data) == 2
  1751. def test_top_events_with_timestamp(self):
  1752. with self.feature(self.enabled_features):
  1753. response = self.client.get(
  1754. self.url,
  1755. data={
  1756. "start": iso_format(self.day_ago),
  1757. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1758. "interval": "1h",
  1759. "yAxis": "count()",
  1760. "orderby": ["-count()"],
  1761. "query": "event.type:default",
  1762. "field": ["count()", "message", "timestamp"],
  1763. "topEvents": 5,
  1764. },
  1765. format="json",
  1766. )
  1767. data = response.data
  1768. assert response.status_code == 200, response.content
  1769. assert len(data) == 6
  1770. # Transactions won't be in the results because of the query
  1771. del self.events[4]
  1772. del self.event_data[4]
  1773. for index, event in enumerate(self.events[:5]):
  1774. results = data[",".join([event.message, event.timestamp])]
  1775. assert results["order"] == index
  1776. assert [{"count": self.event_data[index]["count"]}] in [
  1777. attrs for time, attrs in results["data"]
  1778. ]
  1779. other = data["Other"]
  1780. assert other["order"] == 5
  1781. assert [{"count": 1}] in [attrs for _, attrs in other["data"]]
  1782. def test_top_events_with_int(self):
  1783. with self.feature(self.enabled_features):
  1784. response = self.client.get(
  1785. self.url,
  1786. data={
  1787. "start": iso_format(self.day_ago),
  1788. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1789. "interval": "1h",
  1790. "yAxis": "count()",
  1791. "orderby": ["-count()"],
  1792. "field": ["count()", "message", "transaction.duration"],
  1793. "topEvents": 5,
  1794. },
  1795. format="json",
  1796. )
  1797. data = response.data
  1798. assert response.status_code == 200, response.content
  1799. assert len(data) == 1
  1800. results = data[",".join([self.transaction.transaction, "120000"])]
  1801. assert results["order"] == 0
  1802. assert [attrs for time, attrs in results["data"]] == [[{"count": 3}], [{"count": 0}]]
  1803. def test_top_events_with_user(self):
  1804. with self.feature(self.enabled_features):
  1805. response = self.client.get(
  1806. self.url,
  1807. data={
  1808. "start": iso_format(self.day_ago),
  1809. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1810. "interval": "1h",
  1811. "yAxis": "count()",
  1812. "orderby": ["-count()", "user"],
  1813. "field": ["user", "count()"],
  1814. "topEvents": 5,
  1815. },
  1816. format="json",
  1817. )
  1818. data = response.data
  1819. assert response.status_code == 200, response.content
  1820. assert len(data) == 5
  1821. assert data["email:bar@example.com"]["order"] == 1
  1822. assert [attrs for time, attrs in data["email:bar@example.com"]["data"]] == [
  1823. [{"count": 7}],
  1824. [{"count": 0}],
  1825. ]
  1826. assert [attrs for time, attrs in data["ip:127.0.0.1"]["data"]] == [
  1827. [{"count": 3}],
  1828. [{"count": 0}],
  1829. ]
  1830. def test_top_events_with_user_and_email(self):
  1831. with self.feature(self.enabled_features):
  1832. response = self.client.get(
  1833. self.url,
  1834. data={
  1835. "start": iso_format(self.day_ago),
  1836. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1837. "interval": "1h",
  1838. "yAxis": "count()",
  1839. "orderby": ["-count()", "user"],
  1840. "field": ["user", "user.email", "count()"],
  1841. "topEvents": 5,
  1842. },
  1843. format="json",
  1844. )
  1845. data = response.data
  1846. assert response.status_code == 200, response.content
  1847. assert len(data) == 5
  1848. assert data["email:bar@example.com,bar@example.com"]["order"] == 1
  1849. assert [attrs for time, attrs in data["email:bar@example.com,bar@example.com"]["data"]] == [
  1850. [{"count": 7}],
  1851. [{"count": 0}],
  1852. ]
  1853. assert [attrs for time, attrs in data["ip:127.0.0.1,None"]["data"]] == [
  1854. [{"count": 3}],
  1855. [{"count": 0}],
  1856. ]
  1857. def test_top_events_with_user_display(self):
  1858. with self.feature(self.enabled_features):
  1859. response = self.client.get(
  1860. self.url,
  1861. data={
  1862. "start": iso_format(self.day_ago),
  1863. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1864. "interval": "1h",
  1865. "yAxis": "count()",
  1866. "orderby": ["-count()"],
  1867. "field": ["message", "user.display", "count()"],
  1868. "topEvents": 5,
  1869. },
  1870. format="json",
  1871. )
  1872. data = response.data
  1873. assert response.status_code == 200, response.content
  1874. assert len(data) == 6
  1875. for index, event in enumerate(self.events[:5]):
  1876. message = event.message or event.transaction
  1877. user = self.event_data[index]["data"]["user"]
  1878. results = data[
  1879. ",".join([message, user.get("email", None) or user.get("ip_address", "None")])
  1880. ]
  1881. assert results["order"] == index
  1882. assert [{"count": self.event_data[index]["count"]}] in [
  1883. attrs for _, attrs in results["data"]
  1884. ]
  1885. other = data["Other"]
  1886. assert other["order"] == 5
  1887. assert [{"count": 3}] in [attrs for _, attrs in other["data"]]
  1888. @pytest.mark.skip(reason="A query with group_id will not return transactions")
  1889. def test_top_events_none_filter(self):
  1890. """When a field is None in one of the top events, make sure we filter by it
  1891. In this case event[4] is a transaction and has no issue
  1892. """
  1893. with self.feature(self.enabled_features):
  1894. response = self.client.get(
  1895. self.url,
  1896. data={
  1897. "start": iso_format(self.day_ago),
  1898. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1899. "interval": "1h",
  1900. "yAxis": "count()",
  1901. "orderby": ["-count()"],
  1902. "field": ["count()", "issue"],
  1903. "topEvents": 5,
  1904. },
  1905. format="json",
  1906. )
  1907. data = response.data
  1908. assert response.status_code == 200, response.content
  1909. assert len(data) == 5
  1910. for index, event in enumerate(self.events[:5]):
  1911. if event.group is None:
  1912. issue = "unknown"
  1913. else:
  1914. issue = event.group.qualified_short_id
  1915. results = data[issue]
  1916. assert results["order"] == index
  1917. assert [{"count": self.event_data[index]["count"]}] in [
  1918. attrs for time, attrs in results["data"]
  1919. ]
  1920. @pytest.mark.skip(reason="Invalid query - transaction events don't have group_id field")
  1921. def test_top_events_one_field_with_none(self):
  1922. with self.feature(self.enabled_features):
  1923. response = self.client.get(
  1924. self.url,
  1925. data={
  1926. "start": iso_format(self.day_ago),
  1927. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1928. "interval": "1h",
  1929. "yAxis": "count()",
  1930. "orderby": ["-count()"],
  1931. "query": "event.type:transaction",
  1932. "field": ["count()", "issue"],
  1933. "topEvents": 5,
  1934. },
  1935. format="json",
  1936. )
  1937. data = response.data
  1938. assert response.status_code == 200, response.content
  1939. assert len(data) == 1
  1940. results = data["unknown"]
  1941. assert [attrs for time, attrs in results["data"]] == [[{"count": 3}], [{"count": 0}]]
  1942. assert results["order"] == 0
  1943. def test_top_events_with_error_handled(self):
  1944. data = self.event_data[0]
  1945. data["data"]["level"] = "error"
  1946. data["data"]["exception"] = {
  1947. "values": [
  1948. {
  1949. "type": "ValidationError",
  1950. "value": "Bad request",
  1951. "mechanism": {"handled": True, "type": "generic"},
  1952. }
  1953. ]
  1954. }
  1955. self.store_event(data["data"], project_id=data["project"].id)
  1956. data["data"]["exception"] = {
  1957. "values": [
  1958. {
  1959. "type": "ValidationError",
  1960. "value": "Bad request",
  1961. "mechanism": {"handled": False, "type": "generic"},
  1962. }
  1963. ]
  1964. }
  1965. self.store_event(data["data"], project_id=data["project"].id)
  1966. with self.feature(self.enabled_features):
  1967. response = self.client.get(
  1968. self.url,
  1969. data={
  1970. "start": iso_format(self.day_ago),
  1971. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1972. "interval": "1h",
  1973. "yAxis": "count()",
  1974. "orderby": ["-count()"],
  1975. "field": ["count()", "error.handled"],
  1976. "topEvents": 5,
  1977. "query": "!event.type:transaction",
  1978. },
  1979. format="json",
  1980. )
  1981. assert response.status_code == 200, response.content
  1982. data = response.data
  1983. assert len(data) == 2
  1984. results = data["1"]
  1985. assert [attrs for time, attrs in results["data"]] == [[{"count": 20}], [{"count": 6}]]
  1986. results = data["0"]
  1987. assert [attrs for time, attrs in results["data"]] == [[{"count": 1}], [{"count": 0}]]
  1988. def test_top_events_with_aggregate_condition(self):
  1989. with self.feature(self.enabled_features):
  1990. response = self.client.get(
  1991. self.url,
  1992. data={
  1993. "start": iso_format(self.day_ago),
  1994. "end": iso_format(self.day_ago + timedelta(hours=2)),
  1995. "interval": "1h",
  1996. "yAxis": "count()",
  1997. "orderby": ["-count()"],
  1998. "field": ["message", "count()"],
  1999. "query": "count():>4",
  2000. "topEvents": 5,
  2001. },
  2002. format="json",
  2003. )
  2004. assert response.status_code == 200, response.content
  2005. data = response.data
  2006. assert len(data) == 3
  2007. for index, event in enumerate(self.events[:3]):
  2008. message = event.message or event.transaction
  2009. results = data[message]
  2010. assert results["order"] == index
  2011. assert [{"count": self.event_data[index]["count"]}] in [
  2012. attrs for time, attrs in results["data"]
  2013. ]
  2014. @pytest.mark.xfail(reason="There's only 2 rows total, which mean there shouldn't be other")
  2015. def test_top_events_with_to_other(self):
  2016. version = "version -@'\" 1.2,3+(4)"
  2017. version_escaped = "version -@'\\\" 1.2,3+(4)"
  2018. # every symbol is replaced with a underscore to make the alias
  2019. version_alias = "version_______1_2_3__4_"
  2020. # add an event in the current release
  2021. event = self.event_data[0]
  2022. event_data = event["data"].copy()
  2023. event_data["event_id"] = uuid4().hex
  2024. event_data["release"] = version
  2025. self.store_event(event_data, project_id=event["project"].id)
  2026. with self.feature(self.enabled_features):
  2027. response = self.client.get(
  2028. self.url,
  2029. data={
  2030. "start": iso_format(self.day_ago),
  2031. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2032. "interval": "1h",
  2033. "yAxis": "count()",
  2034. # the double underscores around the version alias is because of a comma and quote
  2035. "orderby": [f"-to_other_release__{version_alias}__others_current"],
  2036. "field": [
  2037. "count()",
  2038. f'to_other(release,"{version_escaped}",others,current)',
  2039. ],
  2040. "topEvents": 2,
  2041. },
  2042. format="json",
  2043. )
  2044. assert response.status_code == 200, response.content
  2045. data = response.data
  2046. assert len(data) == 2
  2047. current = data["current"]
  2048. assert current["order"] == 1
  2049. assert sum(attrs[0]["count"] for _, attrs in current["data"]) == 1
  2050. others = data["others"]
  2051. assert others["order"] == 0
  2052. assert sum(attrs[0]["count"] for _, attrs in others["data"]) == sum(
  2053. event_data["count"] for event_data in self.event_data
  2054. )
  2055. def test_top_events_with_equations(self):
  2056. with self.feature(self.enabled_features):
  2057. response = self.client.get(
  2058. self.url,
  2059. data={
  2060. "start": iso_format(self.day_ago),
  2061. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2062. "interval": "1h",
  2063. "yAxis": "equation|count() / 100",
  2064. "orderby": ["-count()"],
  2065. "field": ["count()", "message", "user.email", "equation|count() / 100"],
  2066. "topEvents": 5,
  2067. },
  2068. format="json",
  2069. )
  2070. data = response.data
  2071. assert response.status_code == 200, response.content
  2072. assert len(data) == 6
  2073. for index, event in enumerate(self.events[:5]):
  2074. message = event.message or event.transaction
  2075. results = data[
  2076. ",".join([message, self.event_data[index]["data"]["user"].get("email", "None")])
  2077. ]
  2078. assert results["order"] == index
  2079. assert [{"count": self.event_data[index]["count"] / 100}] in [
  2080. attrs for time, attrs in results["data"]
  2081. ]
  2082. other = data["Other"]
  2083. assert other["order"] == 5
  2084. assert [{"count": 0.03}] in [attrs for _, attrs in other["data"]]
  2085. @mock.patch("sentry.snuba.discover.bulk_snql_query", return_value=[{"data": [], "meta": []}])
  2086. @mock.patch(
  2087. "sentry.search.events.builder.discover.raw_snql_query",
  2088. return_value={"data": [], "meta": []},
  2089. )
  2090. def test_invalid_interval(self, mock_raw_query, mock_bulk_query):
  2091. with self.feature(self.enabled_features):
  2092. response = self.client.get(
  2093. self.url,
  2094. format="json",
  2095. data={
  2096. "end": iso_format(before_now()),
  2097. # 7,200 points for each event
  2098. "start": iso_format(before_now(seconds=7200)),
  2099. "field": ["count()", "issue"],
  2100. "query": "",
  2101. "interval": "1s",
  2102. "yAxis": "count()",
  2103. },
  2104. )
  2105. assert response.status_code == 200
  2106. assert mock_bulk_query.call_count == 1
  2107. with self.feature(self.enabled_features):
  2108. response = self.client.get(
  2109. self.url,
  2110. format="json",
  2111. data={
  2112. "end": iso_format(before_now()),
  2113. "start": iso_format(before_now(seconds=7200)),
  2114. "field": ["count()", "issue"],
  2115. "query": "",
  2116. "interval": "1s",
  2117. "yAxis": "count()",
  2118. # 7,200 points for each event * 2, should error
  2119. "topEvents": 2,
  2120. },
  2121. )
  2122. assert response.status_code == 200
  2123. assert mock_raw_query.call_count == 2
  2124. # Should've reset to the default for between 1 and 24h
  2125. assert mock_raw_query.mock_calls[1].args[0].query.granularity.granularity == 300
  2126. with self.feature(self.enabled_features):
  2127. response = self.client.get(
  2128. self.url,
  2129. format="json",
  2130. data={
  2131. "end": iso_format(before_now()),
  2132. # 1999 points * 5 events should just be enough to not error
  2133. "start": iso_format(before_now(seconds=1999)),
  2134. "field": ["count()", "issue"],
  2135. "query": "",
  2136. "interval": "1s",
  2137. "yAxis": "count()",
  2138. "topEvents": 5,
  2139. },
  2140. )
  2141. assert response.status_code == 200
  2142. assert mock_raw_query.call_count == 4
  2143. # Should've left the interval alone since we're just below the limit
  2144. assert mock_raw_query.mock_calls[3].args[0].query.granularity.granularity == 1
  2145. with self.feature(self.enabled_features):
  2146. response = self.client.get(
  2147. self.url,
  2148. format="json",
  2149. data={
  2150. "end": iso_format(before_now()),
  2151. "start": iso_format(before_now(hours=24)),
  2152. "field": ["count()", "issue"],
  2153. "query": "",
  2154. "interval": "0d",
  2155. "yAxis": "count()",
  2156. "topEvents": 5,
  2157. },
  2158. )
  2159. assert response.status_code == 200
  2160. assert mock_raw_query.call_count == 6
  2161. # Should've default to 24h's default of 5m
  2162. assert mock_raw_query.mock_calls[5].args[0].query.granularity.granularity == 300
  2163. def test_top_events_timestamp_fields(self):
  2164. with self.feature(self.enabled_features):
  2165. response = self.client.get(
  2166. self.url,
  2167. format="json",
  2168. data={
  2169. "start": iso_format(self.day_ago),
  2170. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2171. "interval": "1h",
  2172. "yAxis": "count()",
  2173. "orderby": ["-count()"],
  2174. "field": ["count()", "timestamp", "timestamp.to_hour", "timestamp.to_day"],
  2175. "topEvents": 5,
  2176. },
  2177. )
  2178. assert response.status_code == 200
  2179. data = response.data
  2180. assert len(data) == 3
  2181. # these are the timestamps corresponding to the events stored
  2182. timestamps = [
  2183. self.day_ago + timedelta(minutes=2),
  2184. self.day_ago + timedelta(hours=1, minutes=2),
  2185. self.day_ago + timedelta(minutes=4),
  2186. ]
  2187. timestamp_hours = [timestamp.replace(minute=0, second=0) for timestamp in timestamps]
  2188. timestamp_days = [timestamp.replace(hour=0, minute=0, second=0) for timestamp in timestamps]
  2189. for ts, ts_hr, ts_day in zip(timestamps, timestamp_hours, timestamp_days):
  2190. key = f"{iso_format(ts)}+00:00,{iso_format(ts_day)}+00:00,{iso_format(ts_hr)}+00:00"
  2191. count = sum(
  2192. e["count"] for e in self.event_data if e["data"]["timestamp"] == iso_format(ts)
  2193. )
  2194. results = data[key]
  2195. assert [{"count": count}] in [attrs for time, attrs in results["data"]]
  2196. def test_top_events_other_with_matching_columns(self):
  2197. with self.feature(self.enabled_features):
  2198. response = self.client.get(
  2199. self.url,
  2200. data={
  2201. "start": iso_format(self.day_ago),
  2202. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2203. "interval": "1h",
  2204. "yAxis": "count()",
  2205. "orderby": ["-count()"],
  2206. "field": ["count()", "tags[shared-tag]", "message"],
  2207. "topEvents": 5,
  2208. },
  2209. format="json",
  2210. )
  2211. data = response.data
  2212. assert response.status_code == 200, response.content
  2213. assert len(data) == 6
  2214. for index, event in enumerate(self.events[:5]):
  2215. message = event.message or event.transaction
  2216. results = data[",".join([message, "yup"])]
  2217. assert results["order"] == index
  2218. assert [{"count": self.event_data[index]["count"]}] in [
  2219. attrs for _, attrs in results["data"]
  2220. ]
  2221. other = data["Other"]
  2222. assert other["order"] == 5
  2223. assert [{"count": 3}] in [attrs for _, attrs in other["data"]]
  2224. def test_top_events_with_field_overlapping_other_key(self):
  2225. transaction_data = load_data("transaction")
  2226. transaction_data["start_timestamp"] = iso_format(self.day_ago + timedelta(minutes=2))
  2227. transaction_data["timestamp"] = iso_format(self.day_ago + timedelta(minutes=6))
  2228. transaction_data["transaction"] = OTHER_KEY
  2229. for i in range(5):
  2230. data = transaction_data.copy()
  2231. data["event_id"] = "ab" + f"{i}" * 30
  2232. data["contexts"]["trace"]["span_id"] = "ab" + f"{i}" * 14
  2233. self.store_event(data, project_id=self.project.id)
  2234. with self.feature(self.enabled_features):
  2235. response = self.client.get(
  2236. self.url,
  2237. data={
  2238. "start": iso_format(self.day_ago),
  2239. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2240. "interval": "1h",
  2241. "yAxis": "count()",
  2242. "orderby": ["-count()"],
  2243. "field": ["count()", "message"],
  2244. "topEvents": 5,
  2245. },
  2246. format="json",
  2247. )
  2248. data = response.data
  2249. assert response.status_code == 200, response.content
  2250. assert len(data) == 6
  2251. assert f"{OTHER_KEY} (message)" in data
  2252. results = data[f"{OTHER_KEY} (message)"]
  2253. assert [{"count": 5}] in [attrs for _, attrs in results["data"]]
  2254. other = data["Other"]
  2255. assert other["order"] == 5
  2256. assert [{"count": 4}] in [attrs for _, attrs in other["data"]]
  2257. def test_top_events_can_exclude_other_series(self):
  2258. with self.feature(self.enabled_features):
  2259. response = self.client.get(
  2260. self.url,
  2261. data={
  2262. "start": iso_format(self.day_ago),
  2263. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2264. "interval": "1h",
  2265. "yAxis": "count()",
  2266. "orderby": ["count()"],
  2267. "field": ["count()", "message"],
  2268. "topEvents": 5,
  2269. "excludeOther": "1",
  2270. },
  2271. format="json",
  2272. )
  2273. data = response.data
  2274. assert response.status_code == 200, response.content
  2275. assert len(data) == 5
  2276. assert "Other" not in response.data
  2277. def test_top_events_with_equation_including_unselected_fields_passes_field_validation(self):
  2278. with self.feature(self.enabled_features):
  2279. response = self.client.get(
  2280. self.url,
  2281. data={
  2282. "start": iso_format(self.day_ago),
  2283. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2284. "interval": "1h",
  2285. "yAxis": "count()",
  2286. "orderby": ["-equation[0]"],
  2287. "field": ["count()", "message", "equation|count_unique(user) * 2"],
  2288. "topEvents": 5,
  2289. },
  2290. format="json",
  2291. )
  2292. data = response.data
  2293. assert response.status_code == 200, response.content
  2294. assert len(data) == 6
  2295. other = data["Other"]
  2296. assert other["order"] == 5
  2297. assert [{"count": 4}] in [attrs for _, attrs in other["data"]]
  2298. def test_top_events_boolean_condition_and_project_field(self):
  2299. with self.feature(self.enabled_features):
  2300. response = self.client.get(
  2301. self.url,
  2302. data={
  2303. "start": iso_format(self.day_ago),
  2304. "end": iso_format(self.day_ago + timedelta(hours=2)),
  2305. "interval": "1h",
  2306. "yAxis": "count()",
  2307. "orderby": ["-count()"],
  2308. "field": ["project", "count()"],
  2309. "topEvents": 5,
  2310. "query": "event.type:transaction (transaction:*a OR transaction:b*)",
  2311. },
  2312. format="json",
  2313. )
  2314. assert response.status_code == 200