test_organization_events_mep.py 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697
  1. from __future__ import annotations
  2. from typing import Any
  3. from unittest import mock
  4. import pytest
  5. from django.urls import reverse
  6. from sentry.api.bases.organization_events import DATASET_OPTIONS
  7. from sentry.discover.models import TeamKeyTransaction
  8. from sentry.models.projectteam import ProjectTeam
  9. from sentry.models.transaction_threshold import (
  10. ProjectTransactionThreshold,
  11. ProjectTransactionThresholdOverride,
  12. TransactionMetric,
  13. )
  14. from sentry.search.events import constants
  15. from sentry.search.utils import map_device_class_level
  16. from sentry.snuba.metrics.extraction import MetricSpecType, OnDemandMetricSpec
  17. from sentry.snuba.metrics.naming_layer.mri import TransactionMRI
  18. from sentry.snuba.metrics.naming_layer.public import TransactionMetricKey
  19. from sentry.testutils.cases import MetricsEnhancedPerformanceTestCase
  20. from sentry.testutils.helpers.datetime import before_now, iso_format
  21. from sentry.testutils.silo import region_silo_test
  22. from sentry.utils.samples import load_data
  23. pytestmark = pytest.mark.sentry_metrics
  24. @region_silo_test
  25. class OrganizationEventsMetricsEnhancedPerformanceEndpointTest(MetricsEnhancedPerformanceTestCase):
  26. viewname = "sentry-api-0-organization-events"
  27. # Poor intentionally omitted for test_measurement_rating_that_does_not_exist
  28. METRIC_STRINGS = [
  29. "foo_transaction",
  30. "bar_transaction",
  31. "baz_transaction",
  32. "staging",
  33. "measurement_rating",
  34. "good",
  35. "meh",
  36. "d:transactions/measurements.something_custom@millisecond",
  37. "d:transactions/measurements.runtime@hour",
  38. "d:transactions/measurements.bytes_transfered@byte",
  39. "d:transactions/measurements.datacenter_memory@petabyte",
  40. "d:transactions/measurements.custom.kilobyte@kilobyte",
  41. "d:transactions/measurements.longtaskcount@none",
  42. "d:transactions/measurements.percent@ratio",
  43. "d:transactions/measurements.custom_type@somethingcustom",
  44. ]
  45. def setUp(self):
  46. super().setUp()
  47. self.min_ago = before_now(minutes=1)
  48. self.two_min_ago = before_now(minutes=2)
  49. self.transaction_data = load_data("transaction", timestamp=before_now(minutes=1))
  50. self.features = {
  51. "organizations:performance-use-metrics": True,
  52. }
  53. def do_request(self, query, features=None):
  54. if features is None:
  55. features = {"organizations:discover-basic": True}
  56. features.update(self.features)
  57. self.login_as(user=self.user)
  58. url = reverse(
  59. self.viewname,
  60. kwargs={"organization_slug": self.organization.slug},
  61. )
  62. with self.feature(features):
  63. return self.client.get(url, query, format="json")
  64. def test_no_projects(self):
  65. response = self.do_request(
  66. {
  67. "dataset": "metricsEnhanced",
  68. }
  69. )
  70. assert response.status_code == 200, response.content
  71. def test_invalid_dataset(self):
  72. response = self.do_request(
  73. {
  74. "dataset": "aFakeDataset",
  75. "project": self.project.id,
  76. }
  77. )
  78. assert response.status_code == 400, response.content
  79. assert (
  80. response.data["detail"]
  81. == f"dataset must be one of: {', '.join([key for key in DATASET_OPTIONS.keys()])}"
  82. )
  83. def test_out_of_retention(self):
  84. self.create_project()
  85. with self.options({"system.event-retention-days": 10}):
  86. query = {
  87. "field": ["id", "timestamp"],
  88. "orderby": ["-timestamp", "-id"],
  89. "query": "event.type:transaction",
  90. "start": iso_format(before_now(days=20)),
  91. "end": iso_format(before_now(days=15)),
  92. "dataset": "metricsEnhanced",
  93. }
  94. response = self.do_request(query)
  95. assert response.status_code == 400, response.content
  96. assert response.data["detail"] == "Invalid date range. Please try a more recent date range."
  97. def test_invalid_search_terms(self):
  98. response = self.do_request(
  99. {
  100. "field": ["epm()"],
  101. "query": "hi \n there",
  102. "project": self.project.id,
  103. "dataset": "metricsEnhanced",
  104. }
  105. )
  106. assert response.status_code == 400, response.content
  107. assert (
  108. response.data["detail"]
  109. == "Parse error at 'hi \n ther' (column 4). This is commonly caused by unmatched parentheses. Enclose any text in double quotes."
  110. )
  111. def test_percentile_with_no_data(self):
  112. response = self.do_request(
  113. {
  114. "field": ["p50()"],
  115. "query": "",
  116. "project": self.project.id,
  117. "dataset": "metricsEnhanced",
  118. }
  119. )
  120. assert response.status_code == 200, response.content
  121. data = response.data["data"]
  122. assert len(data) == 1
  123. assert data[0]["p50()"] == 0
  124. def test_project_name(self):
  125. self.store_transaction_metric(
  126. 1,
  127. tags={"environment": "staging"},
  128. timestamp=self.min_ago,
  129. )
  130. response = self.do_request(
  131. {
  132. "field": ["project.name", "environment", "epm()"],
  133. "query": "event.type:transaction",
  134. "dataset": "metricsEnhanced",
  135. "per_page": 50,
  136. }
  137. )
  138. assert response.status_code == 200, response.content
  139. assert len(response.data["data"]) == 1
  140. data = response.data["data"]
  141. meta = response.data["meta"]
  142. field_meta = meta["fields"]
  143. assert data[0]["project.name"] == self.project.slug
  144. assert "project.id" not in data[0]
  145. assert data[0]["environment"] == "staging"
  146. assert meta["isMetricsData"]
  147. assert field_meta["project.name"] == "string"
  148. assert field_meta["environment"] == "string"
  149. assert field_meta["epm()"] == "rate"
  150. def test_project_id(self):
  151. self.store_transaction_metric(
  152. 1,
  153. tags={"environment": "staging"},
  154. timestamp=self.min_ago,
  155. )
  156. response = self.do_request(
  157. {
  158. "field": ["project_id", "environment", "epm()"],
  159. "query": "event.type:transaction",
  160. "dataset": "metrics",
  161. "per_page": 50,
  162. }
  163. )
  164. assert response.status_code == 200, response.content
  165. assert len(response.data["data"]) == 1
  166. data = response.data["data"]
  167. meta = response.data["meta"]
  168. field_meta = meta["fields"]
  169. assert data[0]["project_id"] == self.project.id
  170. assert data[0]["environment"] == "staging"
  171. assert meta["isMetricsData"]
  172. assert field_meta["project_id"] == "integer"
  173. assert field_meta["environment"] == "string"
  174. assert field_meta["epm()"] == "rate"
  175. def test_project_dot_id(self):
  176. self.store_transaction_metric(
  177. 1,
  178. tags={"environment": "staging"},
  179. timestamp=self.min_ago,
  180. )
  181. response = self.do_request(
  182. {
  183. "field": ["project.id", "environment", "epm()"],
  184. "query": "event.type:transaction",
  185. "dataset": "metrics",
  186. "per_page": 50,
  187. }
  188. )
  189. assert response.status_code == 200, response.content
  190. assert len(response.data["data"]) == 1
  191. data = response.data["data"]
  192. meta = response.data["meta"]
  193. field_meta = meta["fields"]
  194. assert data[0]["project.id"] == self.project.id
  195. assert data[0]["environment"] == "staging"
  196. assert meta["isMetricsData"]
  197. assert field_meta["project.id"] == "integer"
  198. assert field_meta["environment"] == "string"
  199. assert field_meta["epm()"] == "rate"
  200. def test_title_alias(self):
  201. """title is an alias to transaction name"""
  202. self.store_transaction_metric(
  203. 1,
  204. tags={"transaction": "foo_transaction"},
  205. timestamp=self.min_ago,
  206. )
  207. response = self.do_request(
  208. {
  209. "field": ["title", "p50()"],
  210. "query": "event.type:transaction",
  211. "dataset": "metricsEnhanced",
  212. "per_page": 50,
  213. }
  214. )
  215. assert response.status_code == 200, response.content
  216. assert len(response.data["data"]) == 1
  217. data = response.data["data"]
  218. meta = response.data["meta"]
  219. field_meta = meta["fields"]
  220. assert data[0]["title"] == "foo_transaction"
  221. assert data[0]["p50()"] == 1
  222. assert meta["isMetricsData"]
  223. assert field_meta["title"] == "string"
  224. assert field_meta["p50()"] == "duration"
  225. def test_having_condition(self):
  226. self.store_transaction_metric(
  227. 1,
  228. tags={"environment": "staging", "transaction": "foo_transaction"},
  229. timestamp=self.min_ago,
  230. )
  231. self.store_transaction_metric(
  232. # shouldn't show up
  233. 100,
  234. tags={"environment": "staging", "transaction": "bar_transaction"},
  235. timestamp=self.min_ago,
  236. )
  237. response = self.do_request(
  238. {
  239. "field": ["transaction", "project", "p50(transaction.duration)"],
  240. "query": "event.type:transaction p50(transaction.duration):<50",
  241. "dataset": "metricsEnhanced",
  242. "per_page": 50,
  243. }
  244. )
  245. assert response.status_code == 200, response.content
  246. assert len(response.data["data"]) == 1
  247. data = response.data["data"]
  248. meta = response.data["meta"]
  249. field_meta = meta["fields"]
  250. assert data[0]["transaction"] == "foo_transaction"
  251. assert data[0]["project"] == self.project.slug
  252. assert data[0]["p50(transaction.duration)"] == 1
  253. assert meta["isMetricsData"]
  254. assert field_meta["transaction"] == "string"
  255. assert field_meta["project"] == "string"
  256. assert field_meta["p50(transaction.duration)"] == "duration"
  257. def test_having_condition_with_preventing_aggregates(self):
  258. self.store_transaction_metric(
  259. 1,
  260. tags={"environment": "staging", "transaction": "foo_transaction"},
  261. timestamp=self.min_ago,
  262. )
  263. self.store_transaction_metric(
  264. 100,
  265. tags={"environment": "staging", "transaction": "bar_transaction"},
  266. timestamp=self.min_ago,
  267. )
  268. response = self.do_request(
  269. {
  270. "field": ["transaction", "project", "p50(transaction.duration)"],
  271. "query": "event.type:transaction p50(transaction.duration):<50",
  272. "dataset": "metricsEnhanced",
  273. "preventMetricAggregates": "1",
  274. "per_page": 50,
  275. }
  276. )
  277. assert response.status_code == 200, response.content
  278. assert len(response.data["data"]) == 0
  279. meta = response.data["meta"]
  280. field_meta = meta["fields"]
  281. assert not meta["isMetricsData"]
  282. assert field_meta["transaction"] == "string"
  283. assert field_meta["project"] == "string"
  284. assert field_meta["p50(transaction.duration)"] == "duration"
  285. def test_having_condition_with_preventing_aggregate_metrics_only(self):
  286. """same as the previous test, but with the dataset on explicit metrics
  287. which should throw a 400 error instead"""
  288. response = self.do_request(
  289. {
  290. "field": ["transaction", "project", "p50(transaction.duration)"],
  291. "query": "event.type:transaction p50(transaction.duration):<50",
  292. "dataset": "metrics",
  293. "preventMetricAggregates": "1",
  294. "per_page": 50,
  295. "project": self.project.id,
  296. }
  297. )
  298. assert response.status_code == 400, response.content
  299. def test_having_condition_not_selected(self):
  300. self.store_transaction_metric(
  301. 1,
  302. tags={"environment": "staging", "transaction": "foo_transaction"},
  303. timestamp=self.min_ago,
  304. )
  305. self.store_transaction_metric(
  306. # shouldn't show up
  307. 100,
  308. tags={"environment": "staging", "transaction": "bar_transaction"},
  309. timestamp=self.min_ago,
  310. )
  311. response = self.do_request(
  312. {
  313. "field": ["transaction", "project", "p50(transaction.duration)"],
  314. "query": "event.type:transaction p75(transaction.duration):<50",
  315. "dataset": "metricsEnhanced",
  316. "per_page": 50,
  317. }
  318. )
  319. assert response.status_code == 200, response.content
  320. assert len(response.data["data"]) == 1
  321. data = response.data["data"]
  322. meta = response.data["meta"]
  323. field_meta = meta["fields"]
  324. assert data[0]["transaction"] == "foo_transaction"
  325. assert data[0]["project"] == self.project.slug
  326. assert data[0]["p50(transaction.duration)"] == 1
  327. assert meta["isMetricsData"]
  328. assert field_meta["transaction"] == "string"
  329. assert field_meta["project"] == "string"
  330. assert field_meta["p50(transaction.duration)"] == "duration"
  331. def test_non_metrics_tag_with_implicit_format(self):
  332. self.store_transaction_metric(
  333. 1,
  334. tags={"environment": "staging", "transaction": "foo_transaction"},
  335. timestamp=self.min_ago,
  336. )
  337. response = self.do_request(
  338. {
  339. "field": ["test", "p50(transaction.duration)"],
  340. "query": "event.type:transaction",
  341. "dataset": "metricsEnhanced",
  342. "per_page": 50,
  343. }
  344. )
  345. assert response.status_code == 200, response.content
  346. assert len(response.data["data"]) == 0
  347. assert not response.data["meta"]["isMetricsData"]
  348. def test_non_metrics_tag_with_implicit_format_metrics_dataset(self):
  349. self.store_transaction_metric(
  350. 1,
  351. tags={"environment": "staging", "transaction": "foo_transaction"},
  352. timestamp=self.min_ago,
  353. )
  354. response = self.do_request(
  355. {
  356. "field": ["test", "p50(transaction.duration)"],
  357. "query": "event.type:transaction",
  358. "dataset": "metrics",
  359. "per_page": 50,
  360. }
  361. )
  362. assert response.status_code == 400, response.content
  363. def test_performance_homepage_query(self):
  364. self.store_transaction_metric(
  365. 1,
  366. tags={
  367. "transaction": "foo_transaction",
  368. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
  369. },
  370. timestamp=self.min_ago,
  371. )
  372. self.store_transaction_metric(
  373. 1,
  374. "measurements.fcp",
  375. tags={"transaction": "foo_transaction"},
  376. timestamp=self.min_ago,
  377. )
  378. self.store_transaction_metric(
  379. 2,
  380. "measurements.lcp",
  381. tags={"transaction": "foo_transaction"},
  382. timestamp=self.min_ago,
  383. )
  384. self.store_transaction_metric(
  385. 3,
  386. "measurements.fid",
  387. tags={"transaction": "foo_transaction"},
  388. timestamp=self.min_ago,
  389. )
  390. self.store_transaction_metric(
  391. 4,
  392. "measurements.cls",
  393. tags={"transaction": "foo_transaction"},
  394. timestamp=self.min_ago,
  395. )
  396. self.store_transaction_metric(
  397. 1,
  398. "user",
  399. tags={
  400. "transaction": "foo_transaction",
  401. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_FRUSTRATED_TAG_VALUE,
  402. },
  403. timestamp=self.min_ago,
  404. )
  405. for dataset in ["metrics", "metricsEnhanced"]:
  406. response = self.do_request(
  407. {
  408. "field": [
  409. "transaction",
  410. "project",
  411. "tpm()",
  412. "p75(measurements.fcp)",
  413. "p75(measurements.lcp)",
  414. "p75(measurements.fid)",
  415. "p75(measurements.cls)",
  416. "count_unique(user)",
  417. "apdex()",
  418. "count_miserable(user)",
  419. "user_misery()",
  420. "failure_rate()",
  421. "failure_count()",
  422. ],
  423. "orderby": "tpm()",
  424. "query": "event.type:transaction",
  425. "dataset": dataset,
  426. "per_page": 50,
  427. }
  428. )
  429. assert len(response.data["data"]) == 1
  430. data = response.data["data"][0]
  431. meta = response.data["meta"]
  432. field_meta = meta["fields"]
  433. assert data["transaction"] == "foo_transaction"
  434. assert data["project"] == self.project.slug
  435. assert data["p75(measurements.fcp)"] == 1.0
  436. assert data["p75(measurements.lcp)"] == 2.0
  437. assert data["p75(measurements.fid)"] == 3.0
  438. assert data["p75(measurements.cls)"] == 4.0
  439. assert data["apdex()"] == 1.0
  440. assert data["count_miserable(user)"] == 1.0
  441. assert data["user_misery()"] == 0.058
  442. assert data["failure_rate()"] == 1
  443. assert data["failure_count()"] == 1
  444. assert meta["isMetricsData"]
  445. assert field_meta["transaction"] == "string"
  446. assert field_meta["project"] == "string"
  447. assert field_meta["p75(measurements.fcp)"] == "duration"
  448. assert field_meta["p75(measurements.lcp)"] == "duration"
  449. assert field_meta["p75(measurements.fid)"] == "duration"
  450. assert field_meta["p75(measurements.cls)"] == "number"
  451. assert field_meta["apdex()"] == "number"
  452. assert field_meta["count_miserable(user)"] == "integer"
  453. assert field_meta["user_misery()"] == "number"
  454. assert field_meta["failure_rate()"] == "percentage"
  455. assert field_meta["failure_count()"] == "integer"
  456. assert field_meta["tpm()"] == "rate"
  457. assert meta["units"]["tpm()"] == "1/minute"
  458. def test_user_misery_and_team_key_sort(self):
  459. self.store_transaction_metric(
  460. 1,
  461. tags={
  462. "transaction": "foo_transaction",
  463. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
  464. },
  465. timestamp=self.min_ago,
  466. )
  467. self.store_transaction_metric(
  468. 1,
  469. "measurements.fcp",
  470. tags={"transaction": "foo_transaction"},
  471. timestamp=self.min_ago,
  472. )
  473. self.store_transaction_metric(
  474. 2,
  475. "measurements.lcp",
  476. tags={"transaction": "foo_transaction"},
  477. timestamp=self.min_ago,
  478. )
  479. self.store_transaction_metric(
  480. 3,
  481. "measurements.fid",
  482. tags={"transaction": "foo_transaction"},
  483. timestamp=self.min_ago,
  484. )
  485. self.store_transaction_metric(
  486. 4,
  487. "measurements.cls",
  488. tags={"transaction": "foo_transaction"},
  489. timestamp=self.min_ago,
  490. )
  491. self.store_transaction_metric(
  492. 1,
  493. "user",
  494. tags={
  495. "transaction": "foo_transaction",
  496. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_FRUSTRATED_TAG_VALUE,
  497. },
  498. timestamp=self.min_ago,
  499. )
  500. response = self.do_request(
  501. {
  502. "field": [
  503. "team_key_transaction",
  504. "transaction",
  505. "project",
  506. "tpm()",
  507. "p75(measurements.fcp)",
  508. "p75(measurements.lcp)",
  509. "p75(measurements.fid)",
  510. "p75(measurements.cls)",
  511. "count_unique(user)",
  512. "apdex()",
  513. "count_miserable(user)",
  514. "user_misery()",
  515. "failure_rate()",
  516. "failure_count()",
  517. ],
  518. "orderby": ["team_key_transaction", "user_misery()"],
  519. "query": "event.type:transaction",
  520. "dataset": "metrics",
  521. "per_page": 50,
  522. }
  523. )
  524. assert response.status_code == 200, response.content
  525. assert len(response.data["data"]) == 1
  526. data = response.data["data"][0]
  527. meta = response.data["meta"]
  528. field_meta = meta["fields"]
  529. assert data["transaction"] == "foo_transaction"
  530. assert data["project"] == self.project.slug
  531. assert data["p75(measurements.fcp)"] == 1.0
  532. assert data["p75(measurements.lcp)"] == 2.0
  533. assert data["p75(measurements.fid)"] == 3.0
  534. assert data["p75(measurements.cls)"] == 4.0
  535. assert data["apdex()"] == 1.0
  536. assert data["count_miserable(user)"] == 1.0
  537. assert data["user_misery()"] == 0.058
  538. assert data["failure_rate()"] == 1
  539. assert data["failure_count()"] == 1
  540. assert meta["isMetricsData"]
  541. assert field_meta["transaction"] == "string"
  542. assert field_meta["project"] == "string"
  543. assert field_meta["p75(measurements.fcp)"] == "duration"
  544. assert field_meta["p75(measurements.lcp)"] == "duration"
  545. assert field_meta["p75(measurements.fid)"] == "duration"
  546. assert field_meta["p75(measurements.cls)"] == "number"
  547. assert field_meta["apdex()"] == "number"
  548. assert field_meta["count_miserable(user)"] == "integer"
  549. assert field_meta["user_misery()"] == "number"
  550. assert field_meta["failure_rate()"] == "percentage"
  551. assert field_meta["failure_count()"] == "integer"
  552. def test_no_team_key_transactions(self):
  553. self.store_transaction_metric(
  554. 1, tags={"transaction": "foo_transaction"}, timestamp=self.min_ago
  555. )
  556. self.store_transaction_metric(
  557. 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
  558. )
  559. query = {
  560. "team": "myteams",
  561. "project": [self.project.id],
  562. # TODO sort by transaction here once that's possible for order to match the same test without metrics
  563. "orderby": "p95()",
  564. "field": [
  565. "team_key_transaction",
  566. "transaction",
  567. "transaction.status",
  568. "project",
  569. "epm()",
  570. "failure_rate()",
  571. "p95()",
  572. ],
  573. "per_page": 50,
  574. "dataset": "metricsEnhanced",
  575. }
  576. response = self.do_request(query)
  577. assert response.status_code == 200, response.content
  578. assert len(response.data["data"]) == 2
  579. data = response.data["data"]
  580. meta = response.data["meta"]
  581. field_meta = meta["fields"]
  582. assert data[0]["team_key_transaction"] == 0
  583. assert data[0]["transaction"] == "foo_transaction"
  584. assert data[1]["team_key_transaction"] == 0
  585. assert data[1]["transaction"] == "bar_transaction"
  586. assert meta["isMetricsData"]
  587. assert field_meta["team_key_transaction"] == "boolean"
  588. assert field_meta["transaction"] == "string"
  589. def test_team_key_transactions_my_teams(self):
  590. team1 = self.create_team(organization=self.organization, name="Team A")
  591. self.create_team_membership(team1, user=self.user)
  592. self.project.add_team(team1)
  593. team2 = self.create_team(organization=self.organization, name="Team B")
  594. self.project.add_team(team2)
  595. key_transactions = [
  596. (team1, "foo_transaction"),
  597. (team2, "baz_transaction"),
  598. ]
  599. # Not a key transaction
  600. self.store_transaction_metric(
  601. 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
  602. )
  603. for team, transaction in key_transactions:
  604. self.store_transaction_metric(
  605. 1, tags={"transaction": transaction}, timestamp=self.min_ago
  606. )
  607. TeamKeyTransaction.objects.create(
  608. organization=self.organization,
  609. transaction=transaction,
  610. project_team=ProjectTeam.objects.get(project=self.project, team=team),
  611. )
  612. query = {
  613. "team": "myteams",
  614. "project": [self.project.id],
  615. "field": [
  616. "team_key_transaction",
  617. "transaction",
  618. "transaction.status",
  619. "project",
  620. "epm()",
  621. "failure_rate()",
  622. "p95()",
  623. ],
  624. "per_page": 50,
  625. "dataset": "metricsEnhanced",
  626. }
  627. query["orderby"] = ["team_key_transaction", "p95()"]
  628. response = self.do_request(query)
  629. assert response.status_code == 200, response.content
  630. assert len(response.data["data"]) == 3
  631. data = response.data["data"]
  632. meta = response.data["meta"]
  633. field_meta = meta["fields"]
  634. assert data[0]["team_key_transaction"] == 0
  635. assert data[0]["transaction"] == "baz_transaction"
  636. assert data[1]["team_key_transaction"] == 0
  637. assert data[1]["transaction"] == "bar_transaction"
  638. assert data[2]["team_key_transaction"] == 1
  639. assert data[2]["transaction"] == "foo_transaction"
  640. assert meta["isMetricsData"]
  641. assert field_meta["team_key_transaction"] == "boolean"
  642. assert field_meta["transaction"] == "string"
  643. # not specifying any teams should use my teams
  644. query = {
  645. "project": [self.project.id],
  646. "field": [
  647. "team_key_transaction",
  648. "transaction",
  649. "transaction.status",
  650. "project",
  651. "epm()",
  652. "failure_rate()",
  653. "p95()",
  654. ],
  655. "per_page": 50,
  656. "dataset": "metricsEnhanced",
  657. }
  658. query["orderby"] = ["team_key_transaction", "p95()"]
  659. response = self.do_request(query)
  660. assert response.status_code == 200, response.content
  661. assert len(response.data["data"]) == 3
  662. data = response.data["data"]
  663. meta = response.data["meta"]
  664. field_meta = meta["fields"]
  665. assert data[0]["team_key_transaction"] == 0
  666. assert data[0]["transaction"] == "baz_transaction"
  667. assert data[1]["team_key_transaction"] == 0
  668. assert data[1]["transaction"] == "bar_transaction"
  669. assert data[2]["team_key_transaction"] == 1
  670. assert data[2]["transaction"] == "foo_transaction"
  671. assert meta["isMetricsData"]
  672. assert field_meta["team_key_transaction"] == "boolean"
  673. assert field_meta["transaction"] == "string"
  674. def test_team_key_transactions_orderby(self):
  675. team1 = self.create_team(organization=self.organization, name="Team A")
  676. team2 = self.create_team(organization=self.organization, name="Team B")
  677. key_transactions = [
  678. (team1, "foo_transaction", 1),
  679. (team2, "baz_transaction", 100),
  680. ]
  681. # Not a key transaction
  682. self.store_transaction_metric(
  683. 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
  684. )
  685. for team, transaction, value in key_transactions:
  686. self.store_transaction_metric(
  687. value, tags={"transaction": transaction}, timestamp=self.min_ago
  688. )
  689. self.create_team_membership(team, user=self.user)
  690. self.project.add_team(team)
  691. TeamKeyTransaction.objects.create(
  692. organization=self.organization,
  693. transaction=transaction,
  694. project_team=ProjectTeam.objects.get(project=self.project, team=team),
  695. )
  696. query = {
  697. "team": "myteams",
  698. "project": [self.project.id],
  699. "field": [
  700. "team_key_transaction",
  701. "transaction",
  702. "transaction.status",
  703. "project",
  704. "epm()",
  705. "failure_rate()",
  706. "p95()",
  707. ],
  708. "per_page": 50,
  709. "dataset": "metricsEnhanced",
  710. }
  711. # test ascending order
  712. query["orderby"] = ["team_key_transaction", "p95()"]
  713. response = self.do_request(query)
  714. assert response.status_code == 200, response.content
  715. assert len(response.data["data"]) == 3
  716. data = response.data["data"]
  717. meta = response.data["meta"]
  718. field_meta = meta["fields"]
  719. assert data[0]["team_key_transaction"] == 0
  720. assert data[0]["transaction"] == "bar_transaction"
  721. assert data[1]["team_key_transaction"] == 1
  722. assert data[1]["transaction"] == "foo_transaction"
  723. assert data[2]["team_key_transaction"] == 1
  724. assert data[2]["transaction"] == "baz_transaction"
  725. assert meta["isMetricsData"]
  726. assert field_meta["team_key_transaction"] == "boolean"
  727. assert field_meta["transaction"] == "string"
  728. # test descending order
  729. query["orderby"] = ["-team_key_transaction", "p95()"]
  730. response = self.do_request(query)
  731. assert response.status_code == 200, response.content
  732. assert len(response.data["data"]) == 3
  733. data = response.data["data"]
  734. meta = response.data["meta"]
  735. field_meta = meta["fields"]
  736. assert data[0]["team_key_transaction"] == 1
  737. assert data[0]["transaction"] == "foo_transaction"
  738. assert data[1]["team_key_transaction"] == 1
  739. assert data[1]["transaction"] == "baz_transaction"
  740. assert data[2]["team_key_transaction"] == 0
  741. assert data[2]["transaction"] == "bar_transaction"
  742. assert meta["isMetricsData"]
  743. assert field_meta["team_key_transaction"] == "boolean"
  744. assert field_meta["transaction"] == "string"
  745. def test_team_key_transactions_query(self):
  746. team1 = self.create_team(organization=self.organization, name="Team A")
  747. team2 = self.create_team(organization=self.organization, name="Team B")
  748. key_transactions = [
  749. (team1, "foo_transaction", 1),
  750. (team2, "baz_transaction", 100),
  751. ]
  752. # Not a key transaction
  753. self.store_transaction_metric(
  754. 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
  755. )
  756. for team, transaction, value in key_transactions:
  757. self.store_transaction_metric(
  758. value, tags={"transaction": transaction}, timestamp=self.min_ago
  759. )
  760. self.create_team_membership(team, user=self.user)
  761. self.project.add_team(team)
  762. TeamKeyTransaction.objects.create(
  763. organization=self.organization,
  764. transaction=transaction,
  765. project_team=ProjectTeam.objects.get(project=self.project, team=team),
  766. )
  767. query = {
  768. "team": "myteams",
  769. "project": [self.project.id],
  770. # use the order by to ensure the result order
  771. "orderby": "p95()",
  772. "field": [
  773. "team_key_transaction",
  774. "transaction",
  775. "transaction.status",
  776. "project",
  777. "epm()",
  778. "failure_rate()",
  779. "p95()",
  780. ],
  781. "per_page": 50,
  782. "dataset": "metricsEnhanced",
  783. }
  784. # key transactions
  785. query["query"] = "has:team_key_transaction"
  786. response = self.do_request(query)
  787. assert response.status_code == 200, response.content
  788. assert len(response.data["data"]) == 2
  789. data = response.data["data"]
  790. meta = response.data["meta"]
  791. field_meta = meta["fields"]
  792. assert data[0]["team_key_transaction"] == 1
  793. assert data[0]["transaction"] == "foo_transaction"
  794. assert data[1]["team_key_transaction"] == 1
  795. assert data[1]["transaction"] == "baz_transaction"
  796. assert meta["isMetricsData"]
  797. assert field_meta["team_key_transaction"] == "boolean"
  798. assert field_meta["transaction"] == "string"
  799. # key transactions
  800. query["query"] = "team_key_transaction:true"
  801. response = self.do_request(query)
  802. assert response.status_code == 200, response.content
  803. assert len(response.data["data"]) == 2
  804. data = response.data["data"]
  805. meta = response.data["meta"]
  806. field_meta = meta["fields"]
  807. assert data[0]["team_key_transaction"] == 1
  808. assert data[0]["transaction"] == "foo_transaction"
  809. assert data[1]["team_key_transaction"] == 1
  810. assert data[1]["transaction"] == "baz_transaction"
  811. assert meta["isMetricsData"]
  812. assert field_meta["team_key_transaction"] == "boolean"
  813. assert field_meta["transaction"] == "string"
  814. # not key transactions
  815. query["query"] = "!has:team_key_transaction"
  816. response = self.do_request(query)
  817. assert response.status_code == 200, response.content
  818. assert len(response.data["data"]) == 1
  819. data = response.data["data"]
  820. meta = response.data["meta"]
  821. field_meta = meta["fields"]
  822. assert data[0]["team_key_transaction"] == 0
  823. assert data[0]["transaction"] == "bar_transaction"
  824. assert meta["isMetricsData"]
  825. assert field_meta["team_key_transaction"] == "boolean"
  826. assert field_meta["transaction"] == "string"
  827. # not key transactions
  828. query["query"] = "team_key_transaction:false"
  829. response = self.do_request(query)
  830. assert response.status_code == 200, response.content
  831. assert len(response.data["data"]) == 1
  832. data = response.data["data"]
  833. meta = response.data["meta"]
  834. field_meta = meta["fields"]
  835. assert data[0]["team_key_transaction"] == 0
  836. assert data[0]["transaction"] == "bar_transaction"
  837. assert meta["isMetricsData"]
  838. assert field_meta["team_key_transaction"] == "boolean"
  839. assert field_meta["transaction"] == "string"
  840. def test_team_key_transaction_not_exists(self):
  841. team1 = self.create_team(organization=self.organization, name="Team A")
  842. team2 = self.create_team(organization=self.organization, name="Team B")
  843. key_transactions = [
  844. (team1, "foo_transaction", 1),
  845. (team2, "baz_transaction", 100),
  846. ]
  847. for team, transaction, value in key_transactions:
  848. self.store_transaction_metric(
  849. value, tags={"transaction": transaction}, timestamp=self.min_ago
  850. )
  851. self.create_team_membership(team, user=self.user)
  852. self.project.add_team(team)
  853. TeamKeyTransaction.objects.create(
  854. organization=self.organization,
  855. transaction=transaction,
  856. project_team=ProjectTeam.objects.get(project=self.project, team=team),
  857. )
  858. # Don't create a metric for this one
  859. TeamKeyTransaction.objects.create(
  860. organization=self.organization,
  861. transaction="not_in_metrics",
  862. project_team=ProjectTeam.objects.get(project=self.project, team=team1),
  863. )
  864. query = {
  865. "team": "myteams",
  866. "project": [self.project.id],
  867. # use the order by to ensure the result order
  868. "orderby": "p95()",
  869. "field": [
  870. "team_key_transaction",
  871. "transaction",
  872. "transaction.status",
  873. "project",
  874. "epm()",
  875. "failure_rate()",
  876. "p95()",
  877. ],
  878. "per_page": 50,
  879. "dataset": "metricsEnhanced",
  880. }
  881. # key transactions
  882. query["query"] = "has:team_key_transaction"
  883. response = self.do_request(query)
  884. assert response.status_code == 200, response.content
  885. assert len(response.data["data"]) == 2
  886. data = response.data["data"]
  887. meta = response.data["meta"]
  888. field_meta = meta["fields"]
  889. assert data[0]["team_key_transaction"] == 1
  890. assert data[0]["transaction"] == "foo_transaction"
  891. assert data[1]["team_key_transaction"] == 1
  892. assert data[1]["transaction"] == "baz_transaction"
  893. assert meta["isMetricsData"]
  894. assert field_meta["team_key_transaction"] == "boolean"
  895. assert field_meta["transaction"] == "string"
  896. # key transactions
  897. query["query"] = "team_key_transaction:true"
  898. response = self.do_request(query)
  899. assert response.status_code == 200, response.content
  900. assert len(response.data["data"]) == 2
  901. data = response.data["data"]
  902. meta = response.data["meta"]
  903. field_meta = meta["fields"]
  904. assert data[0]["team_key_transaction"] == 1
  905. assert data[0]["transaction"] == "foo_transaction"
  906. assert data[1]["team_key_transaction"] == 1
  907. assert data[1]["transaction"] == "baz_transaction"
  908. assert meta["isMetricsData"]
  909. assert field_meta["team_key_transaction"] == "boolean"
  910. assert field_meta["transaction"] == "string"
  911. # not key transactions
  912. query["query"] = "!has:team_key_transaction"
  913. response = self.do_request(query)
  914. assert response.status_code == 200, response.content
  915. assert len(response.data["data"]) == 0
  916. data = response.data["data"]
  917. meta = response.data["meta"]
  918. field_meta = meta["fields"]
  919. assert meta["isMetricsData"]
  920. assert field_meta["team_key_transaction"] == "boolean"
  921. assert field_meta["transaction"] == "string"
  922. # not key transactions
  923. query["query"] = "team_key_transaction:false"
  924. response = self.do_request(query)
  925. assert response.status_code == 200, response.content
  926. assert len(response.data["data"]) == 0
  927. data = response.data["data"]
  928. meta = response.data["meta"]
  929. field_meta = meta["fields"]
  930. assert meta["isMetricsData"]
  931. assert field_meta["team_key_transaction"] == "boolean"
  932. assert field_meta["transaction"] == "string"
  933. def test_too_many_team_key_transactions(self):
  934. MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS = 1
  935. with mock.patch(
  936. "sentry.search.events.fields.MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS",
  937. MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS,
  938. ):
  939. team = self.create_team(organization=self.organization, name="Team A")
  940. self.create_team_membership(team, user=self.user)
  941. self.project.add_team(team)
  942. project_team = ProjectTeam.objects.get(project=self.project, team=team)
  943. transactions = ["foo_transaction", "bar_transaction", "baz_transaction"]
  944. for i in range(MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS + 1):
  945. self.store_transaction_metric(
  946. 100, tags={"transaction": transactions[i]}, timestamp=self.min_ago
  947. )
  948. TeamKeyTransaction.objects.bulk_create(
  949. [
  950. TeamKeyTransaction(
  951. organization=self.organization,
  952. project_team=project_team,
  953. transaction=transactions[i],
  954. )
  955. for i in range(MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS + 1)
  956. ]
  957. )
  958. query = {
  959. "team": "myteams",
  960. "project": [self.project.id],
  961. "orderby": "p95()",
  962. "field": [
  963. "team_key_transaction",
  964. "transaction",
  965. "transaction.status",
  966. "project",
  967. "epm()",
  968. "failure_rate()",
  969. "p95()",
  970. ],
  971. "dataset": "metricsEnhanced",
  972. "per_page": 50,
  973. }
  974. response = self.do_request(query)
  975. assert response.status_code == 200, response.content
  976. assert len(response.data["data"]) == 2
  977. data = response.data["data"]
  978. meta = response.data["meta"]
  979. assert (
  980. sum(row["team_key_transaction"] for row in data)
  981. == MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS
  982. )
  983. assert meta["isMetricsData"]
  984. def test_measurement_rating(self):
  985. self.store_transaction_metric(
  986. 50,
  987. metric="measurements.lcp",
  988. tags={"measurement_rating": "good", "transaction": "foo_transaction"},
  989. timestamp=self.min_ago,
  990. )
  991. self.store_transaction_metric(
  992. 15,
  993. metric="measurements.fp",
  994. tags={"measurement_rating": "good", "transaction": "foo_transaction"},
  995. timestamp=self.min_ago,
  996. )
  997. self.store_transaction_metric(
  998. 1500,
  999. metric="measurements.fcp",
  1000. tags={"measurement_rating": "meh", "transaction": "foo_transaction"},
  1001. timestamp=self.min_ago,
  1002. )
  1003. self.store_transaction_metric(
  1004. 125,
  1005. metric="measurements.fid",
  1006. tags={"measurement_rating": "meh", "transaction": "foo_transaction"},
  1007. timestamp=self.min_ago,
  1008. )
  1009. self.store_transaction_metric(
  1010. 0.15,
  1011. metric="measurements.cls",
  1012. tags={"measurement_rating": "good", "transaction": "foo_transaction"},
  1013. timestamp=self.min_ago,
  1014. )
  1015. response = self.do_request(
  1016. {
  1017. "field": [
  1018. "transaction",
  1019. "count_web_vitals(measurements.lcp, good)",
  1020. "count_web_vitals(measurements.fp, good)",
  1021. "count_web_vitals(measurements.fcp, meh)",
  1022. "count_web_vitals(measurements.fid, meh)",
  1023. "count_web_vitals(measurements.cls, good)",
  1024. "count_web_vitals(measurements.lcp, any)",
  1025. ],
  1026. "query": "event.type:transaction",
  1027. "dataset": "metricsEnhanced",
  1028. "per_page": 50,
  1029. }
  1030. )
  1031. assert response.status_code == 200, response.content
  1032. assert len(response.data["data"]) == 1
  1033. data = response.data["data"]
  1034. meta = response.data["meta"]
  1035. field_meta = meta["fields"]
  1036. assert data[0]["count_web_vitals(measurements.lcp, good)"] == 1
  1037. assert data[0]["count_web_vitals(measurements.fp, good)"] == 1
  1038. assert data[0]["count_web_vitals(measurements.fcp, meh)"] == 1
  1039. assert data[0]["count_web_vitals(measurements.fid, meh)"] == 1
  1040. assert data[0]["count_web_vitals(measurements.cls, good)"] == 1
  1041. assert data[0]["count_web_vitals(measurements.lcp, any)"] == 1
  1042. assert meta["isMetricsData"]
  1043. assert field_meta["count_web_vitals(measurements.lcp, good)"] == "integer"
  1044. assert field_meta["count_web_vitals(measurements.fp, good)"] == "integer"
  1045. assert field_meta["count_web_vitals(measurements.fcp, meh)"] == "integer"
  1046. assert field_meta["count_web_vitals(measurements.fid, meh)"] == "integer"
  1047. assert field_meta["count_web_vitals(measurements.cls, good)"] == "integer"
  1048. assert field_meta["count_web_vitals(measurements.lcp, any)"] == "integer"
  1049. def test_measurement_rating_that_does_not_exist(self):
  1050. self.store_transaction_metric(
  1051. 1,
  1052. metric="measurements.lcp",
  1053. tags={"measurement_rating": "good", "transaction": "foo_transaction"},
  1054. timestamp=self.min_ago,
  1055. )
  1056. response = self.do_request(
  1057. {
  1058. "field": ["transaction", "count_web_vitals(measurements.lcp, poor)"],
  1059. "query": "event.type:transaction",
  1060. "dataset": "metricsEnhanced",
  1061. "per_page": 50,
  1062. }
  1063. )
  1064. assert response.status_code == 200, response.content
  1065. assert len(response.data["data"]) == 1
  1066. data = response.data["data"]
  1067. meta = response.data["meta"]
  1068. assert data[0]["count_web_vitals(measurements.lcp, poor)"] == 0
  1069. assert meta["isMetricsData"]
  1070. assert meta["fields"]["count_web_vitals(measurements.lcp, poor)"] == "integer"
  1071. def test_count_web_vitals_invalid_vital(self):
  1072. query = {
  1073. "field": [
  1074. "count_web_vitals(measurements.foo, poor)",
  1075. ],
  1076. "project": [self.project.id],
  1077. "dataset": "metricsEnhanced",
  1078. }
  1079. response = self.do_request(query)
  1080. assert response.status_code == 400, response.content
  1081. query = {
  1082. "field": [
  1083. "count_web_vitals(tags[lcp], poor)",
  1084. ],
  1085. "project": [self.project.id],
  1086. "dataset": "metricsEnhanced",
  1087. }
  1088. response = self.do_request(query)
  1089. assert response.status_code == 400, response.content
  1090. query = {
  1091. "field": [
  1092. "count_web_vitals(transaction.duration, poor)",
  1093. ],
  1094. "project": [self.project.id],
  1095. "dataset": "metricsEnhanced",
  1096. }
  1097. response = self.do_request(query)
  1098. assert response.status_code == 400, response.content
  1099. query = {
  1100. "field": [
  1101. "count_web_vitals(measurements.lcp, bad)",
  1102. ],
  1103. "project": [self.project.id],
  1104. "dataset": "metricsEnhanced",
  1105. }
  1106. response = self.do_request(query)
  1107. assert response.status_code == 400, response.content
  1108. def test_count_unique_user_returns_zero(self):
  1109. self.store_transaction_metric(
  1110. 50,
  1111. metric="user",
  1112. tags={"transaction": "foo_transaction"},
  1113. timestamp=self.min_ago,
  1114. )
  1115. self.store_transaction_metric(
  1116. 50,
  1117. tags={"transaction": "foo_transaction"},
  1118. timestamp=self.min_ago,
  1119. )
  1120. self.store_transaction_metric(
  1121. 100,
  1122. tags={"transaction": "bar_transaction"},
  1123. timestamp=self.min_ago,
  1124. )
  1125. query = {
  1126. "project": [self.project.id],
  1127. "orderby": "p50()",
  1128. "field": [
  1129. "transaction",
  1130. "count_unique(user)",
  1131. "p50()",
  1132. ],
  1133. "dataset": "metricsEnhanced",
  1134. "per_page": 50,
  1135. }
  1136. response = self.do_request(query)
  1137. assert response.status_code == 200, response.content
  1138. assert len(response.data["data"]) == 2
  1139. data = response.data["data"]
  1140. meta = response.data["meta"]
  1141. assert data[0]["transaction"] == "foo_transaction"
  1142. assert data[0]["count_unique(user)"] == 1
  1143. assert data[1]["transaction"] == "bar_transaction"
  1144. assert data[1]["count_unique(user)"] == 0
  1145. assert meta["isMetricsData"]
  1146. def test_sum_transaction_duration(self):
  1147. self.store_transaction_metric(
  1148. 50,
  1149. tags={"transaction": "foo_transaction"},
  1150. timestamp=self.min_ago,
  1151. )
  1152. self.store_transaction_metric(
  1153. 100,
  1154. tags={"transaction": "foo_transaction"},
  1155. timestamp=self.min_ago,
  1156. )
  1157. self.store_transaction_metric(
  1158. 150,
  1159. tags={"transaction": "foo_transaction"},
  1160. timestamp=self.min_ago,
  1161. )
  1162. query = {
  1163. "project": [self.project.id],
  1164. "orderby": "sum(transaction.duration)",
  1165. "field": [
  1166. "transaction",
  1167. "sum(transaction.duration)",
  1168. ],
  1169. "dataset": "metricsEnhanced",
  1170. "per_page": 50,
  1171. }
  1172. response = self.do_request(query)
  1173. assert response.status_code == 200, response.content
  1174. assert len(response.data["data"]) == 1
  1175. data = response.data["data"]
  1176. meta = response.data["meta"]
  1177. assert data[0]["transaction"] == "foo_transaction"
  1178. assert data[0]["sum(transaction.duration)"] == 300
  1179. assert meta["isMetricsData"]
  1180. def test_custom_measurements_simple(self):
  1181. self.store_transaction_metric(
  1182. 1,
  1183. metric="measurements.something_custom",
  1184. internal_metric="d:transactions/measurements.something_custom@millisecond",
  1185. entity="metrics_distributions",
  1186. tags={"transaction": "foo_transaction"},
  1187. timestamp=self.min_ago,
  1188. )
  1189. query = {
  1190. "project": [self.project.id],
  1191. "orderby": "p50(measurements.something_custom)",
  1192. "field": [
  1193. "transaction",
  1194. "p50(measurements.something_custom)",
  1195. ],
  1196. "statsPeriod": "24h",
  1197. "dataset": "metricsEnhanced",
  1198. "per_page": 50,
  1199. }
  1200. self.wait_for_metric_count(
  1201. self.project,
  1202. 1,
  1203. metric="measurements.something_custom",
  1204. mri="d:transactions/measurements.something_custom@millisecond",
  1205. )
  1206. response = self.do_request(query)
  1207. assert response.status_code == 200, response.content
  1208. assert len(response.data["data"]) == 1
  1209. data = response.data["data"]
  1210. meta = response.data["meta"]
  1211. assert data[0]["transaction"] == "foo_transaction"
  1212. assert data[0]["p50(measurements.something_custom)"] == 1
  1213. assert meta["isMetricsData"]
  1214. assert meta["fields"]["p50(measurements.something_custom)"] == "duration"
  1215. assert meta["units"]["p50(measurements.something_custom)"] == "millisecond"
  1216. def test_custom_measurement_size_meta_type(self):
  1217. self.store_transaction_metric(
  1218. 100,
  1219. metric="measurements.custom_type",
  1220. internal_metric="d:transactions/measurements.custom_type@somethingcustom",
  1221. entity="metrics_distributions",
  1222. tags={"transaction": "foo_transaction"},
  1223. timestamp=self.min_ago,
  1224. )
  1225. self.store_transaction_metric(
  1226. 100,
  1227. metric="measurements.percent",
  1228. internal_metric="d:transactions/measurements.percent@ratio",
  1229. entity="metrics_distributions",
  1230. tags={"transaction": "foo_transaction"},
  1231. timestamp=self.min_ago,
  1232. )
  1233. self.store_transaction_metric(
  1234. 100,
  1235. metric="measurements.longtaskcount",
  1236. internal_metric="d:transactions/measurements.longtaskcount@none",
  1237. entity="metrics_distributions",
  1238. tags={"transaction": "foo_transaction"},
  1239. timestamp=self.min_ago,
  1240. )
  1241. query = {
  1242. "project": [self.project.id],
  1243. "orderby": "p50(measurements.longtaskcount)",
  1244. "field": [
  1245. "transaction",
  1246. "p50(measurements.longtaskcount)",
  1247. "p50(measurements.percent)",
  1248. "p50(measurements.custom_type)",
  1249. ],
  1250. "statsPeriod": "24h",
  1251. "dataset": "metricsEnhanced",
  1252. "per_page": 50,
  1253. }
  1254. response = self.do_request(query)
  1255. assert response.status_code == 200, response.content
  1256. assert len(response.data["data"]) == 1
  1257. data = response.data["data"]
  1258. meta = response.data["meta"]
  1259. assert data[0]["transaction"] == "foo_transaction"
  1260. assert data[0]["p50(measurements.longtaskcount)"] == 100
  1261. assert data[0]["p50(measurements.percent)"] == 100
  1262. assert data[0]["p50(measurements.custom_type)"] == 100
  1263. assert meta["isMetricsData"]
  1264. assert meta["fields"]["p50(measurements.longtaskcount)"] == "integer"
  1265. assert meta["units"]["p50(measurements.longtaskcount)"] is None
  1266. assert meta["fields"]["p50(measurements.percent)"] == "percentage"
  1267. assert meta["units"]["p50(measurements.percent)"] is None
  1268. assert meta["fields"]["p50(measurements.custom_type)"] == "number"
  1269. assert meta["units"]["p50(measurements.custom_type)"] is None
  1270. def test_custom_measurement_none_type(self):
  1271. self.store_transaction_metric(
  1272. 1,
  1273. metric="measurements.cls",
  1274. entity="metrics_distributions",
  1275. tags={"transaction": "foo_transaction"},
  1276. timestamp=self.min_ago,
  1277. )
  1278. query = {
  1279. "project": [self.project.id],
  1280. "orderby": "p75(measurements.cls)",
  1281. "field": [
  1282. "transaction",
  1283. "p75(measurements.cls)",
  1284. "p99(measurements.cls)",
  1285. "max(measurements.cls)",
  1286. ],
  1287. "statsPeriod": "24h",
  1288. "dataset": "metricsEnhanced",
  1289. "per_page": 50,
  1290. }
  1291. self.wait_for_metric_count(
  1292. self.project,
  1293. 1,
  1294. metric=TransactionMetricKey.MEASUREMENTS_CLS.value,
  1295. mri=TransactionMRI.MEASUREMENTS_CLS.value,
  1296. )
  1297. response = self.do_request(query)
  1298. assert response.status_code == 200, response.content
  1299. assert len(response.data["data"]) == 1
  1300. data = response.data["data"]
  1301. meta = response.data["meta"]
  1302. assert data[0]["transaction"] == "foo_transaction"
  1303. assert data[0]["p75(measurements.cls)"] == 1
  1304. assert data[0]["p99(measurements.cls)"] == 1
  1305. assert data[0]["max(measurements.cls)"] == 1
  1306. assert meta["isMetricsData"]
  1307. assert meta["fields"]["p75(measurements.cls)"] == "number"
  1308. assert meta["units"]["p75(measurements.cls)"] is None
  1309. assert meta["fields"]["p99(measurements.cls)"] == "number"
  1310. assert meta["units"]["p99(measurements.cls)"] is None
  1311. assert meta["fields"]["max(measurements.cls)"] == "number"
  1312. assert meta["units"]["max(measurements.cls)"] is None
  1313. def test_custom_measurement_duration_filtering(self):
  1314. self.store_transaction_metric(
  1315. 1,
  1316. metric="measurements.runtime",
  1317. internal_metric="d:transactions/measurements.runtime@hour",
  1318. entity="metrics_distributions",
  1319. tags={"transaction": "foo_transaction"},
  1320. timestamp=self.min_ago,
  1321. )
  1322. self.store_transaction_metric(
  1323. 180,
  1324. metric="measurements.runtime",
  1325. internal_metric="d:transactions/measurements.runtime@hour",
  1326. entity="metrics_distributions",
  1327. tags={"transaction": "bar_transaction"},
  1328. timestamp=self.min_ago,
  1329. )
  1330. query = {
  1331. "project": [self.project.id],
  1332. "field": [
  1333. "transaction",
  1334. "max(measurements.runtime)",
  1335. ],
  1336. "query": "p50(measurements.runtime):>1wk",
  1337. "statsPeriod": "24h",
  1338. "dataset": "metricsEnhanced",
  1339. "per_page": 50,
  1340. }
  1341. response = self.do_request(query)
  1342. assert response.status_code == 200, response.content
  1343. assert len(response.data["data"]) == 1
  1344. data = response.data["data"]
  1345. meta = response.data["meta"]
  1346. assert data[0]["transaction"] == "bar_transaction"
  1347. assert data[0]["max(measurements.runtime)"] == 180
  1348. assert meta["isMetricsData"]
  1349. def test_custom_measurement_size_filtering(self):
  1350. self.store_transaction_metric(
  1351. 1,
  1352. metric="measurements.datacenter_memory",
  1353. internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
  1354. entity="metrics_distributions",
  1355. tags={"transaction": "foo_transaction"},
  1356. timestamp=self.min_ago,
  1357. )
  1358. self.store_transaction_metric(
  1359. 100,
  1360. metric="measurements.datacenter_memory",
  1361. internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
  1362. entity="metrics_distributions",
  1363. tags={"transaction": "bar_transaction"},
  1364. timestamp=self.min_ago,
  1365. )
  1366. query = {
  1367. "project": [self.project.id],
  1368. "field": [
  1369. "transaction",
  1370. "max(measurements.datacenter_memory)",
  1371. ],
  1372. "query": "p50(measurements.datacenter_memory):>5pb",
  1373. "statsPeriod": "24h",
  1374. "dataset": "metricsEnhanced",
  1375. "per_page": 50,
  1376. }
  1377. response = self.do_request(query)
  1378. assert response.status_code == 200, response.content
  1379. assert len(response.data["data"]) == 1
  1380. data = response.data["data"]
  1381. meta = response.data["meta"]
  1382. assert data[0]["transaction"] == "bar_transaction"
  1383. assert data[0]["max(measurements.datacenter_memory)"] == 100
  1384. assert meta["units"]["max(measurements.datacenter_memory)"] == "petabyte"
  1385. assert meta["fields"]["max(measurements.datacenter_memory)"] == "size"
  1386. assert meta["isMetricsData"]
  1387. def test_has_custom_measurement(self):
  1388. self.store_transaction_metric(
  1389. 33,
  1390. metric="measurements.datacenter_memory",
  1391. internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
  1392. entity="metrics_distributions",
  1393. tags={"transaction": "foo_transaction"},
  1394. timestamp=self.min_ago,
  1395. )
  1396. transaction_data = load_data("transaction", timestamp=self.min_ago)
  1397. transaction_data["measurements"]["datacenter_memory"] = {
  1398. "value": 33,
  1399. "unit": "petabyte",
  1400. }
  1401. self.store_event(transaction_data, self.project.id)
  1402. measurement = "measurements.datacenter_memory"
  1403. response = self.do_request(
  1404. {
  1405. "field": ["transaction", measurement],
  1406. "query": "has:measurements.datacenter_memory",
  1407. "dataset": "discover",
  1408. }
  1409. )
  1410. assert response.status_code == 200, response.content
  1411. assert len(response.data["data"]) == 1
  1412. response = self.do_request(
  1413. {
  1414. "field": ["transaction", measurement],
  1415. "query": "!has:measurements.datacenter_memory",
  1416. "dataset": "discover",
  1417. }
  1418. )
  1419. assert response.status_code == 200, response.content
  1420. assert len(response.data["data"]) == 0
  1421. def test_environment_param(self):
  1422. self.create_environment(self.project, name="staging")
  1423. self.store_transaction_metric(
  1424. 1,
  1425. tags={"transaction": "foo_transaction", "environment": "staging"},
  1426. timestamp=self.min_ago,
  1427. )
  1428. self.store_transaction_metric(
  1429. 100,
  1430. tags={"transaction": "foo_transaction"},
  1431. timestamp=self.min_ago,
  1432. )
  1433. query = {
  1434. "project": [self.project.id],
  1435. "environment": "staging",
  1436. "orderby": "p50(transaction.duration)",
  1437. "field": [
  1438. "transaction",
  1439. "environment",
  1440. "p50(transaction.duration)",
  1441. ],
  1442. "statsPeriod": "24h",
  1443. "dataset": "metricsEnhanced",
  1444. "per_page": 50,
  1445. }
  1446. response = self.do_request(query)
  1447. assert response.status_code == 200, response.content
  1448. assert len(response.data["data"]) == 1
  1449. data = response.data["data"]
  1450. meta = response.data["meta"]
  1451. assert data[0]["transaction"] == "foo_transaction"
  1452. assert data[0]["environment"] == "staging"
  1453. assert data[0]["p50(transaction.duration)"] == 1
  1454. assert meta["isMetricsData"]
  1455. @pytest.mark.xfail(reason="Started failing on ClickHouse 21.8")
  1456. def test_environment_query(self):
  1457. self.create_environment(self.project, name="staging")
  1458. self.store_transaction_metric(
  1459. 1,
  1460. tags={"transaction": "foo_transaction", "environment": "staging"},
  1461. timestamp=self.min_ago,
  1462. )
  1463. self.store_transaction_metric(
  1464. 100,
  1465. tags={"transaction": "foo_transaction"},
  1466. timestamp=self.min_ago,
  1467. )
  1468. query = {
  1469. "project": [self.project.id],
  1470. "orderby": "p50(transaction.duration)",
  1471. "field": [
  1472. "transaction",
  1473. "environment",
  1474. "p50(transaction.duration)",
  1475. ],
  1476. "query": "!has:environment",
  1477. "statsPeriod": "24h",
  1478. "dataset": "metricsEnhanced",
  1479. "per_page": 50,
  1480. }
  1481. self.wait_for_metric_count(self.project, 2)
  1482. response = self.do_request(query)
  1483. assert response.status_code == 200, response.content
  1484. assert len(response.data["data"]) == 1
  1485. data = response.data["data"]
  1486. meta = response.data["meta"]
  1487. assert data[0]["transaction"] == "foo_transaction"
  1488. assert data[0]["environment"] is None or data[0]["environment"] == ""
  1489. assert data[0]["p50(transaction.duration)"] == 100
  1490. assert meta["isMetricsData"]
  1491. def test_has_transaction(self):
  1492. self.store_transaction_metric(
  1493. 1,
  1494. tags={},
  1495. timestamp=self.min_ago,
  1496. )
  1497. self.store_transaction_metric(
  1498. 100,
  1499. tags={"transaction": "foo_transaction"},
  1500. timestamp=self.min_ago,
  1501. )
  1502. query = {
  1503. "project": [self.project.id],
  1504. "orderby": "p50(transaction.duration)",
  1505. "field": [
  1506. "transaction",
  1507. "p50(transaction.duration)",
  1508. ],
  1509. "query": "has:transaction",
  1510. "statsPeriod": "24h",
  1511. "dataset": "metricsEnhanced",
  1512. "per_page": 50,
  1513. }
  1514. self.wait_for_metric_count(self.project, 2)
  1515. response = self.do_request(query)
  1516. assert response.status_code == 200, response.content
  1517. assert len(response.data["data"]) == 2
  1518. data = response.data["data"]
  1519. meta = response.data["meta"]
  1520. assert data[0]["transaction"] == "<< unparameterized >>"
  1521. assert data[0]["p50(transaction.duration)"] == 1
  1522. assert data[1]["transaction"] == "foo_transaction"
  1523. assert data[1]["p50(transaction.duration)"] == 100
  1524. assert meta["isMetricsData"]
  1525. query = {
  1526. "project": [self.project.id],
  1527. "orderby": "p50(transaction.duration)",
  1528. "field": [
  1529. "transaction",
  1530. "p50(transaction.duration)",
  1531. ],
  1532. "query": "!has:transaction",
  1533. "statsPeriod": "24h",
  1534. "dataset": "metricsEnhanced",
  1535. "per_page": 50,
  1536. }
  1537. response = self.do_request(query)
  1538. assert response.status_code == 400, response.content
  1539. def test_apdex_transaction_threshold(self):
  1540. ProjectTransactionThresholdOverride.objects.create(
  1541. transaction="foo_transaction",
  1542. project=self.project,
  1543. organization=self.project.organization,
  1544. threshold=600,
  1545. metric=TransactionMetric.LCP.value,
  1546. )
  1547. ProjectTransactionThresholdOverride.objects.create(
  1548. transaction="bar_transaction",
  1549. project=self.project,
  1550. organization=self.project.organization,
  1551. threshold=600,
  1552. metric=TransactionMetric.LCP.value,
  1553. )
  1554. self.store_transaction_metric(
  1555. 1,
  1556. tags={
  1557. "transaction": "foo_transaction",
  1558. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
  1559. },
  1560. timestamp=self.min_ago,
  1561. )
  1562. self.store_transaction_metric(
  1563. 1,
  1564. "measurements.lcp",
  1565. tags={
  1566. "transaction": "bar_transaction",
  1567. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
  1568. },
  1569. timestamp=self.min_ago,
  1570. )
  1571. response = self.do_request(
  1572. {
  1573. "field": [
  1574. "transaction",
  1575. "apdex()",
  1576. ],
  1577. "orderby": ["apdex()"],
  1578. "query": "event.type:transaction",
  1579. "dataset": "metrics",
  1580. "per_page": 50,
  1581. }
  1582. )
  1583. assert len(response.data["data"]) == 2
  1584. data = response.data["data"]
  1585. meta = response.data["meta"]
  1586. field_meta = meta["fields"]
  1587. assert data[0]["transaction"] == "bar_transaction"
  1588. # Threshold is lcp based
  1589. assert data[0]["apdex()"] == 1
  1590. assert data[1]["transaction"] == "foo_transaction"
  1591. # Threshold is lcp based
  1592. assert data[1]["apdex()"] == 0
  1593. assert meta["isMetricsData"]
  1594. assert field_meta["transaction"] == "string"
  1595. assert field_meta["apdex()"] == "number"
  1596. def test_apdex_project_threshold(self):
  1597. ProjectTransactionThreshold.objects.create(
  1598. project=self.project,
  1599. organization=self.project.organization,
  1600. threshold=600,
  1601. metric=TransactionMetric.LCP.value,
  1602. )
  1603. self.store_transaction_metric(
  1604. 1,
  1605. tags={
  1606. "transaction": "foo_transaction",
  1607. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
  1608. },
  1609. timestamp=self.min_ago,
  1610. )
  1611. self.store_transaction_metric(
  1612. 1,
  1613. "measurements.lcp",
  1614. tags={
  1615. "transaction": "bar_transaction",
  1616. constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
  1617. },
  1618. timestamp=self.min_ago,
  1619. )
  1620. response = self.do_request(
  1621. {
  1622. "field": [
  1623. "transaction",
  1624. "apdex()",
  1625. ],
  1626. "orderby": ["apdex()"],
  1627. "query": "event.type:transaction",
  1628. "dataset": "metrics",
  1629. "per_page": 50,
  1630. }
  1631. )
  1632. assert response.status_code == 200, response.content
  1633. assert len(response.data["data"]) == 2
  1634. data = response.data["data"]
  1635. meta = response.data["meta"]
  1636. field_meta = meta["fields"]
  1637. assert data[0]["transaction"] == "bar_transaction"
  1638. # Threshold is lcp based
  1639. assert data[0]["apdex()"] == 1
  1640. assert data[1]["transaction"] == "foo_transaction"
  1641. # Threshold is lcp based
  1642. assert data[1]["apdex()"] == 0
  1643. assert meta["isMetricsData"]
  1644. assert field_meta["transaction"] == "string"
  1645. assert field_meta["apdex()"] == "number"
  1646. def test_apdex_satisfaction_param(self):
  1647. for function in ["apdex(300)", "user_misery(300)", "count_miserable(user, 300)"]:
  1648. query = {
  1649. "project": [self.project.id],
  1650. "field": [
  1651. "transaction",
  1652. function,
  1653. ],
  1654. "statsPeriod": "24h",
  1655. "dataset": "metricsEnhanced",
  1656. "per_page": 50,
  1657. }
  1658. response = self.do_request(query)
  1659. assert response.status_code == 200, response.content
  1660. assert len(response.data["data"]) == 0
  1661. meta = response.data["meta"]
  1662. assert not meta["isMetricsData"], function
  1663. query = {
  1664. "project": [self.project.id],
  1665. "field": [
  1666. "transaction",
  1667. function,
  1668. ],
  1669. "statsPeriod": "24h",
  1670. "dataset": "metrics",
  1671. "per_page": 50,
  1672. }
  1673. response = self.do_request(query)
  1674. assert response.status_code == 400, function
  1675. assert b"threshold parameter" in response.content, function
  1676. def test_mobile_metrics(self):
  1677. self.store_transaction_metric(
  1678. 0.4,
  1679. "measurements.frames_frozen_rate",
  1680. tags={
  1681. "transaction": "bar_transaction",
  1682. },
  1683. timestamp=self.min_ago,
  1684. )
  1685. query = {
  1686. "project": [self.project.id],
  1687. "field": [
  1688. "transaction",
  1689. "p50(measurements.frames_frozen_rate)",
  1690. ],
  1691. "statsPeriod": "24h",
  1692. "dataset": "metrics",
  1693. "per_page": 50,
  1694. }
  1695. response = self.do_request(query)
  1696. assert response.status_code == 200, response.content
  1697. assert len(response.data["data"]) == 1
  1698. assert response.data["data"][0]["p50(measurements.frames_frozen_rate)"] == 0.4
  1699. def test_merge_null_unparam(self):
  1700. self.store_transaction_metric(
  1701. 1,
  1702. # Transaction: unparam
  1703. tags={
  1704. "transaction": "<< unparameterized >>",
  1705. },
  1706. timestamp=self.min_ago,
  1707. )
  1708. self.store_transaction_metric(
  1709. 2,
  1710. # Transaction:null
  1711. tags={},
  1712. timestamp=self.min_ago,
  1713. )
  1714. query = {
  1715. "project": [self.project.id],
  1716. "field": [
  1717. "transaction",
  1718. "p50(transaction.duration)",
  1719. ],
  1720. "statsPeriod": "24h",
  1721. "dataset": "metrics",
  1722. "per_page": 50,
  1723. }
  1724. response = self.do_request(query)
  1725. assert response.status_code == 200, response.content
  1726. assert len(response.data["data"]) == 1
  1727. assert response.data["data"][0]["p50(transaction.duration)"] == 1.5
  1728. def test_unparam_filter(self):
  1729. self.store_transaction_metric(
  1730. 1,
  1731. # Transaction: unparam
  1732. tags={
  1733. "transaction": "<< unparameterized >>",
  1734. },
  1735. timestamp=self.min_ago,
  1736. )
  1737. self.store_transaction_metric(
  1738. 2,
  1739. # Transaction:null
  1740. tags={},
  1741. timestamp=self.min_ago,
  1742. )
  1743. self.store_transaction_metric(
  1744. 3,
  1745. tags={
  1746. "transaction": "foo_transaction",
  1747. },
  1748. timestamp=self.min_ago,
  1749. )
  1750. query = {
  1751. "project": [self.project.id],
  1752. "field": [
  1753. "transaction",
  1754. "count()",
  1755. ],
  1756. "query": 'transaction:"<< unparameterized >>"',
  1757. "statsPeriod": "24h",
  1758. "dataset": "metrics",
  1759. "per_page": 50,
  1760. }
  1761. self.wait_for_metric_count(self.project, 3)
  1762. response = self.do_request(query)
  1763. assert response.status_code == 200, response.content
  1764. assert len(response.data["data"]) == 1
  1765. assert response.data["data"][0]["transaction"] == "<< unparameterized >>"
  1766. assert response.data["data"][0]["count()"] == 2
  1767. def test_custom_measurements_without_function(self):
  1768. self.store_transaction_metric(
  1769. 33,
  1770. metric="measurements.datacenter_memory",
  1771. internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
  1772. entity="metrics_distributions",
  1773. tags={"transaction": "foo_transaction"},
  1774. timestamp=self.min_ago,
  1775. )
  1776. transaction_data = load_data("transaction", timestamp=self.min_ago)
  1777. transaction_data["measurements"]["datacenter_memory"] = {
  1778. "value": 33,
  1779. "unit": "petabyte",
  1780. }
  1781. self.store_event(transaction_data, self.project.id)
  1782. measurement = "measurements.datacenter_memory"
  1783. response = self.do_request(
  1784. {
  1785. "field": ["transaction", measurement],
  1786. "query": "measurements.datacenter_memory:33pb",
  1787. "dataset": "discover",
  1788. }
  1789. )
  1790. assert response.status_code == 200, response.content
  1791. data = response.data["data"]
  1792. assert len(data) == 1
  1793. assert data[0][measurement] == 33
  1794. meta = response.data["meta"]
  1795. field_meta = meta["fields"]
  1796. unit_meta = meta["units"]
  1797. assert field_meta[measurement] == "size"
  1798. assert unit_meta[measurement] == "petabyte"
  1799. assert not meta["isMetricsData"]
  1800. def test_custom_measurements_with_function(self):
  1801. self.store_transaction_metric(
  1802. 33,
  1803. metric="measurements.datacenter_memory",
  1804. internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
  1805. entity="metrics_distributions",
  1806. tags={"transaction": "foo_transaction"},
  1807. timestamp=self.min_ago,
  1808. )
  1809. transaction_data = load_data("transaction", timestamp=self.min_ago)
  1810. transaction_data["measurements"]["datacenter_memory"] = {
  1811. "value": 33,
  1812. "unit": "petabyte",
  1813. }
  1814. self.store_event(transaction_data, self.project.id)
  1815. measurement = "p50(measurements.datacenter_memory)"
  1816. response = self.do_request(
  1817. {
  1818. "field": ["transaction", measurement],
  1819. "query": "measurements.datacenter_memory:33pb",
  1820. "dataset": "discover",
  1821. }
  1822. )
  1823. assert response.status_code == 200, response.content
  1824. data = response.data["data"]
  1825. assert len(data) == 1
  1826. assert data[0][measurement] == 33
  1827. meta = response.data["meta"]
  1828. field_meta = meta["fields"]
  1829. unit_meta = meta["units"]
  1830. assert field_meta[measurement] == "size"
  1831. assert unit_meta[measurement] == "petabyte"
  1832. assert not meta["isMetricsData"]
  1833. def test_custom_measurements_equation(self):
  1834. self.store_transaction_metric(
  1835. 33,
  1836. metric="measurements.datacenter_memory",
  1837. internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
  1838. entity="metrics_distributions",
  1839. tags={"transaction": "foo_transaction"},
  1840. timestamp=self.min_ago,
  1841. )
  1842. transaction_data = load_data("transaction", timestamp=self.min_ago)
  1843. transaction_data["measurements"]["datacenter_memory"] = {
  1844. "value": 33,
  1845. "unit": "petabyte",
  1846. }
  1847. self.store_event(transaction_data, self.project.id)
  1848. response = self.do_request(
  1849. {
  1850. "field": [
  1851. "transaction",
  1852. "measurements.datacenter_memory",
  1853. "equation|measurements.datacenter_memory / 3",
  1854. ],
  1855. "query": "",
  1856. "dataset": "discover",
  1857. }
  1858. )
  1859. assert response.status_code == 200, response.content
  1860. data = response.data["data"]
  1861. assert len(data) == 1
  1862. assert data[0]["measurements.datacenter_memory"] == 33
  1863. assert data[0]["equation|measurements.datacenter_memory / 3"] == 11
  1864. meta = response.data["meta"]
  1865. assert not meta["isMetricsData"]
  1866. def test_transaction_wildcard(self):
  1867. self.store_transaction_metric(
  1868. 1,
  1869. tags={"transaction": "foo_transaction"},
  1870. timestamp=self.min_ago,
  1871. )
  1872. self.store_transaction_metric(
  1873. 1,
  1874. tags={"transaction": "bar_transaction"},
  1875. timestamp=self.min_ago,
  1876. )
  1877. response = self.do_request(
  1878. {
  1879. "field": [
  1880. "transaction",
  1881. "p90()",
  1882. ],
  1883. "query": "transaction:foo*",
  1884. "dataset": "metrics",
  1885. }
  1886. )
  1887. assert response.status_code == 200, response.content
  1888. data = response.data["data"]
  1889. assert len(data) == 1
  1890. assert data[0]["p90()"] == 1
  1891. meta = response.data["meta"]
  1892. assert meta["isMetricsData"]
  1893. assert data[0]["transaction"] == "foo_transaction"
  1894. def test_transaction_status_wildcard(self):
  1895. self.store_transaction_metric(
  1896. 1,
  1897. tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
  1898. timestamp=self.min_ago,
  1899. )
  1900. response = self.do_request(
  1901. {
  1902. "field": [
  1903. "transaction",
  1904. "p90()",
  1905. ],
  1906. "query": "transaction.status:f*bar",
  1907. "dataset": "metrics",
  1908. }
  1909. )
  1910. assert response.status_code == 200, response.content
  1911. data = response.data["data"]
  1912. assert len(data) == 1
  1913. assert data[0]["p90()"] == 1
  1914. meta = response.data["meta"]
  1915. assert meta["isMetricsData"]
  1916. def test_http_error_rate(self):
  1917. self.store_transaction_metric(
  1918. 1,
  1919. tags={
  1920. "transaction": "foo_transaction",
  1921. "transaction.status": "foobar",
  1922. "http.status_code": "500",
  1923. },
  1924. timestamp=self.min_ago,
  1925. )
  1926. self.store_transaction_metric(
  1927. 1,
  1928. tags={"transaction": "bar_transaction", "http.status_code": "400"},
  1929. timestamp=self.min_ago,
  1930. )
  1931. response = self.do_request(
  1932. {
  1933. "field": [
  1934. "http_error_rate()",
  1935. ],
  1936. "dataset": "metrics",
  1937. }
  1938. )
  1939. assert response.status_code == 200, response.content
  1940. data = response.data["data"]
  1941. assert len(data) == 1
  1942. assert data[0]["http_error_rate()"] == 0.5
  1943. meta = response.data["meta"]
  1944. assert meta["isMetricsData"]
  1945. def test_time_spent(self):
  1946. self.store_transaction_metric(
  1947. 1,
  1948. tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
  1949. timestamp=self.min_ago,
  1950. )
  1951. self.store_transaction_metric(
  1952. 1,
  1953. tags={"transaction": "bar_transaction"},
  1954. timestamp=self.min_ago,
  1955. )
  1956. response = self.do_request(
  1957. {
  1958. "field": [
  1959. "transaction",
  1960. "time_spent_percentage()",
  1961. ],
  1962. "dataset": "metrics",
  1963. }
  1964. )
  1965. assert response.status_code == 200, response.content
  1966. data = response.data["data"]
  1967. assert len(data) == 2
  1968. assert data[0]["time_spent_percentage()"] == 0.5
  1969. meta = response.data["meta"]
  1970. assert meta["isMetricsData"]
  1971. def test_has_filter(self):
  1972. self.store_transaction_metric(
  1973. 1,
  1974. tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
  1975. timestamp=self.min_ago,
  1976. )
  1977. response = self.do_request(
  1978. {
  1979. "field": [
  1980. "transaction",
  1981. "p50()",
  1982. ],
  1983. # For the metrics dataset, has on metrics should be no-ops
  1984. "query": "has:measurements.frames_frozen_rate",
  1985. "dataset": "metrics",
  1986. }
  1987. )
  1988. assert response.status_code == 200, response.content
  1989. data = response.data["data"]
  1990. assert len(data) == 1
  1991. assert data[0]["p50()"] == 1
  1992. meta = response.data["meta"]
  1993. assert meta["isMetricsData"]
  1994. response = self.do_request(
  1995. {
  1996. "field": [
  1997. "transaction",
  1998. "p50()",
  1999. ],
  2000. "query": "has:transaction.status",
  2001. "dataset": "metrics",
  2002. }
  2003. )
  2004. assert response.status_code == 200, response.content
  2005. data = response.data["data"]
  2006. assert len(data) == 1
  2007. assert data[0]["p50()"] == 1
  2008. meta = response.data["meta"]
  2009. assert meta["isMetricsData"]
  2010. def test_not_has_filter(self):
  2011. self.store_transaction_metric(
  2012. 1,
  2013. tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
  2014. timestamp=self.min_ago,
  2015. )
  2016. response = self.do_request(
  2017. {
  2018. "field": [
  2019. "transaction",
  2020. "p50()",
  2021. ],
  2022. "query": "!has:transaction.status",
  2023. "dataset": "metrics",
  2024. }
  2025. )
  2026. assert response.status_code == 200, response.content
  2027. data = response.data["data"]
  2028. assert len(data) == 0
  2029. meta = response.data["meta"]
  2030. assert meta["isMetricsData"]
  2031. response = self.do_request(
  2032. {
  2033. "field": [
  2034. "transaction",
  2035. "p50()",
  2036. ],
  2037. # Doing !has on the metrics dataset doesn't really make sense
  2038. "query": "!has:measurements.frames_frozen_rate",
  2039. "dataset": "metrics",
  2040. }
  2041. )
  2042. assert response.status_code == 400, response.content
  2043. def test_p50_with_count(self):
  2044. """Implicitly test the fact that percentiles are their own 'dataset'"""
  2045. self.store_transaction_metric(
  2046. 1,
  2047. tags={"transaction": "foo_transaction"},
  2048. timestamp=self.min_ago,
  2049. )
  2050. response = self.do_request(
  2051. {
  2052. "field": ["title", "p50()", "count()"],
  2053. "query": "event.type:transaction",
  2054. "dataset": "metrics",
  2055. "project": self.project.id,
  2056. "per_page": 50,
  2057. }
  2058. )
  2059. assert response.status_code == 200, response.content
  2060. assert len(response.data["data"]) == 1
  2061. data = response.data["data"]
  2062. meta = response.data["meta"]
  2063. field_meta = meta["fields"]
  2064. assert data[0]["title"] == "foo_transaction"
  2065. assert data[0]["p50()"] == 1
  2066. assert data[0]["count()"] == 1
  2067. assert meta["isMetricsData"]
  2068. assert field_meta["title"] == "string"
  2069. assert field_meta["p50()"] == "duration"
  2070. assert field_meta["count()"] == "integer"
  2071. def test_p75_with_count_and_more_groupby(self):
  2072. """Implicitly test the fact that percentiles are their own 'dataset'"""
  2073. self.store_transaction_metric(
  2074. 1,
  2075. tags={"transaction": "foo_transaction"},
  2076. timestamp=self.min_ago,
  2077. )
  2078. self.store_transaction_metric(
  2079. 5,
  2080. tags={"transaction": "bar_transaction"},
  2081. timestamp=self.min_ago,
  2082. )
  2083. self.store_transaction_metric(
  2084. 5,
  2085. tags={"transaction": "bar_transaction"},
  2086. timestamp=self.min_ago,
  2087. )
  2088. response = self.do_request(
  2089. {
  2090. "field": [
  2091. "title",
  2092. "project",
  2093. "p75()",
  2094. "count()",
  2095. ],
  2096. "query": "event.type:transaction",
  2097. "orderby": "count()",
  2098. "dataset": "metrics",
  2099. "project": self.project.id,
  2100. "per_page": 50,
  2101. }
  2102. )
  2103. assert response.status_code == 200, response.content
  2104. assert len(response.data["data"]) == 2
  2105. data = response.data["data"]
  2106. meta = response.data["meta"]
  2107. field_meta = meta["fields"]
  2108. assert data[0]["title"] == "foo_transaction"
  2109. assert data[0]["p75()"] == 1
  2110. assert data[0]["count()"] == 1
  2111. assert data[1]["title"] == "bar_transaction"
  2112. assert data[1]["p75()"] == 5
  2113. assert data[1]["count()"] == 2
  2114. assert meta["isMetricsData"]
  2115. assert field_meta["title"] == "string"
  2116. assert field_meta["p75()"] == "duration"
  2117. assert field_meta["count()"] == "integer"
  2118. def test_title_and_transaction_alias(self):
  2119. # Title and transaction are aliases to the same column
  2120. self.store_transaction_metric(
  2121. 1,
  2122. tags={"transaction": "foo_transaction"},
  2123. timestamp=self.min_ago,
  2124. )
  2125. response = self.do_request(
  2126. {
  2127. "field": [
  2128. "title",
  2129. "transaction",
  2130. "p75()",
  2131. ],
  2132. "query": "event.type:transaction",
  2133. "orderby": "p75()",
  2134. "dataset": "metrics",
  2135. "project": self.project.id,
  2136. "per_page": 50,
  2137. }
  2138. )
  2139. assert response.status_code == 200, response.content
  2140. assert len(response.data["data"]) == 1
  2141. data = response.data["data"]
  2142. meta = response.data["meta"]
  2143. field_meta = meta["fields"]
  2144. assert data[0]["title"] == "foo_transaction"
  2145. assert data[0]["transaction"] == "foo_transaction"
  2146. assert data[0]["p75()"] == 1
  2147. assert meta["isMetricsData"]
  2148. assert field_meta["title"] == "string"
  2149. assert field_meta["transaction"] == "string"
  2150. assert field_meta["p75()"] == "duration"
  2151. def test_maintain_sort_order_across_datasets(self):
  2152. self.store_transaction_metric(
  2153. 1,
  2154. tags={"transaction": "foo_transaction"},
  2155. timestamp=self.min_ago,
  2156. )
  2157. self.store_transaction_metric(
  2158. 1,
  2159. metric="user",
  2160. tags={"transaction": "bar_transaction"},
  2161. timestamp=self.min_ago,
  2162. )
  2163. self.store_transaction_metric(
  2164. 5,
  2165. tags={"transaction": "bar_transaction"},
  2166. timestamp=self.min_ago,
  2167. )
  2168. self.store_transaction_metric(
  2169. 5,
  2170. tags={"transaction": "bar_transaction"},
  2171. timestamp=self.min_ago,
  2172. )
  2173. response = self.do_request(
  2174. {
  2175. "field": [
  2176. "title",
  2177. "project",
  2178. "count()",
  2179. "count_unique(user)",
  2180. ],
  2181. "query": "event.type:transaction",
  2182. "orderby": "count()",
  2183. "dataset": "metrics",
  2184. "project": self.project.id,
  2185. "per_page": 50,
  2186. }
  2187. )
  2188. assert response.status_code == 200, response.content
  2189. data = response.data["data"]
  2190. meta = response.data["meta"]
  2191. field_meta = meta["fields"]
  2192. assert len(data) == 2
  2193. assert data[0]["title"] == "foo_transaction"
  2194. assert data[0]["count()"] == 1
  2195. assert data[0]["count_unique(user)"] == 0
  2196. assert data[1]["title"] == "bar_transaction"
  2197. assert data[1]["count()"] == 2
  2198. assert data[1]["count_unique(user)"] == 1
  2199. assert meta["isMetricsData"]
  2200. assert field_meta["title"] == "string"
  2201. assert field_meta["count()"] == "integer"
  2202. assert field_meta["count_unique(user)"] == "integer"
  2203. def test_avg_compare(self):
  2204. self.store_transaction_metric(
  2205. 100,
  2206. timestamp=self.min_ago,
  2207. tags={"release": "foo"},
  2208. )
  2209. self.store_transaction_metric(
  2210. 10,
  2211. timestamp=self.min_ago,
  2212. tags={"release": "bar"},
  2213. )
  2214. for function_name in [
  2215. "avg_compare(transaction.duration, release, foo, bar)",
  2216. 'avg_compare(transaction.duration, release, "foo", "bar")',
  2217. ]:
  2218. response = self.do_request(
  2219. {
  2220. "field": [function_name],
  2221. "query": "",
  2222. "project": self.project.id,
  2223. "dataset": "metrics",
  2224. }
  2225. )
  2226. assert response.status_code == 200, response.content
  2227. data = response.data["data"]
  2228. meta = response.data["meta"]
  2229. assert len(data) == 1
  2230. assert data[0][function_name] == -0.9
  2231. assert meta["dataset"] == "metrics"
  2232. assert meta["fields"][function_name] == "percent_change"
  2233. def test_avg_if(self):
  2234. self.store_transaction_metric(
  2235. 100,
  2236. timestamp=self.min_ago,
  2237. tags={"release": "foo"},
  2238. )
  2239. self.store_transaction_metric(
  2240. 200,
  2241. timestamp=self.min_ago,
  2242. tags={"release": "foo"},
  2243. )
  2244. self.store_transaction_metric(
  2245. 10,
  2246. timestamp=self.min_ago,
  2247. tags={"release": "bar"},
  2248. )
  2249. response = self.do_request(
  2250. {
  2251. "field": ["avg_if(transaction.duration, release, foo)"],
  2252. "query": "",
  2253. "project": self.project.id,
  2254. "dataset": "metrics",
  2255. }
  2256. )
  2257. assert response.status_code == 200, response.content
  2258. data = response.data["data"]
  2259. meta = response.data["meta"]
  2260. assert len(data) == 1
  2261. assert data[0]["avg_if(transaction.duration, release, foo)"] == 150
  2262. assert meta["dataset"] == "metrics"
  2263. assert meta["fields"]["avg_if(transaction.duration, release, foo)"] == "duration"
  2264. def test_device_class(self):
  2265. self.store_transaction_metric(
  2266. 100,
  2267. timestamp=self.min_ago,
  2268. tags={"device.class": "1"},
  2269. )
  2270. self.store_transaction_metric(
  2271. 200,
  2272. timestamp=self.min_ago,
  2273. tags={"device.class": "2"},
  2274. )
  2275. self.store_transaction_metric(
  2276. 300,
  2277. timestamp=self.min_ago,
  2278. tags={"device.class": ""},
  2279. )
  2280. response = self.do_request(
  2281. {
  2282. "field": ["device.class", "p95()"],
  2283. "query": "",
  2284. "orderby": "p95()",
  2285. "project": self.project.id,
  2286. "dataset": "metrics",
  2287. }
  2288. )
  2289. assert response.status_code == 200, response.content
  2290. data = response.data["data"]
  2291. meta = response.data["meta"]
  2292. assert len(data) == 3
  2293. # Need to actually check the dict since the level for 1 isn't guaranteed to stay `low` or `medium`
  2294. assert data[0]["device.class"] == map_device_class_level("1")
  2295. assert data[1]["device.class"] == map_device_class_level("2")
  2296. assert data[2]["device.class"] == "Unknown"
  2297. assert meta["fields"]["device.class"] == "string"
  2298. def test_device_class_filter(self):
  2299. self.store_transaction_metric(
  2300. 300,
  2301. timestamp=self.min_ago,
  2302. tags={"device.class": "1"},
  2303. )
  2304. # Need to actually check the dict since the level for 1 isn't guaranteed to stay `low`
  2305. level = map_device_class_level("1")
  2306. response = self.do_request(
  2307. {
  2308. "field": ["device.class", "count()"],
  2309. "query": f"device.class:{level}",
  2310. "orderby": "count()",
  2311. "project": self.project.id,
  2312. "dataset": "metrics",
  2313. }
  2314. )
  2315. assert response.status_code == 200, response.content
  2316. data = response.data["data"]
  2317. meta = response.data["meta"]
  2318. assert len(data) == 1
  2319. assert data[0]["device.class"] == level
  2320. assert meta["fields"]["device.class"] == "string"
  2321. class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithOnDemandMetrics(
  2322. MetricsEnhancedPerformanceTestCase
  2323. ):
  2324. viewname = "sentry-api-0-organization-events"
  2325. def setUp(self):
  2326. super().setUp()
  2327. def do_request(self, query):
  2328. self.login_as(user=self.user)
  2329. url = reverse(
  2330. self.viewname,
  2331. kwargs={"organization_slug": self.organization.slug},
  2332. )
  2333. with self.feature(
  2334. {
  2335. "organizations:on-demand-metrics-extraction": True, # XXX: We have coupling
  2336. "organizations:on-demand-metrics-extraction-widgets": True,
  2337. }
  2338. ):
  2339. return self.client.get(url, query, format="json")
  2340. def _test_is_metrics_extracted_data(
  2341. self, params: dict[str, Any], expected_on_demand_query: bool, dataset: str
  2342. ) -> None:
  2343. spec = OnDemandMetricSpec(
  2344. field="count()",
  2345. query="transaction.duration:>1s",
  2346. spec_type=MetricSpecType.DYNAMIC_QUERY,
  2347. )
  2348. self.store_on_demand_metric(1, spec=spec)
  2349. response = self.do_request(params)
  2350. assert response.status_code == 200, response.content
  2351. meta = response.data["meta"]
  2352. assert meta.get("isMetricsExtractedData", False) is expected_on_demand_query
  2353. assert meta["dataset"] == dataset
  2354. return meta
  2355. def test_is_metrics_extracted_data_is_included(self):
  2356. self._test_is_metrics_extracted_data(
  2357. {
  2358. "field": ["count()"],
  2359. "dataset": "metricsEnhanced",
  2360. "query": "transaction.duration:>=91",
  2361. "useOnDemandMetrics": "true",
  2362. "yAxis": "count()",
  2363. },
  2364. expected_on_demand_query=True,
  2365. dataset="metricsEnhanced",
  2366. )
  2367. def test_is_metrics_extracted_data_is_excluded(self):
  2368. self._test_is_metrics_extracted_data(
  2369. {
  2370. "field": ["count()"],
  2371. "query": "transaction.duration:>=91",
  2372. "useOnDemandMetrics": "true",
  2373. "yAxis": "count()",
  2374. },
  2375. # Since we do not include metricsEnhanced dataset it will fail
  2376. expected_on_demand_query=False,
  2377. dataset="discover",
  2378. )
  2379. class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithMetricLayer(
  2380. OrganizationEventsMetricsEnhancedPerformanceEndpointTest
  2381. ):
  2382. def setUp(self):
  2383. super().setUp()
  2384. self.features["organizations:use-metrics-layer"] = True
  2385. @pytest.mark.xfail(reason="Not supported")
  2386. def test_time_spent(self):
  2387. super().test_time_spent()
  2388. @pytest.mark.xfail(reason="Not supported")
  2389. def test_http_error_rate(self):
  2390. super().test_http_error_rate()
  2391. @pytest.mark.xfail(reason="Multiple aliases to same column not supported")
  2392. def test_title_and_transaction_alias(self):
  2393. super().test_title_and_transaction_alias()
  2394. @pytest.mark.xfail(reason="Sort order is flaking when querying multiple datasets")
  2395. def test_maintain_sort_order_across_datasets(self):
  2396. """You may need to run this test a few times to get it to fail"""
  2397. super().test_maintain_sort_order_across_datasets()
  2398. @pytest.mark.xfail(reason="Not implemented")
  2399. def test_avg_compare(self):
  2400. super().test_avg_compare()
  2401. @pytest.mark.xfail(reason="Not implemented")
  2402. def test_avg_if(self):
  2403. super().test_avg_if()
  2404. @pytest.mark.xfail(reason="Not implemented")
  2405. def test_device_class(self):
  2406. super().test_device_class()
  2407. @pytest.mark.xfail(reason="Not implemented")
  2408. def test_device_class_filter(self):
  2409. super().test_device_class_filter()