test_organization_events_mep.py 139 KB

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