test_organization_events_mep.py 114 KB

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