test_organization_events_mep.py 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290
  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. class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithOnDemandMetrics(
  2820. MetricsEnhancedPerformanceTestCase
  2821. ):
  2822. viewname = "sentry-api-0-organization-events"
  2823. def setUp(self) -> None:
  2824. super().setUp()
  2825. def do_request(self, query: Any) -> Any:
  2826. self.login_as(user=self.user)
  2827. url = reverse(
  2828. self.viewname,
  2829. kwargs={"organization_slug": self.organization.slug},
  2830. )
  2831. with self.feature({"organizations:on-demand-metrics-extraction-widgets": True}):
  2832. return self.client.get(url, query, format="json")
  2833. def _on_demand_query_check(
  2834. self,
  2835. params: dict[str, Any],
  2836. groupbys: list[str] | None = None,
  2837. expected_on_demand_query: bool | None = True,
  2838. expected_dataset: str | None = "metricsEnhanced",
  2839. ) -> Response:
  2840. """Do a request to the events endpoint with metrics enhanced and on-demand enabled."""
  2841. for field in params["field"]:
  2842. spec = OnDemandMetricSpec(
  2843. field=field,
  2844. query=params["query"],
  2845. environment=params.get("environment"),
  2846. groupbys=groupbys,
  2847. spec_type=MetricSpecType.DYNAMIC_QUERY,
  2848. )
  2849. # Expected parameters for this helper function
  2850. params["dataset"] = "metricsEnhanced"
  2851. params["useOnDemandMetrics"] = "true"
  2852. params["onDemandType"] = "dynamic_query"
  2853. self.store_on_demand_metric(1, spec=spec)
  2854. response = self.do_request(params)
  2855. assert response.status_code == 200, response.content
  2856. meta = response.data["meta"]
  2857. assert meta.get("isMetricsExtractedData", False) is expected_on_demand_query
  2858. assert meta["dataset"] == expected_dataset
  2859. return response
  2860. def test_is_metrics_extracted_data_is_included(self) -> None:
  2861. self._on_demand_query_check(
  2862. {"field": ["count()"], "query": "transaction.duration:>=91", "yAxis": "count()"}
  2863. )
  2864. def test_transaction_user_misery(self) -> None:
  2865. resp = self._on_demand_query_check(
  2866. {
  2867. "field": ["user_misery(300)", "apdex(300)"],
  2868. "project": self.project.id,
  2869. "query": "",
  2870. "sort": "-user_misery(300)",
  2871. "per_page": "20",
  2872. "referrer": "api.dashboards.tablewidget",
  2873. },
  2874. groupbys=["transaction"],
  2875. )
  2876. assert resp.data == {
  2877. "data": [{"user_misery(300)": 0.0, "apdex(300)": 0.0}],
  2878. "meta": {
  2879. "fields": {"user_misery(300)": "number", "apdex(300)": "number"},
  2880. "units": {"user_misery(300)": None, "apdex(300)": None},
  2881. "isMetricsData": True,
  2882. "isMetricsExtractedData": True,
  2883. "tips": {},
  2884. "datasetReason": "unchanged",
  2885. "dataset": "metricsEnhanced",
  2886. },
  2887. }
  2888. class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithMetricLayer(
  2889. OrganizationEventsMetricsEnhancedPerformanceEndpointTest
  2890. ):
  2891. def setUp(self):
  2892. super().setUp()
  2893. self.features["organizations:use-metrics-layer"] = True
  2894. @pytest.mark.xfail(reason="Not supported")
  2895. def test_time_spent(self):
  2896. super().test_time_spent()
  2897. @pytest.mark.xfail(reason="Not supported")
  2898. def test_http_error_rate(self):
  2899. super().test_http_error_rate()
  2900. @pytest.mark.xfail(reason="Multiple aliases to same column not supported")
  2901. def test_title_and_transaction_alias(self):
  2902. super().test_title_and_transaction_alias()
  2903. @pytest.mark.xfail(reason="Sort order is flaking when querying multiple datasets")
  2904. def test_maintain_sort_order_across_datasets(self):
  2905. """You may need to run this test a few times to get it to fail"""
  2906. super().test_maintain_sort_order_across_datasets()
  2907. @pytest.mark.xfail(reason="Not implemented")
  2908. def test_avg_compare(self):
  2909. super().test_avg_compare()
  2910. @pytest.mark.xfail(reason="Not implemented")
  2911. def test_avg_if(self):
  2912. super().test_avg_if()
  2913. @pytest.mark.xfail(reason="Not implemented")
  2914. def test_device_class(self):
  2915. super().test_device_class()
  2916. @pytest.mark.xfail(reason="Not implemented")
  2917. def test_device_class_filter(self):
  2918. super().test_device_class_filter()
  2919. @pytest.mark.xfail(reason="Not implemented")
  2920. def test_performance_score(self):
  2921. super().test_performance_score()
  2922. @pytest.mark.xfail(reason="Not implemented")
  2923. def test_performance_score_boundaries(self):
  2924. super().test_performance_score()
  2925. @pytest.mark.xfail(reason="Not implemented")
  2926. def test_weighted_performance_score(self):
  2927. super().test_weighted_performance_score()
  2928. @pytest.mark.xfail(reason="Not implemented")
  2929. def test_invalid_performance_score_column(self):
  2930. super().test_invalid_performance_score_column()
  2931. @pytest.mark.xfail(reason="Not implemented")
  2932. def test_invalid_weighted_performance_score_column(self):
  2933. super().test_invalid_weighted_performance_score_column()
  2934. @pytest.mark.xfail(reason="Not implemented")
  2935. def test_no_weighted_performance_score_column(self):
  2936. super().test_invalid_weighted_performance_score_column()
  2937. @pytest.mark.xfail(reason="Not implemented")
  2938. def test_opportunity_score(self):
  2939. super().test_opportunity_score()
  2940. @pytest.mark.xfail(reason="Not implemented")
  2941. def test_count_scores(self):
  2942. super().test_count_scores()
  2943. @pytest.mark.xfail(reason="Not implemented")
  2944. def test_count_starts(self):
  2945. super().test_count_starts()
  2946. @pytest.mark.xfail(reason="Not implemented")
  2947. def test_timestamp_groupby(self):
  2948. super().test_timestamp_groupby()
  2949. @pytest.mark.xfail(reason="Not implemented")
  2950. def test_on_demand_with_mep(self):
  2951. super().test_on_demand_with_mep()