123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954 |
- from typing import Any
- from unittest import mock
- import pytest
- from django.urls import reverse
- from rest_framework.response import Response
- from sentry.discover.models import DatasetSourcesTypes, TeamKeyTransaction
- from sentry.models.dashboard_widget import DashboardWidgetTypes
- from sentry.models.projectteam import ProjectTeam
- from sentry.models.transaction_threshold import (
- ProjectTransactionThreshold,
- ProjectTransactionThresholdOverride,
- TransactionMetric,
- )
- from sentry.search.events import constants
- from sentry.search.utils import map_device_class_level
- from sentry.snuba.metrics.extraction import (
- SPEC_VERSION_TWO_FLAG,
- MetricSpecType,
- OnDemandMetricSpec,
- OnDemandMetricSpecVersioning,
- )
- from sentry.snuba.metrics.naming_layer.mri import TransactionMRI
- from sentry.snuba.metrics.naming_layer.public import TransactionMetricKey
- from sentry.snuba.utils import DATASET_OPTIONS
- from sentry.testutils.cases import MetricsEnhancedPerformanceTestCase
- from sentry.testutils.helpers.datetime import before_now, iso_format
- from sentry.testutils.helpers.discover import user_misery_formula
- from sentry.testutils.helpers.on_demand import create_widget
- from sentry.utils.samples import load_data
- pytestmark = pytest.mark.sentry_metrics
- class OrganizationEventsMetricsEnhancedPerformanceEndpointTest(MetricsEnhancedPerformanceTestCase):
- viewname = "sentry-api-0-organization-events"
- # Poor intentionally omitted for test_measurement_rating_that_does_not_exist
- METRIC_STRINGS = [
- "foo_transaction",
- "bar_transaction",
- "baz_transaction",
- "staging",
- "measurement_rating",
- "good",
- "meh",
- "d:transactions/measurements.something_custom@millisecond",
- "d:transactions/measurements.runtime@hour",
- "d:transactions/measurements.bytes_transfered@byte",
- "d:transactions/measurements.datacenter_memory@petabyte",
- "d:transactions/measurements.custom.kilobyte@kilobyte",
- "d:transactions/measurements.longtaskcount@none",
- "d:transactions/measurements.percent@ratio",
- "d:transactions/measurements.custom_type@somethingcustom",
- ]
- def setUp(self):
- super().setUp()
- self.transaction_data = load_data("transaction", timestamp=before_now(minutes=1))
- self.features = {
- "organizations:performance-use-metrics": True,
- }
- def do_request(self, query, features=None):
- if features is None:
- features = {"organizations:discover-basic": True}
- features.update(self.features)
- self.login_as(user=self.user)
- url = reverse(
- self.viewname,
- kwargs={"organization_id_or_slug": self.organization.slug},
- )
- with self.feature(features):
- return self.client.get(url, query, format="json")
- def test_no_projects(self):
- response = self.do_request(
- {
- "dataset": "metricsEnhanced",
- }
- )
- assert response.status_code == 200, response.content
- def test_invalid_dataset(self):
- response = self.do_request(
- {
- "dataset": "aFakeDataset",
- "project": self.project.id,
- }
- )
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == f"dataset must be one of: {', '.join([key for key in DATASET_OPTIONS.keys()])}"
- )
- def test_out_of_retention(self):
- self.create_project()
- with self.options({"system.event-retention-days": 10}):
- query = {
- "field": ["id", "timestamp"],
- "orderby": ["-timestamp", "-id"],
- "query": "event.type:transaction",
- "start": iso_format(before_now(days=20)),
- "end": iso_format(before_now(days=15)),
- "dataset": "metricsEnhanced",
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert response.data["detail"] == "Invalid date range. Please try a more recent date range."
- def test_invalid_search_terms(self):
- response = self.do_request(
- {
- "field": ["epm()"],
- "query": "hi \n there",
- "project": self.project.id,
- "dataset": "metricsEnhanced",
- }
- )
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == "Parse error at 'hi \n ther' (column 4). This is commonly caused by unmatched parentheses. Enclose any text in double quotes."
- )
- def test_percentile_with_no_data(self):
- response = self.do_request(
- {
- "field": ["p50()"],
- "query": "",
- "project": self.project.id,
- "dataset": "metricsEnhanced",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p50()"] == 0
- def test_project_name(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["project.name", "environment", "epm()"],
- "query": "event.type:transaction",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["project.name"] == self.project.slug
- assert "project.id" not in data[0]
- assert data[0]["environment"] == "staging"
- assert meta["isMetricsData"]
- assert field_meta["project.name"] == "string"
- assert field_meta["environment"] == "string"
- assert field_meta["epm()"] == "rate"
- def test_project_id(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["project_id", "environment", "epm()"],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["project_id"] == self.project.id
- assert data[0]["environment"] == "staging"
- assert meta["isMetricsData"]
- assert field_meta["project_id"] == "integer"
- assert field_meta["environment"] == "string"
- assert field_meta["epm()"] == "rate"
- def test_project_dot_id(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["project.id", "environment", "epm()"],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["project.id"] == self.project.id
- assert data[0]["environment"] == "staging"
- assert meta["isMetricsData"]
- assert field_meta["project.id"] == "integer"
- assert field_meta["environment"] == "string"
- assert field_meta["epm()"] == "rate"
- def test_title_alias(self):
- """title is an alias to transaction name"""
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["title", "p50()"],
- "query": "event.type:transaction",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["title"] == "foo_transaction"
- assert data[0]["p50()"] == 1
- assert meta["isMetricsData"]
- assert field_meta["title"] == "string"
- assert field_meta["p50()"] == "duration"
- def test_having_condition(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- # shouldn't show up
- 100,
- tags={"environment": "staging", "transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["transaction", "project", "p50(transaction.duration)"],
- "query": "event.type:transaction p50(transaction.duration):<50",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["project"] == self.project.slug
- assert data[0]["p50(transaction.duration)"] == 1
- assert meta["isMetricsData"]
- assert field_meta["transaction"] == "string"
- assert field_meta["project"] == "string"
- assert field_meta["p50(transaction.duration)"] == "duration"
- def test_having_condition_with_preventing_aggregates(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- tags={"environment": "staging", "transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["transaction", "project", "p50(transaction.duration)"],
- "query": "event.type:transaction p50(transaction.duration):<50",
- "dataset": "metricsEnhanced",
- "preventMetricAggregates": "1",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert not meta["isMetricsData"]
- assert field_meta["transaction"] == "string"
- assert field_meta["project"] == "string"
- assert field_meta["p50(transaction.duration)"] == "duration"
- def test_having_condition_with_preventing_aggregate_metrics_only(self):
- """same as the previous test, but with the dataset on explicit metrics
- which should throw a 400 error instead"""
- response = self.do_request(
- {
- "field": ["transaction", "project", "p50(transaction.duration)"],
- "query": "event.type:transaction p50(transaction.duration):<50",
- "dataset": "metrics",
- "preventMetricAggregates": "1",
- "per_page": 50,
- "project": self.project.id,
- }
- )
- assert response.status_code == 400, response.content
- def test_having_condition_not_selected(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- # shouldn't show up
- 100,
- tags={"environment": "staging", "transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["transaction", "project", "p50(transaction.duration)"],
- "query": "event.type:transaction p75(transaction.duration):<50",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["project"] == self.project.slug
- assert data[0]["p50(transaction.duration)"] == 1
- assert meta["isMetricsData"]
- assert field_meta["transaction"] == "string"
- assert field_meta["project"] == "string"
- assert field_meta["p50(transaction.duration)"] == "duration"
- def test_non_metrics_tag_with_implicit_format(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["test", "p50(transaction.duration)"],
- "query": "event.type:transaction",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- assert not response.data["meta"]["isMetricsData"]
- def test_non_metrics_tag_with_implicit_format_metrics_dataset(self):
- self.store_transaction_metric(
- 1,
- tags={"environment": "staging", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["test", "p50(transaction.duration)"],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 400, response.content
- @pytest.mark.querybuilder
- def test_performance_homepage_query(self):
- self.store_transaction_metric(
- 1,
- tags={
- "transaction": "foo_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- "measurements.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 2,
- "measurements.lcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 3,
- "measurements.fid",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 4,
- "measurements.cls",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- "user",
- tags={
- "transaction": "foo_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_FRUSTRATED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- for dataset in ["metrics", "metricsEnhanced"]:
- response = self.do_request(
- {
- "field": [
- "transaction",
- "project",
- "tpm()",
- "p75(measurements.fcp)",
- "p75(measurements.lcp)",
- "p75(measurements.fid)",
- "p75(measurements.cls)",
- "count_unique(user)",
- "apdex()",
- "count_miserable(user)",
- "user_misery()",
- "failure_rate()",
- "failure_count()",
- ],
- "orderby": "tpm()",
- "query": "event.type:transaction",
- "dataset": dataset,
- "per_page": 50,
- }
- )
- assert len(response.data["data"]) == 1
- data = response.data["data"][0]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data["transaction"] == "foo_transaction"
- assert data["project"] == self.project.slug
- assert data["p75(measurements.fcp)"] == 1.0
- assert data["p75(measurements.lcp)"] == 2.0
- assert data["p75(measurements.fid)"] == 3.0
- assert data["p75(measurements.cls)"] == 4.0
- assert data["apdex()"] == 1.0
- assert data["count_miserable(user)"] == 1.0
- assert data["user_misery()"] == 0.058
- assert data["failure_rate()"] == 1
- assert data["failure_count()"] == 1
- assert meta["isMetricsData"]
- assert field_meta["transaction"] == "string"
- assert field_meta["project"] == "string"
- assert field_meta["p75(measurements.fcp)"] == "duration"
- assert field_meta["p75(measurements.lcp)"] == "duration"
- assert field_meta["p75(measurements.fid)"] == "duration"
- assert field_meta["p75(measurements.cls)"] == "number"
- assert field_meta["apdex()"] == "number"
- assert field_meta["count_miserable(user)"] == "integer"
- assert field_meta["user_misery()"] == "number"
- assert field_meta["failure_rate()"] == "percentage"
- assert field_meta["failure_count()"] == "integer"
- assert field_meta["tpm()"] == "rate"
- assert meta["units"]["tpm()"] == "1/minute"
- def test_user_misery_and_team_key_sort(self):
- self.store_transaction_metric(
- 1,
- tags={
- "transaction": "foo_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- "measurements.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 2,
- "measurements.lcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 3,
- "measurements.fid",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 4,
- "measurements.cls",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- "user",
- tags={
- "transaction": "foo_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_FRUSTRATED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "team_key_transaction",
- "transaction",
- "project",
- "tpm()",
- "p75(measurements.fcp)",
- "p75(measurements.lcp)",
- "p75(measurements.fid)",
- "p75(measurements.cls)",
- "count_unique(user)",
- "apdex()",
- "count_miserable(user)",
- "user_misery()",
- "failure_rate()",
- "failure_count()",
- ],
- "orderby": ["team_key_transaction", "user_misery()"],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"][0]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data["transaction"] == "foo_transaction"
- assert data["project"] == self.project.slug
- assert data["p75(measurements.fcp)"] == 1.0
- assert data["p75(measurements.lcp)"] == 2.0
- assert data["p75(measurements.fid)"] == 3.0
- assert data["p75(measurements.cls)"] == 4.0
- assert data["apdex()"] == 1.0
- assert data["count_miserable(user)"] == 1.0
- assert data["user_misery()"] == 0.058
- assert data["failure_rate()"] == 1
- assert data["failure_count()"] == 1
- assert meta["isMetricsData"]
- assert field_meta["transaction"] == "string"
- assert field_meta["project"] == "string"
- assert field_meta["p75(measurements.fcp)"] == "duration"
- assert field_meta["p75(measurements.lcp)"] == "duration"
- assert field_meta["p75(measurements.fid)"] == "duration"
- assert field_meta["p75(measurements.cls)"] == "number"
- assert field_meta["apdex()"] == "number"
- assert field_meta["count_miserable(user)"] == "integer"
- assert field_meta["user_misery()"] == "number"
- assert field_meta["failure_rate()"] == "percentage"
- assert field_meta["failure_count()"] == "integer"
- def test_no_team_key_transactions(self):
- self.store_transaction_metric(
- 1, tags={"transaction": "foo_transaction"}, timestamp=self.min_ago
- )
- self.store_transaction_metric(
- 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- # TODO sort by transaction here once that's possible for order to match the same test without metrics
- "orderby": "p95()",
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "p95()",
- ],
- "per_page": 50,
- "dataset": "metricsEnhanced",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "foo_transaction"
- assert data[1]["team_key_transaction"] == 0
- assert data[1]["transaction"] == "bar_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- def test_team_key_transactions_my_teams(self):
- team1 = self.create_team(organization=self.organization, name="Team A")
- self.create_team_membership(team1, user=self.user)
- self.project.add_team(team1)
- team2 = self.create_team(organization=self.organization, name="Team B")
- self.project.add_team(team2)
- key_transactions = [
- (team1, "foo_transaction"),
- (team2, "baz_transaction"),
- ]
- # Not a key transaction
- self.store_transaction_metric(
- 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
- )
- for team, transaction in key_transactions:
- self.store_transaction_metric(
- 1, tags={"transaction": transaction}, timestamp=self.min_ago
- )
- TeamKeyTransaction.objects.create(
- organization=self.organization,
- transaction=transaction,
- project_team=ProjectTeam.objects.get(project=self.project, team=team),
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "p95()",
- ],
- "per_page": 50,
- "dataset": "metricsEnhanced",
- }
- query["orderby"] = ["team_key_transaction", "p95()"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "baz_transaction"
- assert data[1]["team_key_transaction"] == 0
- assert data[1]["transaction"] == "bar_transaction"
- assert data[2]["team_key_transaction"] == 1
- assert data[2]["transaction"] == "foo_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # not specifying any teams should use my teams
- query = {
- "project": [self.project.id],
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "p95()",
- ],
- "per_page": 50,
- "dataset": "metricsEnhanced",
- }
- query["orderby"] = ["team_key_transaction", "p95()"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "baz_transaction"
- assert data[1]["team_key_transaction"] == 0
- assert data[1]["transaction"] == "bar_transaction"
- assert data[2]["team_key_transaction"] == 1
- assert data[2]["transaction"] == "foo_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- def test_team_key_transactions_orderby(self):
- team1 = self.create_team(organization=self.organization, name="Team A")
- team2 = self.create_team(organization=self.organization, name="Team B")
- key_transactions = [
- (team1, "foo_transaction", 1),
- (team2, "baz_transaction", 100),
- ]
- # Not a key transaction
- self.store_transaction_metric(
- 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
- )
- for team, transaction, value in key_transactions:
- self.store_transaction_metric(
- value, tags={"transaction": transaction}, timestamp=self.min_ago
- )
- self.create_team_membership(team, user=self.user)
- self.project.add_team(team)
- TeamKeyTransaction.objects.create(
- organization=self.organization,
- transaction=transaction,
- project_team=ProjectTeam.objects.get(project=self.project, team=team),
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "p95()",
- ],
- "per_page": 50,
- "dataset": "metricsEnhanced",
- }
- # test ascending order
- query["orderby"] = ["team_key_transaction", "p95()"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "bar_transaction"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "foo_transaction"
- assert data[2]["team_key_transaction"] == 1
- assert data[2]["transaction"] == "baz_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # test descending order
- query["orderby"] = ["-team_key_transaction", "p95()"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "foo_transaction"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "baz_transaction"
- assert data[2]["team_key_transaction"] == 0
- assert data[2]["transaction"] == "bar_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- def test_team_key_transactions_query(self):
- team1 = self.create_team(organization=self.organization, name="Team A")
- team2 = self.create_team(organization=self.organization, name="Team B")
- key_transactions = [
- (team1, "foo_transaction", 1),
- (team2, "baz_transaction", 100),
- ]
- # Not a key transaction
- self.store_transaction_metric(
- 100, tags={"transaction": "bar_transaction"}, timestamp=self.min_ago
- )
- for team, transaction, value in key_transactions:
- self.store_transaction_metric(
- value, tags={"transaction": transaction}, timestamp=self.min_ago
- )
- self.create_team_membership(team, user=self.user)
- self.project.add_team(team)
- TeamKeyTransaction.objects.create(
- organization=self.organization,
- transaction=transaction,
- project_team=ProjectTeam.objects.get(project=self.project, team=team),
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- # use the order by to ensure the result order
- "orderby": "p95()",
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "p95()",
- ],
- "per_page": 50,
- "dataset": "metricsEnhanced",
- }
- # key transactions
- query["query"] = "has:team_key_transaction"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "foo_transaction"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "baz_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # key transactions
- query["query"] = "team_key_transaction:true"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "foo_transaction"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "baz_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # not key transactions
- query["query"] = "!has:team_key_transaction"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "bar_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # not key transactions
- query["query"] = "team_key_transaction:false"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "bar_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- def test_team_key_transaction_not_exists(self):
- team1 = self.create_team(organization=self.organization, name="Team A")
- team2 = self.create_team(organization=self.organization, name="Team B")
- key_transactions = [
- (team1, "foo_transaction", 1),
- (team2, "baz_transaction", 100),
- ]
- for team, transaction, value in key_transactions:
- self.store_transaction_metric(
- value, tags={"transaction": transaction}, timestamp=self.min_ago
- )
- self.create_team_membership(team, user=self.user)
- self.project.add_team(team)
- TeamKeyTransaction.objects.create(
- organization=self.organization,
- transaction=transaction,
- project_team=ProjectTeam.objects.get(project=self.project, team=team),
- )
- # Don't create a metric for this one
- TeamKeyTransaction.objects.create(
- organization=self.organization,
- transaction="not_in_metrics",
- project_team=ProjectTeam.objects.get(project=self.project, team=team1),
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- # use the order by to ensure the result order
- "orderby": "p95()",
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "p95()",
- ],
- "per_page": 50,
- "dataset": "metricsEnhanced",
- }
- # key transactions
- query["query"] = "has:team_key_transaction"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "foo_transaction"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "baz_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # key transactions
- query["query"] = "team_key_transaction:true"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "foo_transaction"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "baz_transaction"
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # not key transactions
- query["query"] = "!has:team_key_transaction"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- # not key transactions
- query["query"] = "team_key_transaction:false"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert meta["isMetricsData"]
- assert field_meta["team_key_transaction"] == "boolean"
- assert field_meta["transaction"] == "string"
- def test_too_many_team_key_transactions(self):
- MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS = 1
- with mock.patch(
- "sentry.search.events.fields.MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS",
- MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS,
- ):
- team = self.create_team(organization=self.organization, name="Team A")
- self.create_team_membership(team, user=self.user)
- self.project.add_team(team)
- project_team = ProjectTeam.objects.get(project=self.project, team=team)
- transactions = ["foo_transaction", "bar_transaction", "baz_transaction"]
- for i in range(MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS + 1):
- self.store_transaction_metric(
- 100, tags={"transaction": transactions[i]}, timestamp=self.min_ago
- )
- TeamKeyTransaction.objects.bulk_create(
- [
- TeamKeyTransaction(
- organization=self.organization,
- project_team=project_team,
- transaction=transactions[i],
- )
- for i in range(MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS + 1)
- ]
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- "orderby": "p95()",
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "p95()",
- ],
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- assert (
- sum(row["team_key_transaction"] for row in data)
- == MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS
- )
- assert meta["isMetricsData"]
- def test_measurement_rating(self):
- self.store_transaction_metric(
- 50,
- metric="measurements.lcp",
- tags={"measurement_rating": "good", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 15,
- metric="measurements.fp",
- tags={"measurement_rating": "good", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1500,
- metric="measurements.fcp",
- tags={"measurement_rating": "meh", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 125,
- metric="measurements.fid",
- tags={"measurement_rating": "meh", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.15,
- metric="measurements.cls",
- tags={"measurement_rating": "good", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "count_web_vitals(measurements.lcp, good)",
- "count_web_vitals(measurements.fp, good)",
- "count_web_vitals(measurements.fcp, meh)",
- "count_web_vitals(measurements.fid, meh)",
- "count_web_vitals(measurements.cls, good)",
- "count_web_vitals(measurements.lcp, any)",
- ],
- "query": "event.type:transaction",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["count_web_vitals(measurements.lcp, good)"] == 1
- assert data[0]["count_web_vitals(measurements.fp, good)"] == 1
- assert data[0]["count_web_vitals(measurements.fcp, meh)"] == 1
- assert data[0]["count_web_vitals(measurements.fid, meh)"] == 1
- assert data[0]["count_web_vitals(measurements.cls, good)"] == 1
- assert data[0]["count_web_vitals(measurements.lcp, any)"] == 1
- assert meta["isMetricsData"]
- assert field_meta["count_web_vitals(measurements.lcp, good)"] == "integer"
- assert field_meta["count_web_vitals(measurements.fp, good)"] == "integer"
- assert field_meta["count_web_vitals(measurements.fcp, meh)"] == "integer"
- assert field_meta["count_web_vitals(measurements.fid, meh)"] == "integer"
- assert field_meta["count_web_vitals(measurements.cls, good)"] == "integer"
- assert field_meta["count_web_vitals(measurements.lcp, any)"] == "integer"
- def test_measurement_rating_that_does_not_exist(self):
- self.store_transaction_metric(
- 1,
- metric="measurements.lcp",
- tags={"measurement_rating": "good", "transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["transaction", "count_web_vitals(measurements.lcp, poor)"],
- "query": "event.type:transaction",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["count_web_vitals(measurements.lcp, poor)"] == 0
- assert meta["isMetricsData"]
- assert meta["fields"]["count_web_vitals(measurements.lcp, poor)"] == "integer"
- def test_count_web_vitals_invalid_vital(self):
- query = {
- "field": [
- "count_web_vitals(measurements.foo, poor)",
- ],
- "project": [self.project.id],
- "dataset": "metricsEnhanced",
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- query = {
- "field": [
- "count_web_vitals(tags[lcp], poor)",
- ],
- "project": [self.project.id],
- "dataset": "metricsEnhanced",
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- query = {
- "field": [
- "count_web_vitals(transaction.duration, poor)",
- ],
- "project": [self.project.id],
- "dataset": "metricsEnhanced",
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- query = {
- "field": [
- "count_web_vitals(measurements.lcp, bad)",
- ],
- "project": [self.project.id],
- "dataset": "metricsEnhanced",
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- def test_count_unique_user_returns_zero(self):
- self.store_transaction_metric(
- 50,
- metric="user",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 50,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "orderby": "p50()",
- "field": [
- "transaction",
- "count_unique(user)",
- "p50()",
- ],
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["count_unique(user)"] == 1
- assert data[1]["transaction"] == "bar_transaction"
- assert data[1]["count_unique(user)"] == 0
- assert meta["isMetricsData"]
- def test_sum_transaction_duration(self):
- self.store_transaction_metric(
- 50,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 150,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "orderby": "sum(transaction.duration)",
- "field": [
- "transaction",
- "sum(transaction.duration)",
- ],
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["sum(transaction.duration)"] == 300
- assert meta["isMetricsData"]
- def test_custom_measurements_simple(self):
- self.store_transaction_metric(
- 1,
- metric="measurements.something_custom",
- internal_metric="d:transactions/measurements.something_custom@millisecond",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "orderby": "p50(measurements.something_custom)",
- "field": [
- "transaction",
- "p50(measurements.something_custom)",
- ],
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- self.wait_for_metric_count(
- self.project,
- 1,
- metric="measurements.something_custom",
- mri="d:transactions/measurements.something_custom@millisecond",
- )
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["p50(measurements.something_custom)"] == 1
- assert meta["isMetricsData"]
- assert meta["fields"]["p50(measurements.something_custom)"] == "duration"
- assert meta["units"]["p50(measurements.something_custom)"] == "millisecond"
- def test_custom_measurement_size_meta_type(self):
- self.store_transaction_metric(
- 100,
- metric="measurements.custom_type",
- internal_metric="d:transactions/measurements.custom_type@somethingcustom",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- metric="measurements.percent",
- internal_metric="d:transactions/measurements.percent@ratio",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- metric="measurements.longtaskcount",
- internal_metric="d:transactions/measurements.longtaskcount@none",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "orderby": "p50(measurements.longtaskcount)",
- "field": [
- "transaction",
- "p50(measurements.longtaskcount)",
- "p50(measurements.percent)",
- "p50(measurements.custom_type)",
- ],
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["p50(measurements.longtaskcount)"] == 100
- assert data[0]["p50(measurements.percent)"] == 100
- assert data[0]["p50(measurements.custom_type)"] == 100
- assert meta["isMetricsData"]
- assert meta["fields"]["p50(measurements.longtaskcount)"] == "integer"
- assert meta["units"]["p50(measurements.longtaskcount)"] is None
- assert meta["fields"]["p50(measurements.percent)"] == "percentage"
- assert meta["units"]["p50(measurements.percent)"] is None
- assert meta["fields"]["p50(measurements.custom_type)"] == "number"
- assert meta["units"]["p50(measurements.custom_type)"] is None
- def test_custom_measurement_none_type(self):
- self.store_transaction_metric(
- 1,
- metric="measurements.cls",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "orderby": "p75(measurements.cls)",
- "field": [
- "transaction",
- "p75(measurements.cls)",
- "p99(measurements.cls)",
- "max(measurements.cls)",
- ],
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- self.wait_for_metric_count(
- self.project,
- 1,
- metric=TransactionMetricKey.MEASUREMENTS_CLS.value,
- mri=TransactionMRI.MEASUREMENTS_CLS.value,
- )
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["p75(measurements.cls)"] == 1
- assert data[0]["p99(measurements.cls)"] == 1
- assert data[0]["max(measurements.cls)"] == 1
- assert meta["isMetricsData"]
- assert meta["fields"]["p75(measurements.cls)"] == "number"
- assert meta["units"]["p75(measurements.cls)"] is None
- assert meta["fields"]["p99(measurements.cls)"] == "number"
- assert meta["units"]["p99(measurements.cls)"] is None
- assert meta["fields"]["max(measurements.cls)"] == "number"
- assert meta["units"]["max(measurements.cls)"] is None
- def test_custom_measurement_duration_filtering(self):
- self.store_transaction_metric(
- 1,
- metric="measurements.runtime",
- internal_metric="d:transactions/measurements.runtime@hour",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 180,
- metric="measurements.runtime",
- internal_metric="d:transactions/measurements.runtime@hour",
- entity="metrics_distributions",
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "field": [
- "transaction",
- "max(measurements.runtime)",
- ],
- "query": "p50(measurements.runtime):>1wk",
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "bar_transaction"
- assert data[0]["max(measurements.runtime)"] == 180
- assert meta["isMetricsData"]
- def test_custom_measurement_size_filtering(self):
- self.store_transaction_metric(
- 1,
- metric="measurements.datacenter_memory",
- internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- metric="measurements.datacenter_memory",
- internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
- entity="metrics_distributions",
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "field": [
- "transaction",
- "max(measurements.datacenter_memory)",
- ],
- "query": "p50(measurements.datacenter_memory):>5pb",
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "bar_transaction"
- assert data[0]["max(measurements.datacenter_memory)"] == 100
- assert meta["units"]["max(measurements.datacenter_memory)"] == "petabyte"
- assert meta["fields"]["max(measurements.datacenter_memory)"] == "size"
- assert meta["isMetricsData"]
- def test_has_custom_measurement(self):
- self.store_transaction_metric(
- 33,
- metric="measurements.datacenter_memory",
- internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- transaction_data = load_data("transaction", timestamp=self.min_ago)
- transaction_data["measurements"]["datacenter_memory"] = {
- "value": 33,
- "unit": "petabyte",
- }
- self.store_event(transaction_data, self.project.id)
- measurement = "measurements.datacenter_memory"
- response = self.do_request(
- {
- "field": ["transaction", measurement],
- "query": "has:measurements.datacenter_memory",
- "dataset": "discover",
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- response = self.do_request(
- {
- "field": ["transaction", measurement],
- "query": "!has:measurements.datacenter_memory",
- "dataset": "discover",
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_environment_param(self):
- self.create_environment(self.project, name="staging")
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction", "environment": "staging"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "environment": "staging",
- "orderby": "p50(transaction.duration)",
- "field": [
- "transaction",
- "environment",
- "p50(transaction.duration)",
- ],
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["environment"] == "staging"
- assert data[0]["p50(transaction.duration)"] == 1
- assert meta["isMetricsData"]
- @pytest.mark.xfail(reason="Started failing on ClickHouse 21.8")
- def test_environment_query(self):
- self.create_environment(self.project, name="staging")
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction", "environment": "staging"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "orderby": "p50(transaction.duration)",
- "field": [
- "transaction",
- "environment",
- "p50(transaction.duration)",
- ],
- "query": "!has:environment",
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- self.wait_for_metric_count(self.project, 2)
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["environment"] is None or data[0]["environment"] == ""
- assert data[0]["p50(transaction.duration)"] == 100
- assert meta["isMetricsData"]
- def test_has_transaction(self):
- self.store_transaction_metric(
- 1,
- tags={},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "orderby": "p50(transaction.duration)",
- "field": [
- "transaction",
- "p50(transaction.duration)",
- ],
- "query": "has:transaction",
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- self.wait_for_metric_count(self.project, 2)
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "<< unparameterized >>"
- assert data[0]["p50(transaction.duration)"] == 1
- assert data[1]["transaction"] == "foo_transaction"
- assert data[1]["p50(transaction.duration)"] == 100
- assert meta["isMetricsData"]
- query = {
- "project": [self.project.id],
- "orderby": "p50(transaction.duration)",
- "field": [
- "transaction",
- "p50(transaction.duration)",
- ],
- "query": "!has:transaction",
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- def test_apdex_transaction_threshold(self):
- ProjectTransactionThresholdOverride.objects.create(
- transaction="foo_transaction",
- project=self.project,
- organization=self.project.organization,
- threshold=600,
- metric=TransactionMetric.LCP.value,
- )
- ProjectTransactionThresholdOverride.objects.create(
- transaction="bar_transaction",
- project=self.project,
- organization=self.project.organization,
- threshold=600,
- metric=TransactionMetric.LCP.value,
- )
- self.store_transaction_metric(
- 1,
- tags={
- "transaction": "foo_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- "measurements.lcp",
- tags={
- "transaction": "bar_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "apdex()",
- ],
- "orderby": ["apdex()"],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["transaction"] == "bar_transaction"
- # Threshold is lcp based
- assert data[0]["apdex()"] == 1
- assert data[1]["transaction"] == "foo_transaction"
- # Threshold is lcp based
- assert data[1]["apdex()"] == 0
- assert meta["isMetricsData"]
- assert field_meta["transaction"] == "string"
- assert field_meta["apdex()"] == "number"
- def test_apdex_project_threshold(self):
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.project.organization,
- threshold=600,
- metric=TransactionMetric.LCP.value,
- )
- self.store_transaction_metric(
- 1,
- tags={
- "transaction": "foo_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- "measurements.lcp",
- tags={
- "transaction": "bar_transaction",
- constants.METRIC_SATISFACTION_TAG_KEY: constants.METRIC_SATISFIED_TAG_VALUE,
- },
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "apdex()",
- ],
- "orderby": ["apdex()"],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["transaction"] == "bar_transaction"
- # Threshold is lcp based
- assert data[0]["apdex()"] == 1
- assert data[1]["transaction"] == "foo_transaction"
- # Threshold is lcp based
- assert data[1]["apdex()"] == 0
- assert meta["isMetricsData"]
- assert field_meta["transaction"] == "string"
- assert field_meta["apdex()"] == "number"
- def test_apdex_satisfaction_param(self):
- for function in ["apdex(300)", "user_misery(300)", "count_miserable(user, 300)"]:
- query = {
- "project": [self.project.id],
- "field": [
- "transaction",
- function,
- ],
- "statsPeriod": "24h",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- meta = response.data["meta"]
- assert not meta["isMetricsData"], function
- query = {
- "project": [self.project.id],
- "field": [
- "transaction",
- function,
- ],
- "statsPeriod": "24h",
- "dataset": "metrics",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 400, function
- assert b"threshold parameter" in response.content, function
- def test_mobile_metrics(self):
- self.store_transaction_metric(
- 0.4,
- "measurements.frames_frozen_rate",
- tags={
- "transaction": "bar_transaction",
- },
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "field": [
- "transaction",
- "p50(measurements.frames_frozen_rate)",
- ],
- "statsPeriod": "24h",
- "dataset": "metrics",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["p50(measurements.frames_frozen_rate)"] == 0.4
- def test_merge_null_unparam(self):
- self.store_transaction_metric(
- 1,
- # Transaction: unparam
- tags={
- "transaction": "<< unparameterized >>",
- },
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 2,
- # Transaction:null
- tags={},
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "field": [
- "transaction",
- "p50(transaction.duration)",
- ],
- "statsPeriod": "24h",
- "dataset": "metrics",
- "per_page": 50,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["p50(transaction.duration)"] == 1.5
- def test_unparam_filter(self):
- self.store_transaction_metric(
- 1,
- # Transaction: unparam
- tags={
- "transaction": "<< unparameterized >>",
- },
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 2,
- # Transaction:null
- tags={},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 3,
- tags={
- "transaction": "foo_transaction",
- },
- timestamp=self.min_ago,
- )
- query = {
- "project": [self.project.id],
- "field": [
- "transaction",
- "count()",
- ],
- "query": 'transaction:"<< unparameterized >>"',
- "statsPeriod": "24h",
- "dataset": "metrics",
- "per_page": 50,
- }
- self.wait_for_metric_count(self.project, 3)
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["transaction"] == "<< unparameterized >>"
- assert response.data["data"][0]["count()"] == 2
- def test_custom_measurements_without_function(self):
- self.store_transaction_metric(
- 33,
- metric="measurements.datacenter_memory",
- internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- transaction_data = load_data("transaction", timestamp=self.min_ago)
- transaction_data["measurements"]["datacenter_memory"] = {
- "value": 33,
- "unit": "petabyte",
- }
- self.store_event(transaction_data, self.project.id)
- measurement = "measurements.datacenter_memory"
- response = self.do_request(
- {
- "field": ["transaction", measurement],
- "query": "measurements.datacenter_memory:33pb",
- "dataset": "discover",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0][measurement] == 33
- meta = response.data["meta"]
- field_meta = meta["fields"]
- unit_meta = meta["units"]
- assert field_meta[measurement] == "size"
- assert unit_meta[measurement] == "petabyte"
- assert not meta["isMetricsData"]
- def test_custom_measurements_with_function(self):
- self.store_transaction_metric(
- 33,
- metric="measurements.datacenter_memory",
- internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- transaction_data = load_data("transaction", timestamp=self.min_ago)
- transaction_data["measurements"]["datacenter_memory"] = {
- "value": 33,
- "unit": "petabyte",
- }
- self.store_event(transaction_data, self.project.id)
- measurement = "p50(measurements.datacenter_memory)"
- response = self.do_request(
- {
- "field": ["transaction", measurement],
- "query": "measurements.datacenter_memory:33pb",
- "dataset": "discover",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0][measurement] == 33
- meta = response.data["meta"]
- field_meta = meta["fields"]
- unit_meta = meta["units"]
- assert field_meta[measurement] == "size"
- assert unit_meta[measurement] == "petabyte"
- assert not meta["isMetricsData"]
- def test_custom_measurements_equation(self):
- self.store_transaction_metric(
- 33,
- metric="measurements.datacenter_memory",
- internal_metric="d:transactions/measurements.datacenter_memory@petabyte",
- entity="metrics_distributions",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- transaction_data = load_data("transaction", timestamp=self.min_ago)
- transaction_data["measurements"]["datacenter_memory"] = {
- "value": 33,
- "unit": "petabyte",
- }
- self.store_event(transaction_data, self.project.id)
- response = self.do_request(
- {
- "field": [
- "transaction",
- "measurements.datacenter_memory",
- "equation|measurements.datacenter_memory / 3",
- ],
- "query": "",
- "dataset": "discover",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["measurements.datacenter_memory"] == 33
- assert data[0]["equation|measurements.datacenter_memory / 3"] == 11
- meta = response.data["meta"]
- assert not meta["isMetricsData"]
- def test_transaction_wildcard(self):
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "p90()",
- ],
- "query": "transaction:foo*",
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p90()"] == 1
- meta = response.data["meta"]
- assert meta["isMetricsData"]
- assert data[0]["transaction"] == "foo_transaction"
- def test_transaction_status_wildcard(self):
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "p90()",
- ],
- "query": "transaction.status:f*bar",
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p90()"] == 1
- meta = response.data["meta"]
- assert meta["isMetricsData"]
- def test_http_error_rate(self):
- self.store_transaction_metric(
- 1,
- tags={
- "transaction": "foo_transaction",
- "transaction.status": "foobar",
- "http.status_code": "500",
- },
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- tags={"transaction": "bar_transaction", "http.status_code": "400"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "http_error_rate()",
- ],
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["http_error_rate()"] == 0.5
- meta = response.data["meta"]
- assert meta["isMetricsData"]
- def test_time_spent(self):
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "time_spent_percentage()",
- ],
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["time_spent_percentage()"] == 0.5
- meta = response.data["meta"]
- assert meta["isMetricsData"]
- def test_has_filter(self):
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "p50()",
- ],
- # For the metrics dataset, has on metrics should be no-ops
- "query": "has:measurements.frames_frozen_rate",
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p50()"] == 1
- meta = response.data["meta"]
- assert meta["isMetricsData"]
- response = self.do_request(
- {
- "field": [
- "transaction",
- "p50()",
- ],
- "query": "has:transaction.status",
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p50()"] == 1
- meta = response.data["meta"]
- assert meta["isMetricsData"]
- def test_not_has_filter(self):
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction", "transaction.status": "foobar"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "p50()",
- ],
- "query": "!has:transaction.status",
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 0
- meta = response.data["meta"]
- assert meta["isMetricsData"]
- response = self.do_request(
- {
- "field": [
- "transaction",
- "p50()",
- ],
- # Doing !has on the metrics dataset doesn't really make sense
- "query": "!has:measurements.frames_frozen_rate",
- "dataset": "metrics",
- }
- )
- assert response.status_code == 400, response.content
- def test_p50_with_count(self):
- """Implicitly test the fact that percentiles are their own 'dataset'"""
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["title", "p50()", "count()"],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "project": self.project.id,
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["title"] == "foo_transaction"
- assert data[0]["p50()"] == 1
- assert data[0]["count()"] == 1
- assert meta["isMetricsData"]
- assert field_meta["title"] == "string"
- assert field_meta["p50()"] == "duration"
- assert field_meta["count()"] == "integer"
- def test_p75_with_count_and_more_groupby(self):
- """Implicitly test the fact that percentiles are their own 'dataset'"""
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 5,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 5,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "title",
- "project",
- "p75()",
- "count()",
- ],
- "query": "event.type:transaction",
- "orderby": "count()",
- "dataset": "metrics",
- "project": self.project.id,
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["title"] == "foo_transaction"
- assert data[0]["p75()"] == 1
- assert data[0]["count()"] == 1
- assert data[1]["title"] == "bar_transaction"
- assert data[1]["p75()"] == 5
- assert data[1]["count()"] == 2
- assert meta["isMetricsData"]
- assert field_meta["title"] == "string"
- assert field_meta["p75()"] == "duration"
- assert field_meta["count()"] == "integer"
- def test_title_and_transaction_alias(self):
- # Title and transaction are aliases to the same column
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "title",
- "transaction",
- "p75()",
- ],
- "query": "event.type:transaction",
- "orderby": "p75()",
- "dataset": "metrics",
- "project": self.project.id,
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["title"] == "foo_transaction"
- assert data[0]["transaction"] == "foo_transaction"
- assert data[0]["p75()"] == 1
- assert meta["isMetricsData"]
- assert field_meta["title"] == "string"
- assert field_meta["transaction"] == "string"
- assert field_meta["p75()"] == "duration"
- def test_maintain_sort_order_across_datasets(self):
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1,
- metric="user",
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 5,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 5,
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "title",
- "project",
- "count()",
- "count_unique(user)",
- ],
- "query": "event.type:transaction",
- "orderby": "count()",
- "dataset": "metrics",
- "project": self.project.id,
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert len(data) == 2
- assert data[0]["title"] == "foo_transaction"
- assert data[0]["count()"] == 1
- assert data[0]["count_unique(user)"] == 0
- assert data[1]["title"] == "bar_transaction"
- assert data[1]["count()"] == 2
- assert data[1]["count_unique(user)"] == 1
- assert meta["isMetricsData"]
- assert field_meta["title"] == "string"
- assert field_meta["count()"] == "integer"
- assert field_meta["count_unique(user)"] == "integer"
- def test_avg_compare(self):
- self.store_transaction_metric(
- 100,
- timestamp=self.min_ago,
- tags={"release": "foo"},
- )
- self.store_transaction_metric(
- 10,
- timestamp=self.min_ago,
- tags={"release": "bar"},
- )
- for function_name in [
- "avg_compare(transaction.duration, release, foo, bar)",
- 'avg_compare(transaction.duration, release, "foo", "bar")',
- ]:
- response = self.do_request(
- {
- "field": [function_name],
- "query": "",
- "project": self.project.id,
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0][function_name] == -0.9
- assert meta["dataset"] == "metrics"
- assert meta["fields"][function_name] == "percent_change"
- def test_avg_if(self):
- self.store_transaction_metric(
- 100,
- timestamp=self.min_ago,
- tags={"release": "foo"},
- )
- self.store_transaction_metric(
- 200,
- timestamp=self.min_ago,
- tags={"release": "foo"},
- )
- self.store_transaction_metric(
- 10,
- timestamp=self.min_ago,
- tags={"release": "bar"},
- )
- response = self.do_request(
- {
- "field": ["avg_if(transaction.duration, release, foo)"],
- "query": "",
- "project": self.project.id,
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["avg_if(transaction.duration, release, foo)"] == 150
- assert meta["dataset"] == "metrics"
- assert meta["fields"]["avg_if(transaction.duration, release, foo)"] == "duration"
- def test_count_if(self):
- self.store_transaction_metric(
- 100,
- timestamp=self.min_ago,
- tags={"release": "1.0.0"},
- )
- self.store_transaction_metric(
- 200,
- timestamp=self.min_ago,
- tags={"release": "1.0.0"},
- )
- self.store_transaction_metric(
- 10,
- timestamp=self.min_ago,
- tags={"release": "2.0.0"},
- )
- countIfRelease1 = "count_if(transaction.duration,release,1.0.0)"
- countIfRelease2 = "count_if(transaction.duration,release,2.0.0)"
- response = self.do_request(
- {
- "field": [
- countIfRelease1,
- countIfRelease2,
- ],
- "query": "",
- "project": self.project.id,
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0][countIfRelease1] == 2
- assert data[0][countIfRelease2] == 1
- assert meta["dataset"] == "metrics"
- assert meta["fields"][countIfRelease1] == "integer"
- assert meta["fields"][countIfRelease2] == "integer"
- def test_device_class(self):
- self.store_transaction_metric(
- 100,
- timestamp=self.min_ago,
- tags={"device.class": "1"},
- )
- self.store_transaction_metric(
- 200,
- timestamp=self.min_ago,
- tags={"device.class": "2"},
- )
- self.store_transaction_metric(
- 300,
- timestamp=self.min_ago,
- tags={"device.class": ""},
- )
- response = self.do_request(
- {
- "field": ["device.class", "p95()"],
- "query": "",
- "orderby": "p95()",
- "project": self.project.id,
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 3
- # Need to actually check the dict since the level for 1 isn't guaranteed to stay `low` or `medium`
- assert data[0]["device.class"] == map_device_class_level("1")
- assert data[1]["device.class"] == map_device_class_level("2")
- assert data[2]["device.class"] == "Unknown"
- assert meta["fields"]["device.class"] == "string"
- def test_device_class_filter(self):
- self.store_transaction_metric(
- 300,
- timestamp=self.min_ago,
- tags={"device.class": "1"},
- )
- # Need to actually check the dict since the level for 1 isn't guaranteed to stay `low`
- level = map_device_class_level("1")
- response = self.do_request(
- {
- "field": ["device.class", "count()"],
- "query": f"device.class:{level}",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": "metrics",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["device.class"] == level
- assert meta["fields"]["device.class"] == "string"
- def test_performance_score(self):
- self.store_transaction_metric(
- 0.03,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.30,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.35,
- metric="measurements.score.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.70,
- metric="measurements.score.weight.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.38,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.fid",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- # These fid and ttfb scenarios shouldn't really be happening, but we can test them anyways
- self.store_transaction_metric(
- 0.00,
- metric="measurements.score.weight.fid",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.00,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.00,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- # INP metrics
- self.store_transaction_metric(
- 0.80,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.weight.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.80,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "performance_score(measurements.score.fcp)",
- "performance_score(measurements.score.fid)",
- "performance_score(measurements.score.ttfb)",
- "performance_score(measurements.score.inp)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["performance_score(measurements.score.fcp)"] == 0.5
- assert data[0]["performance_score(measurements.score.fid)"] == 0
- assert data[0]["performance_score(measurements.score.ttfb)"] == 0.7923076923076923
- assert data[0]["performance_score(measurements.score.inp)"] == 0.8
- assert meta["isMetricsData"]
- assert field_meta["performance_score(measurements.score.ttfb)"] == "number"
- def test_performance_score_boundaries(self):
- # Scores shouldn't exceed 1 or go below 0, but we can test these boundaries anyways
- self.store_transaction_metric(
- 0.65,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.30,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- -0.35,
- metric="measurements.score.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.70,
- metric="measurements.score.weight.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.3,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "performance_score(measurements.score.ttfb)",
- "performance_score(measurements.score.fcp)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["performance_score(measurements.score.ttfb)"] == 1.0
- assert data[0]["performance_score(measurements.score.fcp)"] == 0.0
- assert meta["isMetricsData"]
- assert field_meta["performance_score(measurements.score.ttfb)"] == "number"
- def test_weighted_performance_score(self):
- self.store_transaction_metric(
- 0.03,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.30,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.03,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.80,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.weight.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.80,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "weighted_performance_score(measurements.score.ttfb)",
- "weighted_performance_score(measurements.score.inp)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["weighted_performance_score(measurements.score.ttfb)"] == 0.3433333333333333
- assert data[0]["weighted_performance_score(measurements.score.inp)"] == 0.26666666666666666
- assert meta["isMetricsData"]
- assert field_meta["weighted_performance_score(measurements.score.ttfb)"] == "number"
- def test_invalid_performance_score_column(self):
- self.store_transaction_metric(
- 0.03,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "performance_score(measurements.score.fp)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 400, response.content
- def test_invalid_weighted_performance_score_column(self):
- self.store_transaction_metric(
- 0.03,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "weighted_performance_score(measurements.score.fp)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 400, response.content
- def test_no_weighted_performance_score_column(self):
- self.store_transaction_metric(
- 0.0,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "weighted_performance_score(measurements.score.ttfb)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert data[0]["weighted_performance_score(measurements.score.ttfb)"] == 0.0
- assert meta["isMetricsData"]
- assert field_meta["weighted_performance_score(measurements.score.ttfb)"] == "number"
- def test_opportunity_score(self):
- self.store_transaction_metric(
- 0.03,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.30,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.40,
- metric="measurements.score.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.70,
- metric="measurements.score.weight.fcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.43,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.0,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.0,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.0,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.0,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.80,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.00,
- metric="measurements.score.weight.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.80,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "opportunity_score(measurements.score.ttfb)",
- "opportunity_score(measurements.score.inp)",
- "opportunity_score(measurements.score.total)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["opportunity_score(measurements.score.ttfb)"] == 0.27
- # Should be 0.2. Precision issue?
- assert data[0]["opportunity_score(measurements.score.inp)"] == 0.19999999999999996
- assert data[0]["opportunity_score(measurements.score.total)"] == 1.77
- assert meta["isMetricsData"]
- def test_opportunity_score_with_fixed_weights(self):
- self.store_transaction_metric(
- 0.5,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.0,
- metric="measurements.score.weight.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.2,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 1.0,
- metric="measurements.score.weight.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.2,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.5,
- metric="measurements.score.weight.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.1,
- metric="measurements.score.lcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.3,
- metric="measurements.score.weight.lcp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.2,
- metric="measurements.score.inp",
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.5,
- metric="measurements.score.weight.inp",
- tags={"transaction": "bar_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "total_opportunity_score()",
- ],
- "query": "event.type:transaction",
- "orderby": "transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["total_opportunity_score()"] == 0.029999999999999995
- assert data[1]["total_opportunity_score()"] == 0.36
- assert meta["isMetricsData"]
- def test_total_performance_score(self):
- self.store_transaction_metric(
- 0.03,
- metric="measurements.score.lcp",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.30,
- metric="measurements.score.weight.lcp",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.15,
- metric="measurements.score.fcp",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.15,
- metric="measurements.score.weight.fcp",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.10,
- metric="measurements.score.cls",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.15,
- metric="measurements.score.weight.cls",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.05,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.10,
- metric="measurements.score.weight.ttfb",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.05,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.10,
- metric="measurements.score.weight.inp",
- tags={"transaction": "foo_transaction", "transaction.op": "pageload"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "performance_score(measurements.score.total)",
- ],
- "query": "",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["performance_score(measurements.score.total)"] == 0.48
- assert meta["isMetricsData"]
- def test_count_scores(self):
- self.store_transaction_metric(
- 0.1,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.2,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.3,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.4,
- metric="measurements.score.total",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.5,
- metric="measurements.score.ttfb",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 0.8,
- metric="measurements.score.inp",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "count_scores(measurements.score.total)",
- "count_scores(measurements.score.ttfb)",
- "count_scores(measurements.score.inp)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["count_scores(measurements.score.total)"] == 4
- assert data[0]["count_scores(measurements.score.ttfb)"] == 1
- assert data[0]["count_scores(measurements.score.inp)"] == 1
- assert meta["isMetricsData"]
- def test_count_starts(self):
- self.store_transaction_metric(
- 200,
- metric="measurements.app_start_warm",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- metric="measurements.app_start_warm",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 10,
- metric="measurements.app_start_cold",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "count_starts(measurements.app_start_warm)",
- "count_starts(measurements.app_start_cold)",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["count_starts(measurements.app_start_warm)"] == 2
- assert data[0]["count_starts(measurements.app_start_cold)"] == 1
- assert meta["isMetricsData"]
- def test_count_starts_returns_all_counts_when_no_arg_is_passed(self):
- self.store_transaction_metric(
- 200,
- metric="measurements.app_start_warm",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 100,
- metric="measurements.app_start_warm",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- self.store_transaction_metric(
- 10,
- metric="measurements.app_start_cold",
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "count_total_starts()",
- ],
- "query": "event.type:transaction",
- "dataset": "metrics",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["count_total_starts()"] == 3
- assert meta["isMetricsData"]
- def test_timestamp_groupby(self):
- self.store_transaction_metric(
- 0.03,
- tags={"transaction": "foo_transaction", "user": "foo"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "timestamp",
- "count()",
- "count_unique(user)",
- ],
- "query": "event.type:transaction",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["transaction"] == "foo_transaction"
- assert meta["dataset"] == "metricsEnhanced"
- def test_on_demand_with_mep(self):
- # Store faketag as an OnDemandMetricSpec, which will put faketag into the metrics indexer
- spec = OnDemandMetricSpec(
- field="count()",
- query="user.email:blah@example.com",
- environment="prod",
- groupbys=["faketag"],
- spec_type=MetricSpecType.DYNAMIC_QUERY,
- )
- self.store_on_demand_metric(123, spec=spec)
- # This is the event that we should actually return
- transaction_data = load_data("transaction", timestamp=self.min_ago)
- transaction_data["tags"].append(("faketag", "foo"))
- self.store_event(transaction_data, self.project.id)
- with self.feature({"organizations:mep-use-default-tags": True}):
- response = self.do_request(
- {
- "field": [
- "faketag",
- "count()",
- ],
- "query": "event.type:transaction",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- meta = response.data["meta"]
- assert data[0]["faketag"] == "foo"
- assert not meta["isMetricsData"]
- def test_filtering_by_org_id_is_not_compatible(self):
- """Implicitly test the fact that percentiles are their own 'dataset'"""
- self.store_transaction_metric(
- 1,
- tags={"transaction": "foo_transaction"},
- timestamp=self.min_ago,
- )
- response = self.do_request(
- {
- "field": ["title", "p50()", "count()"],
- "query": "event.type:transaction organization_id:2",
- "dataset": "metrics",
- "project": self.project.id,
- "per_page": 50,
- }
- )
- assert response.status_code == 400, response.content
- class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithOnDemandMetrics(
- MetricsEnhancedPerformanceTestCase
- ):
- viewname = "sentry-api-0-organization-events"
- def setUp(self) -> None:
- super().setUp()
- self.url = reverse(
- self.viewname, kwargs={"organization_id_or_slug": self.organization.slug}
- )
- self.features = {"organizations:on-demand-metrics-extraction-widgets": True}
- def _create_specs(
- self, params: dict[str, Any], groupbys: list[str] | None = None
- ) -> list[OnDemandMetricSpec]:
- """Creates all specs based on the parameters that would be passed to the endpoint."""
- specs = []
- for field in params["field"]:
- spec = OnDemandMetricSpec(
- field=field,
- query=params["query"],
- environment=params.get("environment"),
- groupbys=groupbys,
- spec_type=MetricSpecType.DYNAMIC_QUERY,
- )
- specs.append(spec)
- return specs
- def _make_on_demand_request(
- self, params: dict[str, Any], extra_features: dict[str, bool] | None = None
- ) -> Response:
- """Ensures that the required parameters for an on-demand request are included."""
- # Expected parameters for this helper function
- params["dataset"] = "metricsEnhanced"
- params["useOnDemandMetrics"] = "true"
- params["onDemandType"] = "dynamic_query"
- _features = {**self.features, **(extra_features or {})}
- return self.do_request(params, features=_features)
- def _assert_on_demand_response(
- self,
- response: Response,
- expected_on_demand_query: bool | None = True,
- expected_dataset: str | None = "metricsEnhanced",
- ) -> None:
- """Basic assertions for an on-demand request."""
- assert response.status_code == 200, response.content
- meta = response.data["meta"]
- assert meta.get("isMetricsExtractedData", False) is expected_on_demand_query
- assert meta["dataset"] == expected_dataset
- def test_is_metrics_extracted_data_is_included(self) -> None:
- params = {"field": ["count()"], "query": "transaction.duration:>=91", "yAxis": "count()"}
- specs = self._create_specs(params)
- for spec in specs:
- self.store_on_demand_metric(1, spec=spec)
- response = self._make_on_demand_request(params)
- self._assert_on_demand_response(response)
- def test_on_demand_user_misery(self) -> None:
- user_misery_field = "user_misery(300)"
- query = "transaction.duration:>=100"
- # We store data for both specs, however, when the query builders try to query
- # for the data it will not query on-demand data
- for spec_version in OnDemandMetricSpecVersioning.get_spec_versions():
- spec = OnDemandMetricSpec(
- field=user_misery_field,
- query=query,
- spec_type=MetricSpecType.DYNAMIC_QUERY,
- # We only allow querying the function in the latest spec version,
- # otherwise, the data returned by the endpoint would be 0.05
- spec_version=spec_version,
- )
- tags = {"satisfaction": "miserable"}
- self.store_on_demand_metric(1, spec=spec, additional_tags=tags, timestamp=self.min_ago)
- self.store_on_demand_metric(2, spec=spec, timestamp=self.min_ago)
- params = {"field": [user_misery_field], "project": self.project.id, "query": query}
- self._create_specs(params)
- # We expect it to be False because we're not using the extra feature flag
- response = self._make_on_demand_request(params)
- self._assert_on_demand_response(response, expected_on_demand_query=False)
- # Since we're using the extra feature flag we expect user_misery to be an on-demand metric
- response = self._make_on_demand_request(params, {SPEC_VERSION_TWO_FLAG: True})
- self._assert_on_demand_response(response, expected_on_demand_query=True)
- assert response.data["data"] == [{user_misery_field: user_misery_formula(1, 2)}]
- def test_on_demand_user_misery_discover_split_with_widget_id_unsaved(self) -> None:
- user_misery_field = "user_misery(300)"
- query = "transaction.duration:>=100"
- _, widget, __ = create_widget(["count()"], "", self.project, discover_widget_split=None)
- # We store data for both specs, however, when the query builders try to query
- # for the data it will not query on-demand data
- for spec_version in OnDemandMetricSpecVersioning.get_spec_versions():
- spec = OnDemandMetricSpec(
- field=user_misery_field,
- query=query,
- spec_type=MetricSpecType.DYNAMIC_QUERY,
- # We only allow querying the function in the latest spec version,
- # otherwise, the data returned by the endpoint would be 0.05
- spec_version=spec_version,
- )
- tags = {"satisfaction": "miserable"}
- self.store_on_demand_metric(1, spec=spec, additional_tags=tags, timestamp=self.min_ago)
- self.store_on_demand_metric(2, spec=spec, timestamp=self.min_ago)
- params = {"field": [user_misery_field], "project": self.project.id, "query": query}
- self._create_specs(params)
- params["dashboardWidgetId"] = widget.id
- # Since we're using the extra feature flag we expect user_misery to be an on-demand metric
- with mock.patch.object(widget, "save") as mock_widget_save:
- response = self._make_on_demand_request(params, {SPEC_VERSION_TWO_FLAG: True})
- assert bool(mock_widget_save.assert_called_once)
- self._assert_on_demand_response(response, expected_on_demand_query=True)
- assert response.data["data"] == [{user_misery_field: user_misery_formula(1, 2)}]
- def test_on_demand_user_misery_discover_split_with_widget_id_saved(self) -> None:
- user_misery_field = "user_misery(300)"
- query = "transaction.duration:>=100"
- _, widget, __ = create_widget(
- ["count()"],
- "",
- self.project,
- discover_widget_split=DashboardWidgetTypes.TRANSACTION_LIKE, # Transactions like uses on-demand
- )
- # We store data for both specs, however, when the query builders try to query
- # for the data it will not query on-demand data
- for spec_version in OnDemandMetricSpecVersioning.get_spec_versions():
- spec = OnDemandMetricSpec(
- field=user_misery_field,
- query=query,
- spec_type=MetricSpecType.DYNAMIC_QUERY,
- # We only allow querying the function in the latest spec version,
- # otherwise, the data returned by the endpoint would be 0.05
- spec_version=spec_version,
- )
- tags = {"satisfaction": "miserable"}
- self.store_on_demand_metric(1, spec=spec, additional_tags=tags, timestamp=self.min_ago)
- self.store_on_demand_metric(2, spec=spec, timestamp=self.min_ago)
- params = {"field": [user_misery_field], "project": self.project.id, "query": query}
- self._create_specs(params)
- params["dashboardWidgetId"] = widget.id
- # Since we're using the extra feature flag we expect user_misery to be an on-demand metric
- with mock.patch.object(widget, "save") as mock_widget_save:
- response = self._make_on_demand_request(params, {SPEC_VERSION_TWO_FLAG: True})
- assert bool(mock_widget_save.assert_not_called)
- self._assert_on_demand_response(response, expected_on_demand_query=True)
- assert response.data["data"] == [{user_misery_field: user_misery_formula(1, 2)}]
- def test_on_demand_count_unique(self):
- field = "count_unique(user)"
- query = "transaction.duration:>0"
- params = {"field": [field], "query": query}
- # We do not really have to create the metrics for both specs since
- # the first API call will not query any on-demand metric
- for spec_version in OnDemandMetricSpecVersioning.get_spec_versions():
- spec = OnDemandMetricSpec(
- field=field,
- query=query,
- spec_type=MetricSpecType.DYNAMIC_QUERY,
- spec_version=spec_version,
- )
- self.store_on_demand_metric(1, spec=spec, timestamp=self.min_ago)
- self.store_on_demand_metric(2, spec=spec, timestamp=self.min_ago)
- # The first call will not be on-demand
- response = self._make_on_demand_request(params)
- self._assert_on_demand_response(response, expected_on_demand_query=False)
- # This second call will be on-demand
- response = self._make_on_demand_request(
- params, extra_features={SPEC_VERSION_TWO_FLAG: True}
- )
- self._assert_on_demand_response(response, expected_on_demand_query=True)
- assert response.data["data"] == [{"count_unique(user)": 2}]
- def test_split_decision_for_errors_widget(self):
- error_data = load_data("python", timestamp=before_now(minutes=1))
- self.store_event(
- data={
- **error_data,
- "exception": {"values": [{"type": "blah", "data": {"values": []}}]},
- },
- project_id=self.project.id,
- )
- _, widget, __ = create_widget(
- ["count()", "error.type"], "error.type:blah", self.project, discover_widget_split=None
- )
- response = self.do_request(
- {
- "field": ["count()", "error.type"],
- "query": "error.type:blah",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- "dashboardWidgetId": widget.id,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data.get("meta").get(
- "discoverSplitDecision"
- ) is DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.ERROR_EVENTS)
- widget.refresh_from_db()
- assert widget.discover_widget_split == DashboardWidgetTypes.ERROR_EVENTS
- assert widget.dataset_source == DatasetSourcesTypes.INFERRED.value
- def test_split_decision_for_transactions_widget(self):
- transaction_data = load_data("transaction", timestamp=before_now(minutes=1))
- self.store_event(
- data={
- **transaction_data,
- },
- project_id=self.project.id,
- )
- _, widget, __ = create_widget(
- ["count()", "transaction.name"], "", self.project, discover_widget_split=None
- )
- assert widget.discover_widget_split is None
- response = self.do_request(
- {
- "field": ["count()", "transaction.name"],
- "query": "",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- "dashboardWidgetId": widget.id,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data.get("meta").get(
- "discoverSplitDecision"
- ) is DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.TRANSACTION_LIKE)
- widget.refresh_from_db()
- assert widget.discover_widget_split == DashboardWidgetTypes.TRANSACTION_LIKE
- assert widget.dataset_source == DatasetSourcesTypes.INFERRED.value
- def test_split_decision_for_ambiguous_widget_without_data(self):
- _, widget, __ = create_widget(
- ["count()", "transaction.name", "error.type"],
- "",
- self.project,
- discover_widget_split=None,
- )
- assert widget.discover_widget_split is None
- response = self.do_request(
- {
- "field": ["count()", "transaction.op", "error.type"],
- "query": "",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- "dashboardWidgetId": widget.id,
- },
- features={"organizations:performance-discover-dataset-selector": True},
- )
- assert response.status_code == 200, response.content
- assert response.data.get("meta").get(
- "discoverSplitDecision"
- ) == DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.ERROR_EVENTS)
- widget.refresh_from_db()
- assert widget.discover_widget_split == DashboardWidgetTypes.ERROR_EVENTS
- assert widget.dataset_source == DatasetSourcesTypes.FORCED.value
- def test_split_decision_for_ambiguous_widget_with_data(self):
- # Store a transaction
- transaction_data = load_data("transaction", timestamp=before_now(minutes=1))
- self.store_event(
- data={
- **transaction_data,
- },
- project_id=self.project.id,
- )
- # Store an event
- error_data = load_data("python", timestamp=before_now(minutes=1))
- self.store_event(
- data={
- **error_data,
- "exception": {"values": [{"type": "blah", "data": {"values": []}}]},
- },
- project_id=self.project.id,
- )
- _, widget, __ = create_widget(
- ["count()"],
- "",
- self.project,
- discover_widget_split=None,
- )
- assert widget.discover_widget_split is None
- response = self.do_request(
- {
- "field": ["count()"],
- "query": "",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- "dashboardWidgetId": widget.id,
- },
- features={"organizations:performance-discover-dataset-selector": True},
- )
- assert response.status_code == 200, response.content
- assert response.data.get("meta").get(
- "discoverSplitDecision"
- ) == DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.ERROR_EVENTS)
- widget.refresh_from_db()
- assert widget.discover_widget_split == DashboardWidgetTypes.ERROR_EVENTS
- assert widget.dataset_source == DatasetSourcesTypes.FORCED.value
- @mock.patch("sentry.snuba.metrics_enhanced_performance.query")
- def test_split_decision_can_be_inferred_from_fields(self, mock_mep_query):
- _, widget, __ = create_widget(
- ["count()"], "", self.project, discover_widget_split=None, columns=["error.type"]
- )
- assert widget.discover_widget_split is None
- response = self.do_request(
- {
- "field": ["error.type", "count()"],
- "query": "",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- "dashboardWidgetId": widget.id,
- }
- )
- assert response.status_code == 200, response.content
- # This is the "original" data call that gets bypassed by the inference
- mock_mep_query.assert_not_called()
- assert response.data.get("meta").get(
- "discoverSplitDecision"
- ) is DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.ERROR_EVENTS)
- widget.refresh_from_db()
- assert widget.discover_widget_split is DashboardWidgetTypes.ERROR_EVENTS
- @mock.patch("sentry.snuba.metrics_enhanced_performance.query")
- def test_split_decision_can_be_inferred_from_query(self, mock_mep_query):
- _, widget, __ = create_widget(
- ["count()"],
- "",
- self.project,
- discover_widget_split=None,
- )
- assert widget.discover_widget_split is None
- response = self.do_request(
- {
- "field": ["count()"],
- "query": "error.type:blah",
- "dataset": "metricsEnhanced",
- "per_page": 50,
- "dashboardWidgetId": widget.id,
- }
- )
- assert response.status_code == 200, response.content
- # This is the "original" data call that gets bypassed by the inference
- mock_mep_query.assert_not_called()
- assert response.data.get("meta").get(
- "discoverSplitDecision"
- ) is DashboardWidgetTypes.get_type_name(DashboardWidgetTypes.ERROR_EVENTS)
- widget.refresh_from_db()
- assert widget.discover_widget_split is DashboardWidgetTypes.ERROR_EVENTS
- class OrganizationEventsMetricsEnhancedPerformanceEndpointTestWithMetricLayer(
- OrganizationEventsMetricsEnhancedPerformanceEndpointTest
- ):
- def setUp(self):
- super().setUp()
- self.features["organizations:use-metrics-layer"] = True
- @pytest.mark.xfail(reason="Not supported")
- def test_time_spent(self):
- super().test_time_spent()
- @pytest.mark.xfail(reason="Not supported")
- def test_http_error_rate(self):
- super().test_http_error_rate()
- @pytest.mark.xfail(reason="Multiple aliases to same column not supported")
- def test_title_and_transaction_alias(self):
- super().test_title_and_transaction_alias()
- @pytest.mark.xfail(reason="Sort order is flaking when querying multiple datasets")
- def test_maintain_sort_order_across_datasets(self):
- """You may need to run this test a few times to get it to fail"""
- super().test_maintain_sort_order_across_datasets()
- @pytest.mark.xfail(reason="Not implemented")
- def test_avg_compare(self):
- super().test_avg_compare()
- @pytest.mark.xfail(reason="Not implemented")
- def test_avg_if(self):
- super().test_avg_if()
- @pytest.mark.xfail(reason="Not implemented")
- def test_count_if(self):
- super().test_count_if()
- @pytest.mark.xfail(reason="Not implemented")
- def test_device_class(self):
- super().test_device_class()
- @pytest.mark.xfail(reason="Not implemented")
- def test_device_class_filter(self):
- super().test_device_class_filter()
- @pytest.mark.xfail(reason="Not implemented")
- def test_performance_score(self):
- super().test_performance_score()
- @pytest.mark.xfail(reason="Not implemented")
- def test_performance_score_boundaries(self):
- super().test_performance_score_boundaries()
- @pytest.mark.xfail(reason="Not implemented")
- def test_total_performance_score(self):
- super().test_total_performance_score()
- @pytest.mark.xfail(reason="Not implemented")
- def test_weighted_performance_score(self):
- super().test_weighted_performance_score()
- @pytest.mark.xfail(reason="Not implemented")
- def test_invalid_performance_score_column(self):
- super().test_invalid_performance_score_column()
- @pytest.mark.xfail(reason="Not implemented")
- def test_invalid_weighted_performance_score_column(self):
- super().test_invalid_weighted_performance_score_column()
- @pytest.mark.xfail(reason="Not implemented")
- def test_no_weighted_performance_score_column(self):
- super().test_invalid_weighted_performance_score_column()
- @pytest.mark.xfail(reason="Not implemented")
- def test_opportunity_score(self):
- super().test_opportunity_score()
- @pytest.mark.xfail(reason="Not implemented")
- def test_opportunity_score_with_fixed_weights(self):
- super().test_opportunity_score_with_fixed_weights()
- @pytest.mark.xfail(reason="Not implemented")
- def test_count_scores(self):
- super().test_count_scores()
- @pytest.mark.xfail(reason="Not implemented")
- def test_count_starts(self):
- super().test_count_starts()
- @pytest.mark.xfail(reason="Not implemented")
- def test_count_starts_returns_all_counts_when_no_arg_is_passed(self):
- super().test_count_starts_returns_all_counts_when_no_arg_is_passed()
- @pytest.mark.xfail(reason="Not implemented")
- def test_timestamp_groupby(self):
- super().test_timestamp_groupby()
- @pytest.mark.xfail(reason="Not implemented")
- def test_on_demand_with_mep(self):
- super().test_on_demand_with_mep()
|