test_organization_events_mep.py 116 KB

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