12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473 |
- import math
- import uuid
- from datetime import datetime, timedelta, timezone
- from typing import Any, Dict
- from unittest import mock
- from uuid import uuid4
- import pytest
- from django.test import override_settings
- from django.urls import reverse
- from django.utils import timezone as django_timezone
- from snuba_sdk.column import Column
- from snuba_sdk.function import Function
- from sentry.discover.models import TeamKeyTransaction
- from sentry.issues.grouptype import ProfileFileIOGroupType
- from sentry.models.group import GroupStatus
- from sentry.models.projectteam import ProjectTeam
- from sentry.models.releaseprojectenvironment import ReleaseStages
- from sentry.models.transaction_threshold import (
- ProjectTransactionThreshold,
- ProjectTransactionThresholdOverride,
- TransactionMetric,
- )
- from sentry.search.events import constants
- from sentry.testutils.cases import (
- APITestCase,
- PerformanceIssueTestCase,
- ProfilesSnubaTestCase,
- SnubaTestCase,
- )
- from sentry.testutils.helpers import parse_link_header
- from sentry.testutils.helpers.datetime import before_now, freeze_time, iso_format
- from sentry.testutils.silo import region_silo_test
- from sentry.testutils.skips import requires_not_arm64
- from sentry.types.group import GroupSubStatus
- from sentry.utils import json
- from sentry.utils.samples import load_data
- from tests.sentry.issues.test_utils import SearchIssueTestMixin
- MAX_QUERYABLE_TRANSACTION_THRESHOLDS = 1
- class OrganizationEventsEndpointTestBase(APITestCase, SnubaTestCase):
- viewname = "sentry-api-0-organization-events"
- referrer = "api.organization-events"
- # Some base data for create_span
- base_span: Dict[str, Any] = {
- "is_segment": False,
- "retention_days": 90,
- "tags": {},
- "sentry_tags": {},
- "measurements": {},
- }
- def setUp(self):
- super().setUp()
- self.nine_mins_ago = before_now(minutes=9)
- self.ten_mins_ago = before_now(minutes=10)
- self.ten_mins_ago_iso = iso_format(self.ten_mins_ago)
- self.eleven_mins_ago = before_now(minutes=11)
- self.eleven_mins_ago_iso = iso_format(self.eleven_mins_ago)
- self.transaction_data = load_data("transaction", timestamp=self.ten_mins_ago)
- self.features = {}
- def client_get(self, *args, **kwargs):
- return self.client.get(*args, **kwargs)
- def reverse_url(self):
- return reverse(
- self.viewname,
- kwargs={"organization_slug": self.organization.slug},
- )
- def do_request(self, query, features=None, **kwargs):
- if features is None:
- features = {"organizations:discover-basic": True}
- features.update(self.features)
- self.login_as(user=self.user)
- with self.feature(features):
- return self.client_get(self.reverse_url(), query, format="json", **kwargs)
- def load_data(self, platform="transaction", timestamp=None, duration=None, **kwargs):
- if timestamp is None:
- timestamp = self.ten_mins_ago
- min_age = before_now(minutes=10)
- if timestamp > min_age:
- # Sentry does some rounding of timestamps to improve cache hits in snuba.
- # This can result in events not being returns if the timestamps
- # are too recent.
- raise Exception(
- f"Please define a timestamp older than 10 minutes to avoid flakey tests. Want a timestamp before {min_age}, got: {timestamp} "
- )
- start_timestamp = None
- if duration is not None:
- start_timestamp = timestamp - duration
- start_timestamp = start_timestamp - timedelta(
- microseconds=start_timestamp.microsecond % 1000
- )
- return load_data(platform, timestamp=timestamp, start_timestamp=start_timestamp, **kwargs)
- def create_span(
- self, extra_data=None, organization=None, project=None, start_ts=None, duration=1000
- ):
- """Create span json, not required for store_span, but with no params passed should just work out of the box"""
- if organization is None:
- organization = self.organization
- if project is None:
- project = self.project
- if start_ts is None:
- start_ts = datetime.now() - timedelta(minutes=1)
- if extra_data is None:
- extra_data = {}
- span = self.base_span.copy()
- # Load some defaults
- span.update(
- {
- "event_id": uuid4().hex,
- "organization_id": organization.id,
- "project_id": project.id,
- "trace_id": uuid4().hex,
- "span_id": uuid4().hex[:16],
- "parent_span_id": uuid4().hex[:16],
- "segment_id": uuid4().hex[:16],
- "group_raw": uuid4().hex[:16],
- "profile_id": uuid4().hex,
- # Multiply by 1000 cause it needs to be ms
- "start_timestamp_ms": int(start_ts.timestamp() * 1000),
- "timestamp": int(start_ts.timestamp() * 1000),
- "received": start_ts.timestamp(),
- "duration_ms": duration,
- "exclusive_time_ms": duration,
- }
- )
- # Load any specific custom data
- span.update(extra_data)
- # coerce to string
- for tag, value in dict(span["tags"]).items():
- span["tags"][tag] = str(value)
- return span
- @region_silo_test
- class OrganizationEventsEndpointTest(OrganizationEventsEndpointTestBase, PerformanceIssueTestCase):
- def test_no_projects(self):
- response = self.do_request({})
- assert response.status_code == 200, response.content
- assert response.data["data"] == []
- assert response.data["meta"] == {
- "tips": {"query": "Need at least one valid project to query."}
- }
- def test_environment_filter(self):
- self.create_environment(self.project, name="production")
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "environment": "production",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["id", "project.id"],
- "project": [self.project.id],
- "environment": ["staging", "production"],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 2
- def test_performance_view_feature(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=self.project.id,
- )
- query = {"field": ["id", "project.id"], "project": [self.project.id]}
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- def test_multi_project_feature_gate_rejection(self):
- team = self.create_team(organization=self.organization, members=[self.user])
- project = self.create_project(organization=self.organization, teams=[team])
- project2 = self.create_project(organization=self.organization, teams=[team])
- query = {"field": ["id", "project.id"], "project": [project.id, project2.id]}
- response = self.do_request(query)
- assert response.status_code == 400
- assert "events from multiple projects" in response.data["detail"]
- def test_multi_project_feature_gate_replays(self):
- team = self.create_team(organization=self.organization, members=[self.user])
- project = self.create_project(organization=self.organization, teams=[team])
- project2 = self.create_project(organization=self.organization, teams=[team])
- query = {"field": ["id", "project.id"], "project": [project.id, project2.id]}
- response = self.do_request(query, **{"HTTP_X-Sentry-Replay-Request": "1"})
- assert response.status_code == 200
- def test_invalid_search_terms(self):
- self.create_project()
- query = {"field": ["id"], "query": "hi \n there"}
- response = self.do_request(query)
- 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_invalid_trace_span(self):
- self.create_project()
- query = {"field": ["id"], "query": "trace.span:invalid"}
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == "trace.span must be a valid 16 character hex (containing only digits, or a-f characters)"
- )
- query = {"field": ["id"], "query": "trace.parent_span:invalid"}
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == "trace.parent_span must be a valid 16 character hex (containing only digits, or a-f characters)"
- )
- query = {"field": ["id"], "query": "trace.span:*"}
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"] == "Wildcard conditions are not permitted on `trace.span` field"
- )
- query = {"field": ["id"], "query": "trace.parent_span:*"}
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == "Wildcard conditions are not permitted on `trace.parent_span` field"
- )
- def test_has_trace_context(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "contexts": {
- "trace": {
- "span_id": "a" * 16,
- "trace_id": "b" * 32,
- },
- },
- },
- project_id=self.project.id,
- )
- query = {"field": ["id", "trace.parent_span"], "query": "has:trace.span"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["id"] == "a" * 32
- query = {"field": ["id"], "query": "has:trace.parent_span"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_treat_status_as_tag_discover_transaction(self):
- event_1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"status": "good"},
- },
- project_id=self.project.id,
- )
- event_2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"status": "bad"},
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["event_id"],
- "query": "!status:good",
- "dataset": "discover",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"] == [
- {"event_id": "", "id": event_2.event_id, "project.name": self.project.slug}
- ]
- query = {"field": ["event_id"], "query": ["status:good"], "dataset": "discover"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"] == [
- {"event_id": "", "id": event_1.event_id, "project.name": self.project.slug}
- ]
- def test_not_has_trace_context(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "contexts": {
- "trace": {
- "span_id": "a" * 16,
- "trace_id": "b" * 32,
- },
- },
- },
- project_id=self.project.id,
- )
- query = {"field": ["id", "trace.parent_span"], "query": "!has:trace.span"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- query = {"field": ["id"], "query": "!has:trace.parent_span"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["id"] == "a" * 32
- def test_parent_span_id_in_context(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "contexts": {
- "trace": {
- "span_id": "a" * 16,
- "trace_id": "b" * 32,
- "parent_span_id": "c" * 16,
- },
- },
- },
- project_id=self.project.id,
- )
- query = {"field": ["id"], "query": f"trace.parent_span:{'c' * 16}"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["id"] == "a" * 32
- def test_out_of_retention(self):
- self.create_project()
- with self.options({"system.event-retention-days": 10}):
- query = {
- "field": ["id", "timestamp"],
- "orderby": ["-timestamp", "-id"],
- "start": iso_format(before_now(days=20)),
- "end": iso_format(before_now(days=15)),
- }
- 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_raw_data(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.eleven_mins_ago_iso,
- "user": {"ip_address": "127.0.0.1", "email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"ip_address": "127.0.0.1", "email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["id", "project.id", "user.email", "user.ip", "timestamp"],
- "orderby": "-timestamp",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["id"] == "b" * 32
- assert data[0]["project.id"] == self.project.id
- assert data[0]["user.email"] == "foo@example.com"
- assert "project.name" not in data[0], "project.id does not auto select name"
- assert "project" not in data[0]
- meta = response.data["meta"]
- field_meta = meta["fields"]
- assert field_meta["id"] == "string"
- assert field_meta["user.email"] == "string"
- assert field_meta["user.ip"] == "string"
- assert field_meta["timestamp"] == "date"
- def test_project_name(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {"field": ["project.name", "environment"]}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["project.name"] == self.project.slug
- assert "project.id" not in response.data["data"][0]
- assert response.data["data"][0]["environment"] == "staging"
- def test_project_without_name(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {"field": ["project", "environment"]}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["project"] == self.project.slug
- assert response.data["meta"]["fields"]["project"] == "string"
- assert "project.id" not in response.data["data"][0]
- assert response.data["data"][0]["environment"] == "staging"
- def test_project_in_query(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["project", "count()"],
- "query": f'project:"{self.project.slug}"',
- "statsPeriod": "14d",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["project"] == self.project.slug
- assert "project.id" not in response.data["data"][0]
- def test_project_in_query_not_in_header(self):
- project = self.create_project()
- other_project = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=project.id,
- )
- query = {
- "field": ["project", "count()"],
- "query": 'project:"%s"' % project.slug,
- "statsPeriod": "14d",
- "project": other_project.id,
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == f"Invalid query. Project(s) {project.slug} do not exist or are not actively selected."
- )
- def test_project_in_query_does_not_exist(self):
- self.create_project()
- query = {"field": ["project", "count()"], "query": "project:morty", "statsPeriod": "14d"}
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == "Invalid query. Project(s) morty do not exist or are not actively selected."
- )
- def test_not_project_in_query_but_in_header(self):
- team = self.create_team(organization=self.organization, members=[self.user])
- project = self.create_project(organization=self.organization, teams=[team])
- project2 = self.create_project(organization=self.organization, teams=[team])
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group2"],
- },
- project_id=project2.id,
- )
- query = {
- "field": ["id", "project.id"],
- "project": [project.id],
- "query": f"!project:{project2.slug}",
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert response.data["data"] == [{"id": "a" * 32, "project.id": project.id}]
- def test_not_project_in_query_with_all_projects(self):
- team = self.create_team(organization=self.organization, members=[self.user])
- project = self.create_project(organization=self.organization, teams=[team])
- project2 = self.create_project(organization=self.organization, teams=[team])
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group2"],
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["id", "project.id"],
- "project": [-1],
- "query": f"!project:{project2.slug}",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200
- assert response.data["data"] == [{"id": "a" * 32, "project.id": project.id}]
- def test_project_condition_used_for_automatic_filters(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["project", "count()"],
- "query": f'project:"{self.project.slug}"',
- "statsPeriod": "14d",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["project"] == self.project.slug
- assert "project.id" not in response.data["data"][0]
- def test_auto_insert_project_name_when_event_id_present(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {"field": ["id"], "statsPeriod": "1h"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"] == [{"project.name": self.project.slug, "id": "a" * 32}]
- def test_auto_insert_project_name_when_event_id_present_with_aggregate(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {"field": ["id", "count()"], "statsPeriod": "1h"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"] == [
- {"project.name": self.project.slug, "id": "a" * 32, "count()": 1}
- ]
- def test_performance_short_group_id(self):
- event = self.create_performance_issue()
- query = {
- "field": ["count()"],
- "statsPeriod": "1h",
- "query": f"project:{event.group.project.slug} issue:{event.group.qualified_short_id}",
- "dataset": "issuePlatform",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 1
- def test_multiple_performance_short_group_ids_filter(self):
- event1 = self.create_performance_issue()
- event2 = self.create_performance_issue()
- query = {
- "field": ["count()"],
- "statsPeriod": "1h",
- "query": f"project:{event1.group.project.slug} issue:[{event1.group.qualified_short_id},{event2.group.qualified_short_id}]",
- "dataset": "issuePlatform",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 2
- def test_event_id_with_in_search(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging1",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "environment": "staging2",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- # Should not show up
- self.store_event(
- data={
- "event_id": "c" * 32,
- "environment": "staging3",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["id", "environment"],
- "statsPeriod": "1h",
- "query": f"id:[{'a' * 32}, {'b' * 32}]",
- "orderby": "environment",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- assert response.data["data"][0]["id"] == "a" * 32
- assert response.data["data"][1]["id"] == "b" * 32
- def test_user_search(self):
- self.transaction_data["user"] = {
- "email": "foo@example.com",
- "id": "123",
- "ip_address": "127.0.0.1",
- "username": "foo",
- }
- self.store_event(self.transaction_data, project_id=self.project.id)
- fields = {
- "email": "user.email",
- "id": "user.id",
- "ip_address": "user.ip",
- "username": "user.username",
- }
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- for key, value in self.transaction_data["user"].items():
- field = fields[key]
- query = {
- "field": ["project", "user"],
- "query": f"{field}:{value}",
- "statsPeriod": "14d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["project"] == self.project.slug
- assert response.data["data"][0]["user"] == "id:123"
- def test_has_user(self):
- self.store_event(self.transaction_data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- for value in self.transaction_data["user"].values():
- query = {"field": ["project", "user"], "query": "has:user", "statsPeriod": "14d"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["user"] == "ip:{}".format(
- self.transaction_data["user"]["ip_address"]
- )
- def test_team_param_no_access(self):
- org = self.create_organization(
- owner=self.user, # use other user as owner
- name="foo",
- flags=0, # disable default allow_joinleave
- )
- project = self.create_project(name="baz", organization=org)
- user = self.create_user()
- self.login_as(user=user, superuser=False)
- team = self.create_team(organization=org, name="Team Bar")
- project.add_team(team)
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=project.id,
- )
- query = {"field": ["id", "project.id"], "project": [project.id], "team": [team.id]}
- response = self.do_request(query)
- assert response.status_code == 403, response.content
- assert response.data["detail"] == "You do not have permission to perform this action."
- def test_team_is_nan(self):
- query = {"field": ["id"], "project": [self.project.id], "team": [math.nan]}
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert response.data["detail"] == "Invalid Team ID: nan"
- def test_comparison_operators_on_numeric_field(self):
- event = self.store_event(
- {"timestamp": iso_format(before_now(minutes=1))}, project_id=self.project.id
- )
- query = {"field": ["issue"], "query": f"issue.id:>{event.group.id - 1}"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == event.group.qualified_short_id
- query = {"field": ["issue"], "query": f"issue.id:>{event.group.id}"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_negation_on_numeric_field_excludes_issue(self):
- event = self.store_event({"timestamp": self.ten_mins_ago_iso}, project_id=self.project.id)
- query = {"field": ["issue"], "query": f"issue.id:{event.group.id}"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == event.group.qualified_short_id
- query = {"field": ["issue"], "query": f"!issue.id:{event.group.id}"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_negation_on_numeric_in_filter_excludes_issue(self):
- event = self.store_event({"timestamp": self.ten_mins_ago_iso}, project_id=self.project.id)
- query = {"field": ["issue"], "query": f"issue.id:[{event.group.id}]"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == event.group.qualified_short_id
- query = {"field": ["issue"], "query": f"!issue.id:[{event.group.id}]"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_negation_on_duration_filter_excludes_transaction(self):
- event = self.store_event(self.transaction_data, project_id=self.project.id)
- duration = int(event.data.get("timestamp") - event.data.get("start_timestamp")) * 1000
- query = {"field": ["transaction"], "query": f"transaction.duration:{duration}"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["id"] == event.event_id
- query = {"field": ["transaction"], "query": f"!transaction.duration:{duration}"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_has_issue(self):
- event = self.store_event({"timestamp": self.ten_mins_ago_iso}, project_id=self.project.id)
- self.store_event(self.transaction_data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- # should only show 1 event of type default
- query = {"field": ["project", "issue"], "query": "has:issue", "statsPeriod": "14d"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == event.group.qualified_short_id
- # should only show 1 event of type default
- query = {
- "field": ["project", "issue"],
- "query": "event.type:default has:issue",
- "statsPeriod": "14d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == event.group.qualified_short_id
- # should show no results because no the default event has an issue
- query = {
- "field": ["project", "issue"],
- "query": "event.type:default !has:issue",
- "statsPeriod": "14d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- # should show no results because no transactions have issues
- query = {
- "field": ["project", "issue"],
- "query": "event.type:transaction has:issue",
- "statsPeriod": "14d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- # should only show 1 event of type transaction since they don't have issues
- query = {
- "field": ["project", "issue"],
- "query": "event.type:transaction !has:issue",
- "statsPeriod": "14d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == "unknown"
- @pytest.mark.skip("Cannot look up group_id of transaction events")
- def test_unknown_issue(self):
- event = self.store_event({"timestamp": self.ten_mins_ago_iso}, project_id=self.project.id)
- self.store_event(self.transaction_data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {"field": ["project", "issue"], "query": "issue:unknown", "statsPeriod": "14d"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == "unknown"
- query = {"field": ["project", "issue"], "query": "!issue:unknown", "statsPeriod": "14d"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["issue"] == event.group.qualified_short_id
- def test_negative_user_search(self):
- user_data = {"email": "foo@example.com", "id": "123", "username": "foo"}
- # Load an event with data that shouldn't match
- data = self.transaction_data.copy()
- data["transaction"] = "/transactions/nomatch"
- event_user = user_data.copy()
- event_user["id"] = "undefined"
- data["user"] = event_user
- self.store_event(data, project_id=self.project.id)
- # Load a matching event
- data = self.transaction_data.copy()
- data["transaction"] = "/transactions/matching"
- data["user"] = user_data
- self.store_event(data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["project", "user"],
- "query": '!user:"id:undefined"',
- "statsPeriod": "14d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["user"] == "id:{}".format(user_data["id"])
- assert "user.email" not in response.data["data"][0]
- assert "user.id" not in response.data["data"][0]
- def test_not_project_in_query(self):
- project1 = self.create_project()
- project2 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=project1.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["project", "count()"],
- "query": '!project:"%s"' % project1.slug,
- "statsPeriod": "14d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["project"] == project2.slug
- assert "project.id" not in response.data["data"][0]
- def test_error_handled_condition(self):
- prototype = self.load_data(platform="android-ndk")
- events = (
- ("a" * 32, "not handled", False),
- ("b" * 32, "was handled", True),
- ("c" * 32, "undefined", None),
- )
- for event in events:
- prototype["event_id"] = event[0]
- prototype["message"] = event[1]
- prototype["exception"]["values"][0]["value"] = event[1]
- prototype["exception"]["values"][0]["mechanism"]["handled"] = event[2]
- prototype["timestamp"] = self.ten_mins_ago_iso
- self.store_event(data=prototype, project_id=self.project.id)
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["message", "error.handled"],
- "query": "error.handled:0",
- "orderby": "message",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 1 == len(response.data["data"])
- assert 0 == response.data["data"][0]["error.handled"]
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["message", "error.handled"],
- "query": "error.handled:1",
- "orderby": "message",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 2 == len(response.data["data"])
- assert 1 == response.data["data"][0]["error.handled"]
- assert 1 == response.data["data"][1]["error.handled"]
- def test_error_unhandled_condition(self):
- prototype = self.load_data(platform="android-ndk")
- events = (
- ("a" * 32, "not handled", False),
- ("b" * 32, "was handled", True),
- ("c" * 32, "undefined", None),
- )
- for event in events:
- prototype["event_id"] = event[0]
- prototype["message"] = event[1]
- prototype["exception"]["values"][0]["value"] = event[1]
- prototype["exception"]["values"][0]["mechanism"]["handled"] = event[2]
- prototype["timestamp"] = self.ten_mins_ago_iso
- self.store_event(data=prototype, project_id=self.project.id)
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["message", "error.unhandled", "error.handled"],
- "query": "error.unhandled:true",
- "orderby": "message",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 1 == len(response.data["data"])
- assert 0 == response.data["data"][0]["error.handled"]
- assert 1 == response.data["data"][0]["error.unhandled"]
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["message", "error.handled", "error.unhandled"],
- "query": "error.unhandled:false",
- "orderby": "message",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 2 == len(response.data["data"])
- assert 1 == response.data["data"][0]["error.handled"]
- assert 0 == response.data["data"][0]["error.unhandled"]
- assert 1 == response.data["data"][1]["error.handled"]
- assert 0 == response.data["data"][1]["error.unhandled"]
- def test_groupby_error_handled_and_unhandled(self):
- prototype = self.load_data(platform="android-ndk")
- events = (
- ("a" * 32, "not handled", False),
- ("b" * 32, "was handled", True),
- ("c" * 32, "undefined", None),
- )
- for event in events:
- prototype["event_id"] = event[0]
- prototype["message"] = event[1]
- prototype["exception"]["values"][0]["value"] = event[1]
- prototype["exception"]["values"][0]["mechanism"]["handled"] = event[2]
- prototype["timestamp"] = self.ten_mins_ago_iso
- self.store_event(data=prototype, project_id=self.project.id)
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["error.handled", "count()"],
- "query": "event.type:error",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 2 == len(response.data["data"])
- assert 0 == response.data["data"][0]["error.handled"]
- assert 1 == response.data["data"][0]["count()"]
- assert 1 == response.data["data"][1]["error.handled"]
- assert 2 == response.data["data"][1]["count()"]
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["error.unhandled", "count()"],
- "query": "event.type:error",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 2 == len(response.data["data"])
- assert 0 == response.data["data"][0]["error.unhandled"]
- assert 2 == response.data["data"][0]["count()"]
- assert 1 == response.data["data"][1]["error.unhandled"]
- assert 1 == response.data["data"][1]["count()"]
- def test_error_main_thread_condition(self):
- prototype = self.load_data(platform="android-ndk")
- prototype["timestamp"] = self.ten_mins_ago_iso
- self.store_event(data=prototype, project_id=self.project.id)
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["id", "project.id"],
- "query": "error.main_thread:true",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 1 == len(response.data["data"])
- with self.feature("organizations:discover-basic"):
- query = {
- "field": ["id", "project.id"],
- "query": "error.main_thread:false",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.data
- assert 0 == len(response.data["data"])
- def test_implicit_groupby(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.eleven_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- event1 = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- event2 = self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- },
- project_id=self.project.id,
- )
- query = {"field": ["count(id)", "project.id", "issue.id"], "orderby": "issue.id"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0] == {
- "project.id": self.project.id,
- "issue.id": event1.group_id,
- "count(id)": 2,
- }
- assert data[1] == {
- "project.id": self.project.id,
- "issue.id": event2.group_id,
- "count(id)": 1,
- }
- meta = response.data["meta"]["fields"]
- assert meta["count(id)"] == "integer"
- def test_orderby(self):
- self.store_event(
- data={"event_id": "a" * 32, "timestamp": self.eleven_mins_ago_iso},
- project_id=self.project.id,
- )
- self.store_event(
- data={"event_id": "b" * 32, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- )
- self.store_event(
- data={"event_id": "c" * 32, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- )
- query = {"field": ["id", "timestamp"], "orderby": ["-timestamp", "-id"]}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert data[0]["id"] == "c" * 32
- assert data[1]["id"] == "b" * 32
- assert data[2]["id"] == "a" * 32
- def test_sort_title(self):
- self.store_event(
- data={"event_id": "a" * 32, "message": "zlast", "timestamp": self.eleven_mins_ago_iso},
- project_id=self.project.id,
- )
- self.store_event(
- data={"event_id": "b" * 32, "message": "second", "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- )
- self.store_event(
- data={"event_id": "c" * 32, "message": "first", "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- )
- query = {"field": ["id", "title"], "sort": "title"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert data[0]["id"] == "c" * 32
- assert data[1]["id"] == "b" * 32
- assert data[2]["id"] == "a" * 32
- def test_sort_invalid(self):
- self.create_project()
- query = {"field": ["id"], "sort": "garbage"}
- response = self.do_request(query)
- assert response.status_code == 400
- assert "sort by" in response.data["detail"]
- def test_latest_release_alias(self):
- event1 = self.store_event(
- data={"event_id": "a" * 32, "timestamp": self.eleven_mins_ago_iso, "release": "0.8"},
- project_id=self.project.id,
- )
- query = {"field": ["issue.id", "release"], "query": "release:latest"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert data[0]["issue.id"] == event1.group_id
- assert data[0]["release"] == "0.8"
- event2 = self.store_event(
- data={"event_id": "a" * 32, "timestamp": self.ten_mins_ago_iso, "release": "0.9"},
- project_id=self.project.id,
- )
- query = {"field": ["issue.id", "release"], "query": "release:latest"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert data[0]["issue.id"] == event2.group_id
- assert data[0]["release"] == "0.9"
- def test_semver(self):
- release_1 = self.create_release(version="test@1.2.3")
- release_2 = self.create_release(version="test@1.2.4")
- release_3 = self.create_release(version="test@1.2.5")
- release_1_e_1 = self.store_event(
- data={"release": release_1.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_1_e_2 = self.store_event(
- data={"release": release_1.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_2_e_1 = self.store_event(
- data={"release": release_2.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_2_e_2 = self.store_event(
- data={"release": release_2.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_3_e_1 = self.store_event(
- data={"release": release_3.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_3_e_2 = self.store_event(
- data={"release": release_3.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- query = {"field": ["id"], "query": f"{constants.SEMVER_ALIAS}:>1.2.3"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_2_e_1,
- release_2_e_2,
- release_3_e_1,
- release_3_e_2,
- }
- query = {"field": ["id"], "query": f"{constants.SEMVER_ALIAS}:>=1.2.3"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_1_e_1,
- release_1_e_2,
- release_2_e_1,
- release_2_e_2,
- release_3_e_1,
- release_3_e_2,
- }
- query = {"field": ["id"], "query": f"{constants.SEMVER_ALIAS}:<1.2.4"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_1_e_1,
- release_1_e_2,
- }
- query = {"field": ["id"], "query": f"{constants.SEMVER_ALIAS}:1.2.3"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_1_e_1,
- release_1_e_2,
- }
- query = {"field": ["id"], "query": f"!{constants.SEMVER_ALIAS}:1.2.3"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_2_e_1,
- release_2_e_2,
- release_3_e_1,
- release_3_e_2,
- }
- def test_release_stage(self):
- replaced_release = self.create_release(
- version="replaced_release",
- environments=[self.environment],
- adopted=django_timezone.now(),
- unadopted=django_timezone.now(),
- )
- adopted_release = self.create_release(
- version="adopted_release",
- environments=[self.environment],
- adopted=django_timezone.now(),
- )
- self.create_release(version="not_adopted_release", environments=[self.environment])
- adopted_release_e_1 = self.store_event(
- data={
- "release": adopted_release.version,
- "timestamp": self.ten_mins_ago_iso,
- "environment": self.environment.name,
- },
- project_id=self.project.id,
- ).event_id
- adopted_release_e_2 = self.store_event(
- data={
- "release": adopted_release.version,
- "timestamp": self.ten_mins_ago_iso,
- "environment": self.environment.name,
- },
- project_id=self.project.id,
- ).event_id
- replaced_release_e_1 = self.store_event(
- data={
- "release": replaced_release.version,
- "timestamp": self.ten_mins_ago_iso,
- "environment": self.environment.name,
- },
- project_id=self.project.id,
- ).event_id
- replaced_release_e_2 = self.store_event(
- data={
- "release": replaced_release.version,
- "timestamp": self.ten_mins_ago_iso,
- "environment": self.environment.name,
- },
- project_id=self.project.id,
- ).event_id
- query = {
- "field": ["id"],
- "query": f"{constants.RELEASE_STAGE_ALIAS}:{ReleaseStages.ADOPTED.value}",
- "environment": [self.environment.name],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- adopted_release_e_1,
- adopted_release_e_2,
- }
- query = {
- "field": ["id"],
- "query": f"!{constants.RELEASE_STAGE_ALIAS}:{ReleaseStages.LOW_ADOPTION.value}",
- "environment": [self.environment.name],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- adopted_release_e_1,
- adopted_release_e_2,
- replaced_release_e_1,
- replaced_release_e_2,
- }
- query = {
- "field": ["id"],
- "query": f"{constants.RELEASE_STAGE_ALIAS}:[{ReleaseStages.ADOPTED.value}, {ReleaseStages.REPLACED.value}]",
- "environment": [self.environment.name],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- adopted_release_e_1,
- adopted_release_e_2,
- replaced_release_e_1,
- replaced_release_e_2,
- }
- def test_semver_package(self):
- release_1 = self.create_release(version="test@1.2.3")
- release_2 = self.create_release(version="test2@1.2.4")
- release_1_e_1 = self.store_event(
- data={"release": release_1.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_1_e_2 = self.store_event(
- data={"release": release_1.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_2_e_1 = self.store_event(
- data={"release": release_2.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- query = {"field": ["id"], "query": f"{constants.SEMVER_PACKAGE_ALIAS}:test"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_1_e_1,
- release_1_e_2,
- }
- query = {"field": ["id"], "query": f"{constants.SEMVER_PACKAGE_ALIAS}:test2"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_2_e_1,
- }
- def test_semver_build(self):
- release_1 = self.create_release(version="test@1.2.3+123")
- release_2 = self.create_release(version="test2@1.2.4+124")
- release_1_e_1 = self.store_event(
- data={"release": release_1.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_1_e_2 = self.store_event(
- data={"release": release_1.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- release_2_e_1 = self.store_event(
- data={"release": release_2.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- ).event_id
- query = {"field": ["id"], "query": f"{constants.SEMVER_BUILD_ALIAS}:123"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_1_e_1,
- release_1_e_2,
- }
- query = {"field": ["id"], "query": f"{constants.SEMVER_BUILD_ALIAS}:124"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_2_e_1,
- }
- query = {"field": ["id"], "query": f"!{constants.SEMVER_BUILD_ALIAS}:124"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert {r["id"] for r in response.data["data"]} == {
- release_1_e_1,
- release_1_e_2,
- }
- def test_aliased_fields(self):
- event1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "user": {"email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- event2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "bar@example.com"},
- },
- project_id=self.project.id,
- )
- query = {"field": ["issue.id", "count(id)", "count_unique(user)"], "orderby": "issue.id"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0]["issue.id"] == event1.group_id
- assert data[0]["count(id)"] == 1
- assert data[0]["count_unique(user)"] == 1
- assert "projectid" not in data[0]
- assert "project.id" not in data[0]
- assert data[1]["issue.id"] == event2.group_id
- assert data[1]["count(id)"] == 2
- assert data[1]["count_unique(user)"] == 2
- def test_aggregate_field_with_dotted_param(self):
- event1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "user": {"id": "123", "email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- event2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"id": "123", "email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"id": "456", "email": "bar@example.com"},
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["issue.id", "issue_title", "count(id)", "count_unique(user.email)"],
- "orderby": "issue.id",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0]["issue.id"] == event1.group_id
- assert data[0]["count(id)"] == 1
- assert data[0]["count_unique(user.email)"] == 1
- assert "projectid" not in data[0]
- assert "project.id" not in data[0]
- assert data[1]["issue.id"] == event2.group_id
- assert data[1]["count(id)"] == 2
- assert data[1]["count_unique(user.email)"] == 2
- def test_failure_rate_alias_field(self):
- data = self.transaction_data.copy()
- data["transaction"] = "/failure_rate/success"
- self.store_event(data, project_id=self.project.id)
- data = self.transaction_data.copy()
- data["transaction"] = "/failure_rate/unknown"
- data["contexts"]["trace"]["status"] = "unknown_error"
- self.store_event(data, project_id=self.project.id)
- for i in range(6):
- data = self.transaction_data.copy()
- data["transaction"] = f"/failure_rate/{i}"
- data["contexts"]["trace"]["status"] = "unauthenticated"
- self.store_event(data, project_id=self.project.id)
- query = {"field": ["failure_rate()"], "query": "event.type:transaction"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["failure_rate()"] == 0.75
- def test_count_miserable_alias_field(self):
- events = [
- ("one", 300),
- ("one", 300),
- ("two", 3000),
- ("two", 3000),
- ("three", 300),
- ("three", 3000),
- ]
- for idx, event in enumerate(events):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- duration=timedelta(milliseconds=event[1]),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = f"/count_miserable/horribilis/{idx}"
- data["user"] = {"email": f"{event[0]}@example.com"}
- self.store_event(data, project_id=self.project.id)
- query = {"field": ["count_miserable(user, 300)"], "query": "event.type:transaction"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["count_miserable(user, 300)"] == 2
- @mock.patch(
- "sentry.search.events.fields.MAX_QUERYABLE_TRANSACTION_THRESHOLDS",
- MAX_QUERYABLE_TRANSACTION_THRESHOLDS,
- )
- @mock.patch(
- "sentry.search.events.datasets.discover.MAX_QUERYABLE_TRANSACTION_THRESHOLDS",
- MAX_QUERYABLE_TRANSACTION_THRESHOLDS,
- )
- def test_too_many_transaction_thresholds(self):
- project_transaction_thresholds = []
- project_ids = []
- for i in range(MAX_QUERYABLE_TRANSACTION_THRESHOLDS + 1):
- project = self.create_project(name=f"bulk_txn_{i}")
- project_ids.append(project.id)
- project_transaction_thresholds.append(
- ProjectTransactionThreshold(
- organization=self.organization,
- project=project,
- threshold=400,
- metric=TransactionMetric.LCP.value,
- )
- )
- ProjectTransactionThreshold.objects.bulk_create(project_transaction_thresholds)
- query = {
- "field": [
- "transaction",
- "count_miserable(user)",
- ],
- "query": "event.type:transaction",
- "project": project_ids,
- }
- response = self.do_request(
- query,
- features={
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- },
- )
- assert response.status_code == 400
- assert (
- response.data["detail"]
- == "Exceeded 1 configured transaction thresholds limit, try with fewer Projects."
- )
- def test_count_miserable_new_alias_field(self):
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.project.organization,
- threshold=400,
- metric=TransactionMetric.DURATION.value,
- )
- events = [
- ("one", 400),
- ("one", 400),
- ("two", 3000),
- ("two", 3000),
- ("three", 300),
- ("three", 3000),
- ]
- for idx, event in enumerate(events):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- duration=timedelta(milliseconds=event[1]),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = f"/count_miserable/horribilis/{event[0]}"
- data["user"] = {"email": f"{idx}@example.com"}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "transaction",
- "count_miserable(user)",
- ],
- "query": "event.type:transaction",
- "project": [self.project.id],
- "sort": "count_miserable_user",
- }
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- assert data[0]["count_miserable(user)"] == 0
- assert data[1]["count_miserable(user)"] == 1
- assert data[2]["count_miserable(user)"] == 2
- query["query"] = "event.type:transaction count_miserable(user):>0"
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert abs(data[0]["count_miserable(user)"]) == 1
- assert abs(data[1]["count_miserable(user)"]) == 2
- def test_user_misery_denominator(self):
- """This is to test against a bug where the denominator of misery(total unique users) was wrong
- This is because the total unique users for a LCP misery should only count users that have had a txn with lcp,
- and not count all transactions (ie. uniq_if(transaction has lcp) not just uniq())
- """
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.project.organization,
- threshold=600,
- metric=TransactionMetric.LCP.value,
- )
- lcps = [
- 400,
- 400,
- 300,
- 3000,
- 3000,
- 3000,
- ]
- for idx, lcp in enumerate(lcps):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = "/misery/new/"
- data["user"] = {"email": f"{idx}@example.com"}
- data["measurements"] = {
- "lcp": {"value": lcp},
- }
- self.store_event(data, project_id=self.project.id)
- # Shouldn't count towards misery
- data = self.load_data(timestamp=self.ten_mins_ago, duration=timedelta(milliseconds=0))
- data["transaction"] = "/misery/new/"
- data["user"] = {"email": "7@example.com"}
- data["measurements"] = {}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "transaction",
- "user_misery()",
- ],
- "query": "event.type:transaction",
- "project": [self.project.id],
- "sort": "-user_misery",
- }
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- # (3 frustrated + 5.8875) / (6 + 117.75)
- assert abs(data[0]["user_misery()"] - 0.071818) < 0.0001
- def test_user_misery_alias_field(self):
- events = [
- ("one", 300),
- ("one", 300),
- ("two", 3000),
- ("two", 3000),
- ("three", 300),
- ("three", 3000),
- ]
- for idx, event in enumerate(events):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- duration=timedelta(milliseconds=event[1]),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = f"/user_misery/{idx}"
- data["user"] = {"email": f"{event[0]}@example.com"}
- self.store_event(data, project_id=self.project.id)
- query = {"field": ["user_misery(300)"], "query": "event.type:transaction"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert abs(data[0]["user_misery(300)"] - 0.0653) < 0.0001
- def test_apdex_denominator_correct(self):
- """This is to test against a bug where the denominator of apdex(total count) was wrong
- This is because the total_count for a LCP apdex should only count transactions that have lcp, and not count
- all transactions (ie. count_if(transaction has lcp) not just count())
- """
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.project.organization,
- threshold=600,
- metric=TransactionMetric.LCP.value,
- )
- lcps = [
- 400,
- 400,
- 300,
- 800,
- 3000,
- 3000,
- 3000,
- ]
- for idx, lcp in enumerate(lcps):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = "/apdex/new/"
- data["user"] = {"email": f"{idx}@example.com"}
- data["measurements"] = {
- "lcp": {"value": lcp},
- }
- self.store_event(data, project_id=self.project.id)
- # Shouldn't count towards apdex
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(milliseconds=0),
- )
- data["transaction"] = "/apdex/new/"
- data["user"] = {"email": "7@example.com"}
- data["measurements"] = {}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "transaction",
- "apdex()",
- ],
- "query": "event.type:transaction",
- "project": [self.project.id],
- "sort": "-apdex",
- }
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- # 3 satisfied + 1 tolerated => 3.5/7
- assert data[0]["apdex()"] == 0.5
- def test_apdex_new_alias_field(self):
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.project.organization,
- threshold=400,
- metric=TransactionMetric.DURATION.value,
- )
- events = [
- ("one", 400),
- ("one", 400),
- ("two", 3000),
- ("two", 3000),
- ("three", 300),
- ("three", 3000),
- ]
- for idx, event in enumerate(events):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- duration=timedelta(milliseconds=event[1]),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = f"/apdex/new/{event[0]}"
- data["user"] = {"email": f"{idx}@example.com"}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "transaction",
- "apdex()",
- ],
- "query": "event.type:transaction",
- "project": [self.project.id],
- "sort": "-apdex",
- }
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- assert data[0]["apdex()"] == 1.0
- assert data[1]["apdex()"] == 0.5
- assert data[2]["apdex()"] == 0.0
- query["query"] = "event.type:transaction apdex():>0.50"
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["apdex()"] == 1.0
- def test_user_misery_alias_field_with_project_threshold(self):
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.project.organization,
- threshold=400,
- metric=TransactionMetric.DURATION.value,
- )
- events = [
- ("one", 400),
- ("one", 400),
- ("two", 3000),
- ("two", 3000),
- ("three", 300),
- ("three", 3000),
- ]
- for idx, event in enumerate(events):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- duration=timedelta(milliseconds=event[1]),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = f"/count_miserable/horribilis/{event[0]}"
- data["user"] = {"email": f"{idx}@example.com"}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "transaction",
- "user_misery()",
- ],
- "orderby": "user_misery()",
- "query": "event.type:transaction",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- assert data[0]["user_misery()"] == pytest.approx(0.04916, rel=1e-3)
- assert data[1]["user_misery()"] == pytest.approx(0.05751, rel=1e-3)
- assert data[2]["user_misery()"] == pytest.approx(0.06586, rel=1e-3)
- query["query"] = "event.type:transaction user_misery():>0.050"
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0]["user_misery()"] == pytest.approx(0.05751, rel=1e-3)
- assert data[1]["user_misery()"] == pytest.approx(0.06586, rel=1e-3)
- def test_user_misery_alias_field_with_transaction_threshold(self):
- events = [
- ("one", 300),
- ("two", 300),
- ("one", 3000),
- ("two", 3000),
- ("three", 400),
- ("four", 4000),
- ]
- for idx, event in enumerate(events):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- duration=timedelta(milliseconds=event[1]),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = f"/count_miserable/horribilis/{idx}"
- data["user"] = {"email": f"{event[0]}@example.com"}
- self.store_event(data, project_id=self.project.id)
- if idx % 2:
- ProjectTransactionThresholdOverride.objects.create(
- transaction=f"/count_miserable/horribilis/{idx}",
- project=self.project,
- organization=self.project.organization,
- threshold=100 * idx,
- metric=TransactionMetric.DURATION.value,
- )
- query = {
- "field": [
- "transaction",
- "user_misery()",
- ],
- "query": "event.type:transaction",
- "orderby": "transaction",
- "project": [self.project.id],
- }
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- expected = [
- ("/count_miserable/horribilis/0", ["duration", 300], 0.049578),
- ("/count_miserable/horribilis/1", ["duration", 100], 0.049578),
- ("/count_miserable/horribilis/2", ["duration", 300], 0.058),
- ("/count_miserable/horribilis/3", ["duration", 300], 0.058),
- ("/count_miserable/horribilis/4", ["duration", 300], 0.049578),
- ("/count_miserable/horribilis/5", ["duration", 500], 0.058),
- ]
- assert len(response.data["data"]) == 6
- data = response.data["data"]
- for i, record in enumerate(expected):
- name, threshold_config, misery = record
- assert data[i]["transaction"] == name
- assert data[i]["project_threshold_config"] == threshold_config
- assert data[i]["user_misery()"] == pytest.approx(misery, rel=1e-3)
- query["query"] = "event.type:transaction user_misery():>0.050"
- response = self.do_request(
- query,
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- assert data[0]["user_misery()"] == pytest.approx(0.058, rel=1e-3)
- assert data[1]["user_misery()"] == pytest.approx(0.058, rel=1e-3)
- assert data[2]["user_misery()"] == pytest.approx(0.058, rel=1e-3)
- def test_user_misery_alias_field_with_transaction_threshold_and_project_threshold(self):
- project = self.create_project()
- ProjectTransactionThreshold.objects.create(
- project=project,
- organization=project.organization,
- threshold=100,
- metric=TransactionMetric.DURATION.value,
- )
- events = [
- ("one", 300),
- ("two", 300),
- ("one", 3000),
- ("two", 3000),
- ("three", 400),
- ("four", 4000),
- ]
- for idx, event in enumerate(events):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + idx)),
- duration=timedelta(milliseconds=event[1]),
- )
- data["event_id"] = f"{idx}" * 32
- data["transaction"] = f"/count_miserable/horribilis/{idx}"
- data["user"] = {"email": f"{event[0]}@example.com"}
- self.store_event(data, project_id=project.id)
- if idx % 2:
- ProjectTransactionThresholdOverride.objects.create(
- transaction=f"/count_miserable/horribilis/{idx}",
- project=project,
- organization=project.organization,
- threshold=100 * idx,
- metric=TransactionMetric.DURATION.value,
- )
- project2 = self.create_project()
- data = self.load_data()
- data["transaction"] = "/count_miserable/horribilis/project2"
- data["user"] = {"email": "project2@example.com"}
- self.store_event(data, project_id=project2.id)
- query = {
- "field": [
- "transaction",
- "user_misery()",
- ],
- "query": "event.type:transaction",
- "orderby": "transaction",
- "project": [project.id, project2.id],
- }
- response = self.do_request(
- query,
- features={
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- },
- )
- assert response.status_code == 200, response.content
- expected = [
- (
- "/count_miserable/horribilis/0",
- ["duration", 100],
- 0.049578,
- ), # Uses project threshold
- ("/count_miserable/horribilis/1", ["duration", 100], 0.049578), # Uses txn threshold
- ("/count_miserable/horribilis/2", ["duration", 100], 0.058), # Uses project threshold
- ("/count_miserable/horribilis/3", ["duration", 300], 0.058), # Uses txn threshold
- (
- "/count_miserable/horribilis/4",
- ["duration", 100],
- 0.049578,
- ), # Uses project threshold
- ("/count_miserable/horribilis/5", ["duration", 500], 0.058), # Uses txn threshold
- ("/count_miserable/horribilis/project2", ["duration", 300], 0.058), # Uses fallback
- ]
- assert len(response.data["data"]) == 7
- data = response.data["data"]
- for i, record in enumerate(expected):
- name, threshold_config, misery = record
- assert data[i]["transaction"] == name
- assert data[i]["project_threshold_config"] == threshold_config
- assert data[i]["user_misery()"] == pytest.approx(misery, rel=1e-3)
- query["query"] = "event.type:transaction user_misery():>0.050"
- response = self.do_request(
- query,
- features={
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- },
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 4
- def test_aggregation(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- "tags": {"sub_customer.is-Enterprise-42": "1"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "staging",
- "tags": {"sub_customer.is-Enterprise-42": "1"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- "tags": {"sub_customer.is-Enterprise-42": "0"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "d" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- "tags": {"sub_customer.is-Enterprise-42": "1"},
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["sub_customer.is-Enterprise-42", "count(sub_customer.is-Enterprise-42)"],
- "orderby": "sub_customer.is-Enterprise-42",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0]["count(sub_customer.is-Enterprise-42)"] == 1
- assert data[1]["count(sub_customer.is-Enterprise-42)"] == 3
- def test_aggregation_comparison(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "user": {"email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- event = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "bar@example.com"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "d" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_3"],
- "user": {"email": "bar@example.com"},
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "e" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_3"],
- "user": {"email": "bar@example.com"},
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["issue.id", "count(id)", "count_unique(user)"],
- "query": "count(id):>1 count_unique(user):>1",
- "orderby": "issue.id",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["issue.id"] == event.group_id
- assert data[0]["count(id)"] == 2
- assert data[0]["count_unique(user)"] == 2
- def test_aggregation_alias_comparison(self):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/aggregates/1"
- self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=3),
- )
- data["transaction"] = "/aggregates/2"
- event = self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["transaction", "p95()"],
- "query": "event.type:transaction p95():<4000",
- "orderby": ["transaction"],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["transaction"] == event.transaction
- assert data[0]["p95()"] == 3000
- def test_auto_aggregations(self):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/aggregates/1"
- self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=3),
- )
- data["transaction"] = "/aggregates/2"
- event = self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["transaction", "p75()"],
- "query": "event.type:transaction p95():<4000",
- "orderby": ["transaction"],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["transaction"] == event.transaction
- query = {
- "field": ["transaction"],
- "query": "event.type:transaction p95():<4000",
- "orderby": ["transaction"],
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- def test_aggregation_comparison_with_conditions(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "staging",
- },
- project_id=self.project.id,
- )
- event = self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "d" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["issue.id", "count(id)"],
- "query": "count(id):>1 user.email:foo@example.com environment:prod",
- "orderby": "issue.id",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["issue.id"] == event.group_id
- assert data[0]["count(id)"] == 2
- def test_aggregation_date_comparison_with_conditions(self):
- event = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "staging",
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "d" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["issue.id", "max(timestamp)"],
- "query": "max(timestamp):>1 user.email:foo@example.com environment:prod",
- "orderby": "issue.id",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- assert response.data["meta"]["fields"]["max(timestamp)"] == "date"
- data = response.data["data"]
- assert data[0]["issue.id"] == event.group_id
- def test_percentile_function(self):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/aggregates/1"
- event1 = self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=3),
- )
- data["transaction"] = "/aggregates/2"
- event2 = self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["transaction", "percentile(transaction.duration, 0.95)"],
- "query": "event.type:transaction",
- "orderby": ["transaction"],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0]["transaction"] == event1.transaction
- assert data[0]["percentile(transaction.duration, 0.95)"] == 5000
- assert data[1]["transaction"] == event2.transaction
- assert data[1]["percentile(transaction.duration, 0.95)"] == 3000
- def test_percentile_function_as_condition(self):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/aggregates/1"
- event1 = self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=3),
- )
- data["transaction"] = "/aggregates/2"
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["transaction", "percentile(transaction.duration, 0.95)"],
- "query": "event.type:transaction percentile(transaction.duration, 0.95):>4000",
- "orderby": ["transaction"],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["transaction"] == event1.transaction
- assert data[0]["percentile(transaction.duration, 0.95)"] == 5000
- def test_epm_function(self):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/aggregates/1"
- event1 = self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=3),
- )
- data["transaction"] = "/aggregates/2"
- event2 = self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["transaction", "epm()"],
- "query": "event.type:transaction",
- "orderby": ["transaction"],
- "start": self.eleven_mins_ago_iso,
- "end": iso_format(self.nine_mins_ago),
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0]["transaction"] == event1.transaction
- assert data[0]["epm()"] == 0.5
- assert data[1]["transaction"] == event2.transaction
- assert data[1]["epm()"] == 0.5
- meta = response.data["meta"]
- assert meta["fields"]["epm()"] == "rate"
- assert meta["units"]["epm()"] == "1/minute"
- def test_nonexistent_fields(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {"field": ["issue_world.id"]}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["issue_world.id"] == ""
- def test_no_requested_fields_or_grouping(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {"query": "test"}
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- assert response.data["detail"] == "No columns selected"
- def test_condition_on_aggregate_misses(self):
- self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "bar@example.com"},
- },
- project_id=self.project.id,
- )
- query = {"field": ["issue.id"], "query": "event_count:>0", "orderby": "issue.id"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_next_prev_link_headers(self):
- events = [("a", "group_1"), ("b", "group_2"), ("c", "group_2"), ("d", "group_2")]
- for e in events:
- self.store_event(
- data={
- "event_id": e[0] * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": [e[1]],
- "user": {"email": "foo@example.com"},
- "tags": {"language": "C++"},
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["count(id)", "issue.id", "context.key"],
- "sort": "-count_id",
- "query": "language:C++",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- links = parse_link_header(response["Link"])
- for link in links:
- assert "field=issue.id" in link
- assert "field=count%28id%29" in link
- assert "field=context.key" in link
- assert "sort=-count_id" in link
- assert "query=language%3AC%2B%2B" in link
- assert len(response.data["data"]) == 2
- data = response.data["data"]
- assert data[0]["count(id)"] == 3
- assert data[1]["count(id)"] == 1
- def test_empty_count_query(self):
- event = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["1123581321"],
- "user": {"email": "foo@example.com"},
- "tags": {"language": "C++"},
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["count()"],
- "query": f"issue.id:{event.group_id} timestamp:>{self.ten_mins_ago_iso}",
- "statsPeriod": "14d",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count()"] == 0
- def test_stack_wildcard_condition(self):
- data = self.load_data(platform="javascript")
- data["timestamp"] = self.ten_mins_ago_iso
- self.store_event(data=data, project_id=self.project.id)
- query = {"field": ["stack.filename", "message"], "query": "stack.filename:*.js"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["meta"]["fields"]["message"] == "string"
- def test_email_wildcard_condition(self):
- data = self.load_data(platform="javascript")
- data["timestamp"] = self.ten_mins_ago_iso
- self.store_event(data=data, project_id=self.project.id)
- query = {"field": ["stack.filename", "message"], "query": "user.email:*@example.org"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["meta"]["fields"]["message"] == "string"
- def test_release_wildcard_condition(self):
- release = self.create_release(version="test@1.2.3+123")
- self.store_event(
- data={"release": release.version, "timestamp": self.ten_mins_ago_iso},
- project_id=self.project.id,
- )
- query = {"field": ["stack.filename", "release"], "query": "release:test*"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["release"] == release.version
- def test_transaction_event_type(self):
- self.store_event(data=self.transaction_data, project_id=self.project.id)
- query = {
- "field": ["transaction", "transaction.duration", "transaction.status"],
- "query": "event.type:transaction",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["meta"]["fields"]["transaction.duration"] == "duration"
- assert response.data["meta"]["fields"]["transaction.status"] == "string"
- assert response.data["meta"]["units"]["transaction.duration"] == "millisecond"
- assert response.data["data"][0]["transaction.status"] == "ok"
- def test_trace_columns(self):
- self.store_event(data=self.transaction_data, project_id=self.project.id)
- query = {"field": ["trace"], "query": "event.type:transaction"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["meta"]["fields"]["trace"] == "string"
- assert (
- response.data["data"][0]["trace"]
- == self.transaction_data["contexts"]["trace"]["trace_id"]
- )
- def test_issue_in_columns(self):
- project1 = self.create_project()
- project2 = self.create_project()
- event1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=project1.id,
- )
- event2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {"field": ["id", "issue"], "orderby": ["id"]}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["id"] == event1.event_id
- assert data[0]["issue.id"] == event1.group_id
- assert data[0]["issue"] == event1.group.qualified_short_id
- assert data[1]["id"] == event2.event_id
- assert data[1]["issue.id"] == event2.group_id
- assert data[1]["issue"] == event2.group.qualified_short_id
- def test_issue_in_search_and_columns(self):
- project1 = self.create_project()
- project2 = self.create_project()
- event1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=project1.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=project2.id,
- )
- tests = [
- ("issue", "issue:%s" % event1.group.qualified_short_id),
- ("issue.id", "issue:%s" % event1.group.qualified_short_id),
- ("issue", "issue.id:%s" % event1.group_id),
- ("issue.id", "issue.id:%s" % event1.group_id),
- ]
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- for testdata in tests:
- query = {"field": [testdata[0]], "query": testdata[1]}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["id"] == event1.event_id
- assert data[0]["issue.id"] == event1.group_id
- if testdata[0] == "issue":
- assert data[0]["issue"] == event1.group.qualified_short_id
- else:
- assert data[0].get("issue", None) is None
- def test_issue_negation(self):
- project1 = self.create_project()
- project2 = self.create_project()
- event1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=project1.id,
- )
- event2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "go really fast plz",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["title", "issue.id"],
- "query": f"!issue:{event1.group.qualified_short_id}",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["title"] == event2.title
- assert data[0]["issue.id"] == event2.group_id
- def test_search_for_nonexistent_issue(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {"field": ["count()"], "query": "issue.id:112358"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count()"] == 0
- def test_issue_alias_inside_aggregate(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- },
- project_id=self.project.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["project", "count(id)", "count_unique(issue.id)", "count_unique(issue)"],
- "sort": "-count(id)",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count(id)"] == 2
- assert data[0]["count_unique(issue.id)"] == 2
- assert data[0]["count_unique(issue)"] == 2
- def test_project_alias_inside_aggregate(self):
- project1 = self.create_project()
- project2 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=project1.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": [
- "event.type",
- "count(id)",
- "count_unique(project.id)",
- "count_unique(project)",
- ],
- "sort": "-count(id)",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count(id)"] == 2
- assert data[0]["count_unique(project.id)"] == 2
- assert data[0]["count_unique(project)"] == 2
- def test_user_display(self):
- project1 = self.create_project()
- project2 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"email": "cathy@example.com"},
- },
- project_id=project1.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"username": "catherine"},
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "user.display"],
- "query": "user.display:cath*",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- result = {r["user.display"] for r in data}
- assert result == {"catherine", "cathy@example.com"}
- def test_user_display_with_aggregates(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"email": "cathy@example.com"},
- },
- project_id=self.project.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "user.display", "count_unique(title)"],
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- result = {r["user.display"] for r in data}
- assert result == {"cathy@example.com"}
- query = {"field": ["event.type", "count_unique(user.display)"], "statsPeriod": "24h"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count_unique(user.display)"] == 1
- def test_orderby_user_display(self):
- project1 = self.create_project()
- project2 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"email": "cathy@example.com"},
- },
- project_id=project1.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"username": "catherine"},
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "user.display"],
- "query": "user.display:cath*",
- "statsPeriod": "24h",
- "orderby": "-user.display",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- result = [r["user.display"] for r in data]
- # because we're ordering by `-user.display`, we expect the results in reverse sorted order
- assert result == ["cathy@example.com", "catherine"]
- def test_orderby_user_display_with_aggregates(self):
- project1 = self.create_project()
- project2 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"email": "cathy@example.com"},
- },
- project_id=project1.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"username": "catherine"},
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "user.display", "count_unique(title)"],
- "query": "user.display:cath*",
- "statsPeriod": "24h",
- "orderby": "user.display",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- result = [r["user.display"] for r in data]
- # because we're ordering by `user.display`, we expect the results in sorted order
- assert result == ["catherine", "cathy@example.com"]
- def test_any_field_alias(self):
- day_ago = before_now(days=1).replace(hour=10, minute=11, second=12, microsecond=13)
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": iso_format(day_ago),
- "user": {"email": "cathy@example.com"},
- },
- project_id=self.project.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": [
- "event.type",
- "any(user.display)",
- "any(timestamp.to_day)",
- "any(timestamp.to_hour)",
- ],
- "statsPeriod": "7d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- result = {r["any(user.display)"] for r in data}
- assert result == {"cathy@example.com"}
- result = {r["any(timestamp.to_day)"][:19] for r in data}
- assert result == {iso_format(day_ago.replace(hour=0, minute=0, second=0, microsecond=0))}
- result = {r["any(timestamp.to_hour)"][:19] for r in data}
- assert result == {iso_format(day_ago.replace(minute=0, second=0, microsecond=0))}
- def test_field_aliases_in_conflicting_functions(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": iso_format(
- before_now(days=1).replace(hour=10, minute=11, second=12, microsecond=13)
- ),
- "user": {"email": "cathy@example.com"},
- },
- project_id=self.project.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- field_aliases = ["user.display", "timestamp.to_day", "timestamp.to_hour"]
- for alias in field_aliases:
- query = {
- "field": [alias, f"any({alias})"],
- "statsPeriod": "7d",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 400, response.content
- assert (
- response.data["detail"]
- == f"A single field cannot be used both inside and outside a function in the same query. To use {alias} you must first remove the function(s): any({alias})"
- )
- @pytest.mark.skip(
- """
- For some reason ClickHouse errors when there are two of the same string literals
- (in this case the empty string "") in a query and one is in the prewhere clause.
- Does not affect production or ClickHouse versions > 20.4.
- """
- )
- def test_has_message(self):
- event = self.store_event(
- {"timestamp": self.ten_mins_ago_iso, "message": "a"}, project_id=self.project.id
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {"field": ["project", "message"], "query": "has:message", "statsPeriod": "14d"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["message"] == event.message
- query = {"field": ["project", "message"], "query": "!has:message", "statsPeriod": "14d"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 0
- def test_has_transaction_status(self):
- self.store_event(self.transaction_data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "count(id)"],
- "query": "event.type:transaction has:transaction.status",
- "sort": "-count(id)",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count(id)"] == 1
- @pytest.mark.xfail(reason="Started failing on ClickHouse 21.8")
- def test_not_has_transaction_status(self):
- self.store_event(self.transaction_data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "count(id)"],
- "query": "event.type:transaction !has:transaction.status",
- "sort": "-count(id)",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count(id)"] == 0
- def test_tag_that_looks_like_aggregation(self):
- data = {
- "message": "Failure state",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"count_diff": 99},
- }
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["message", "count_diff", "count()"],
- "query": "",
- "project": [self.project.id],
- "statsPeriod": "24h",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- meta = response.data["meta"]["fields"]
- assert "string" == meta["count_diff"], "tags should not be counted as integers"
- assert "string" == meta["message"]
- assert "integer" == meta["count()"]
- assert 1 == len(response.data["data"])
- data = response.data["data"][0]
- assert "99" == data["count_diff"]
- assert "Failure state" == data["message"]
- assert 1 == data["count()"]
- def test_aggregate_negation(self):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- self.store_event(data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "count()"],
- "query": "event.type:transaction count():1",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- query = {
- "field": ["event.type", "count()"],
- "query": "event.type:transaction !count():1",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 0
- def test_all_aggregates_in_columns(self):
- data = self.load_data(
- timestamp=self.eleven_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/failure_rate/1"
- self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/failure_rate/1"
- data["contexts"]["trace"]["status"] = "unauthenticated"
- event = self.store_event(data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": [
- "event.type",
- "p50()",
- "p75()",
- "p95()",
- "p99()",
- "p100()",
- "percentile(transaction.duration, 0.99)",
- "apdex(300)",
- "count_miserable(user, 300)",
- "user_misery(300)",
- "failure_rate()",
- ],
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- meta = response.data["meta"]["fields"]
- units = response.data["meta"]["units"]
- assert meta["p50()"] == "duration"
- assert meta["p75()"] == "duration"
- assert meta["p95()"] == "duration"
- assert meta["p99()"] == "duration"
- assert meta["p100()"] == "duration"
- assert meta["percentile(transaction.duration, 0.99)"] == "duration"
- assert meta["apdex(300)"] == "number"
- assert meta["failure_rate()"] == "percentage"
- assert meta["user_misery(300)"] == "number"
- assert meta["count_miserable(user, 300)"] == "integer"
- assert units["p50()"] == "millisecond"
- assert units["p75()"] == "millisecond"
- assert units["p95()"] == "millisecond"
- assert units["p99()"] == "millisecond"
- assert units["p100()"] == "millisecond"
- assert units["percentile(transaction.duration, 0.99)"] == "millisecond"
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p50()"] == 5000
- assert data[0]["p75()"] == 5000
- assert data[0]["p95()"] == 5000
- assert data[0]["p99()"] == 5000
- assert data[0]["p100()"] == 5000
- assert data[0]["percentile(transaction.duration, 0.99)"] == 5000
- assert data[0]["apdex(300)"] == 0.0
- assert data[0]["count_miserable(user, 300)"] == 1
- assert data[0]["user_misery(300)"] == 0.058
- assert data[0]["failure_rate()"] == 0.5
- features = {
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- }
- query = {
- "field": [
- "event.type",
- "p50()",
- "p75()",
- "p95()",
- "p99()",
- "p100()",
- "percentile(transaction.duration, 0.99)",
- "apdex(300)",
- "apdex()",
- "count_miserable(user, 300)",
- "user_misery(300)",
- "failure_rate()",
- "count_miserable(user)",
- "user_misery()",
- ],
- "query": "event.type:transaction",
- "project": [self.project.id],
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- meta = response.data["meta"]["fields"]
- units = response.data["meta"]["units"]
- assert meta["p50()"] == "duration"
- assert meta["p75()"] == "duration"
- assert meta["p95()"] == "duration"
- assert meta["p99()"] == "duration"
- assert meta["p100()"] == "duration"
- assert meta["percentile(transaction.duration, 0.99)"] == "duration"
- assert meta["apdex(300)"] == "number"
- assert meta["apdex()"] == "number"
- assert meta["failure_rate()"] == "percentage"
- assert meta["user_misery(300)"] == "number"
- assert meta["count_miserable(user, 300)"] == "integer"
- assert meta["project_threshold_config"] == "string"
- assert meta["user_misery()"] == "number"
- assert meta["count_miserable(user)"] == "integer"
- assert units["p50()"] == "millisecond"
- assert units["p75()"] == "millisecond"
- assert units["p95()"] == "millisecond"
- assert units["p99()"] == "millisecond"
- assert units["p100()"] == "millisecond"
- assert units["percentile(transaction.duration, 0.99)"] == "millisecond"
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p50()"] == 5000
- assert data[0]["p75()"] == 5000
- assert data[0]["p95()"] == 5000
- assert data[0]["p99()"] == 5000
- assert data[0]["p100()"] == 5000
- assert data[0]["percentile(transaction.duration, 0.99)"] == 5000
- assert data[0]["apdex(300)"] == 0.0
- assert data[0]["apdex()"] == 0.0
- assert data[0]["count_miserable(user, 300)"] == 1
- assert data[0]["user_misery(300)"] == 0.058
- assert data[0]["failure_rate()"] == 0.5
- assert data[0]["project_threshold_config"] == ["duration", 300]
- assert data[0]["user_misery()"] == 0.058
- assert data[0]["count_miserable(user)"] == 1
- query = {
- "field": ["event.type", "last_seen()", "latest_event()"],
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert self.ten_mins_ago_iso[:-5] in data[0]["last_seen()"]
- assert data[0]["latest_event()"] == event.event_id
- query = {
- "field": [
- "event.type",
- "count()",
- "count(id)",
- "count_unique(project)",
- "min(transaction.duration)",
- "max(transaction.duration)",
- "avg(transaction.duration)",
- "stddev(transaction.duration)",
- "var(transaction.duration)",
- "cov(transaction.duration, transaction.duration)",
- "corr(transaction.duration, transaction.duration)",
- "linear_regression(transaction.duration, transaction.duration)",
- "sum(transaction.duration)",
- ],
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count()"] == 2
- assert data[0]["count(id)"] == 2
- assert data[0]["count_unique(project)"] == 1
- assert data[0]["min(transaction.duration)"] == 5000
- assert data[0]["max(transaction.duration)"] == 5000
- assert data[0]["avg(transaction.duration)"] == 5000
- assert data[0]["stddev(transaction.duration)"] == 0.0
- assert data[0]["var(transaction.duration)"] == 0.0
- assert data[0]["cov(transaction.duration, transaction.duration)"] == 0.0
- assert data[0]["corr(transaction.duration, transaction.duration)"] == 0.0
- assert data[0]["linear_regression(transaction.duration, transaction.duration)"] == [0, 0]
- assert data[0]["sum(transaction.duration)"] == 10000
- @requires_not_arm64
- def test_null_user_misery_returns_zero(self):
- self.transaction_data["user"] = None
- self.transaction_data["transaction"] = "/no_users/1"
- self.store_event(self.transaction_data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["user_misery(300)"],
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- meta = response.data["meta"]["fields"]
- assert meta["user_misery(300)"] == "number"
- data = response.data["data"]
- assert data[0]["user_misery(300)"] == 0
- @requires_not_arm64
- def test_null_user_misery_new_returns_zero(self):
- self.transaction_data["user"] = None
- self.transaction_data["transaction"] = "/no_users/1"
- self.store_event(self.transaction_data, project_id=self.project.id)
- features = {
- "organizations:discover-basic": True,
- }
- query = {
- "field": ["user_misery()"],
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- meta = response.data["meta"]["fields"]
- assert meta["user_misery()"] == "number"
- data = response.data["data"]
- assert data[0]["user_misery()"] == 0
- def test_all_aggregates_in_query(self):
- data = self.load_data(
- timestamp=self.eleven_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/failure_rate/1"
- self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/failure_rate/2"
- data["contexts"]["trace"]["status"] = "unauthenticated"
- self.store_event(data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": [
- "event.type",
- "p50()",
- "p75()",
- "p95()",
- "percentile(transaction.duration, 0.99)",
- "p100()",
- ],
- "query": "event.type:transaction p50():>100 p75():>1000 p95():>1000 p100():>1000 percentile(transaction.duration, 0.99):>1000",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p50()"] == 5000
- assert data[0]["p75()"] == 5000
- assert data[0]["p95()"] == 5000
- assert data[0]["p100()"] == 5000
- assert data[0]["percentile(transaction.duration, 0.99)"] == 5000
- query = {
- "field": [
- "event.type",
- "apdex(300)",
- "count_miserable(user, 300)",
- "user_misery(300)",
- "failure_rate()",
- ],
- "query": "event.type:transaction apdex(300):>-1.0 failure_rate():>0.25",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["apdex(300)"] == 0.0
- assert data[0]["count_miserable(user, 300)"] == 1
- assert data[0]["user_misery(300)"] == 0.058
- assert data[0]["failure_rate()"] == 0.5
- query = {
- "field": ["event.type", "last_seen()", "latest_event()"],
- "query": "event.type:transaction last_seen():>1990-12-01T00:00:00",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- query = {
- "field": ["event.type", "count()", "count(id)", "count_unique(transaction)"],
- "query": "event.type:transaction count():>1 count(id):>1 count_unique(transaction):>1",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count()"] == 2
- assert data[0]["count(id)"] == 2
- assert data[0]["count_unique(transaction)"] == 2
- query = {
- "field": [
- "event.type",
- "min(transaction.duration)",
- "max(transaction.duration)",
- "avg(transaction.duration)",
- "sum(transaction.duration)",
- "stddev(transaction.duration)",
- "var(transaction.duration)",
- "cov(transaction.duration, transaction.duration)",
- "corr(transaction.duration, transaction.duration)",
- ],
- "query": " ".join(
- [
- "event.type:transaction",
- "min(transaction.duration):>1000",
- "max(transaction.duration):>1000",
- "avg(transaction.duration):>1000",
- "sum(transaction.duration):>1000",
- "stddev(transaction.duration):>=0.0",
- "var(transaction.duration):>=0.0",
- "cov(transaction.duration, transaction.duration):>=0.0",
- # correlation is nan because variance is 0
- # "corr(transaction.duration, transaction.duration):>=0.0",
- ]
- ),
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["min(transaction.duration)"] == 5000
- assert data[0]["max(transaction.duration)"] == 5000
- assert data[0]["avg(transaction.duration)"] == 5000
- assert data[0]["sum(transaction.duration)"] == 10000
- assert data[0]["stddev(transaction.duration)"] == 0.0
- assert data[0]["var(transaction.duration)"] == 0.0
- assert data[0]["cov(transaction.duration, transaction.duration)"] == 0.0
- assert data[0]["corr(transaction.duration, transaction.duration)"] == 0.0
- query = {
- "field": ["event.type", "apdex(400)"],
- "query": "event.type:transaction apdex(400):0",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["apdex(400)"] == 0
- def test_functions_in_orderby(self):
- data = self.load_data(
- timestamp=self.eleven_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/failure_rate/1"
- self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/failure_rate/2"
- data["contexts"]["trace"]["status"] = "unauthenticated"
- event = self.store_event(data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "p75()"],
- "sort": "-p75",
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p75()"] == 5000
- query = {
- "field": ["event.type", "percentile(transaction.duration, 0.99)"],
- "sort": "-percentile_transaction_duration_0_99",
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["percentile(transaction.duration, 0.99)"] == 5000
- query = {
- "field": ["event.type", "apdex(300)"],
- "sort": "-apdex(300)",
- "query": "event.type:transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["apdex(300)"] == 0.0
- query = {
- "field": ["event.type", "latest_event()"],
- "query": "event.type:transaction",
- "sort": "latest_event",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["latest_event()"] == event.event_id
- query = {
- "field": ["event.type", "count_unique(transaction)"],
- "query": "event.type:transaction",
- "sort": "-count_unique_transaction",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count_unique(transaction)"] == 2
- query = {
- "field": ["event.type", "min(transaction.duration)"],
- "query": "event.type:transaction",
- "sort": "-min_transaction_duration",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["min(transaction.duration)"] == 5000
- def test_issue_alias_in_aggregate(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.eleven_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- },
- project_id=self.project.id,
- )
- query = {"field": ["event.type", "count_unique(issue)"], "query": "count_unique(issue):>1"}
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count_unique(issue)"] == 2
- def test_deleted_issue_in_results(self):
- event1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.eleven_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- event2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- },
- project_id=self.project.id,
- )
- event2.group.delete()
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {"field": ["issue", "count()"], "sort": "issue.id"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["issue"] == event1.group.qualified_short_id
- assert data[1]["issue"] == "unknown"
- def test_last_seen_negative_duration(self):
- self.store_event(
- data={
- "event_id": "f" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {"field": ["id", "last_seen()"], "query": "last_seen():-30d"}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["id"] == "f" * 32
- def test_last_seen_aggregate_condition(self):
- self.store_event(
- data={
- "event_id": "f" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["id", "last_seen()"],
- "query": f"last_seen():>{iso_format(before_now(days=30))}",
- }
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["id"] == "f" * 32
- def test_conditional_filter(self):
- for v in ["a", "b"]:
- self.store_event(
- data={
- "event_id": v * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["id"],
- "query": "id:{} OR id:{}".format("a" * 32, "b" * 32),
- "orderby": "id",
- }
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["id"] == "a" * 32
- assert data[1]["id"] == "b" * 32
- def test_aggregation_comparison_with_conditional_filter(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "staging",
- },
- project_id=self.project.id,
- )
- event = self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "prod",
- },
- project_id=self.project.id,
- )
- self.store_event(
- data={
- "event_id": "d" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "user": {"email": "foo@example.com"},
- "environment": "canary",
- },
- project_id=self.project.id,
- )
- query = {
- "field": ["issue.id", "count(id)"],
- "query": "count(id):>1 user.email:foo@example.com AND (environment:prod OR environment:staging)",
- "orderby": "issue.id",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["issue.id"] == event.group_id
- assert data[0]["count(id)"] == 2
- def run_test_in_query(self, query, expected_events, expected_negative_events=None):
- params = {
- "field": ["id"],
- "query": query,
- "orderby": "id",
- }
- response = self.do_request(
- params, {"organizations:discover-basic": True, "organizations:global-views": True}
- )
- assert response.status_code == 200, response.content
- assert [row["id"] for row in response.data["data"]] == [e.event_id for e in expected_events]
- if expected_negative_events is not None:
- params["query"] = f"!{query}"
- response = self.do_request(
- params,
- {"organizations:discover-basic": True, "organizations:global-views": True},
- )
- assert response.status_code == 200, response.content
- assert [row["id"] for row in response.data["data"]] == [
- e.event_id for e in expected_negative_events
- ]
- def test_in_query_events(self):
- project_1 = self.create_project()
- event_1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- "message": "group1",
- "user": {"email": "hello@example.com"},
- "environment": "prod",
- "tags": {"random": "123"},
- "release": "1.0",
- },
- project_id=project_1.id,
- )
- project_2 = self.create_project()
- event_2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_2"],
- "message": "group2",
- "user": {"email": "bar@example.com"},
- "environment": "staging",
- "tags": {"random": "456"},
- "stacktrace": {"frames": [{"filename": "src/app/group2.py"}]},
- "release": "1.2",
- },
- project_id=project_2.id,
- )
- project_3 = self.create_project()
- event_3 = self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_3"],
- "message": "group3",
- "user": {"email": "foo@example.com"},
- "environment": "canary",
- "tags": {"random": "789"},
- },
- project_id=project_3.id,
- )
- self.run_test_in_query("environment:[prod, staging]", [event_1, event_2], [event_3])
- self.run_test_in_query("environment:[staging]", [event_2], [event_1, event_3])
- self.run_test_in_query(
- "user.email:[foo@example.com, hello@example.com]", [event_1, event_3], [event_2]
- )
- self.run_test_in_query("user.email:[foo@example.com]", [event_3], [event_1, event_2])
- self.run_test_in_query(
- "user.display:[foo@example.com, hello@example.com]", [event_1, event_3], [event_2]
- )
- self.run_test_in_query(
- 'message:["group2 src/app/group2.py in ?", group1]', [event_1, event_2], [event_3]
- )
- self.run_test_in_query(
- f"issue.id:[{event_1.group_id},{event_2.group_id}]", [event_1, event_2]
- )
- self.run_test_in_query(
- f"issue:[{event_1.group.qualified_short_id},{event_2.group.qualified_short_id}]",
- [event_1, event_2],
- )
- self.run_test_in_query(
- f"issue:[{event_1.group.qualified_short_id},{event_2.group.qualified_short_id}, unknown]",
- [event_1, event_2],
- )
- self.run_test_in_query(f"project_id:[{project_3.id},{project_2.id}]", [event_2, event_3])
- self.run_test_in_query(
- f"project.name:[{project_3.slug},{project_2.slug}]", [event_2, event_3]
- )
- self.run_test_in_query("random:[789,456]", [event_2, event_3], [event_1])
- self.run_test_in_query("tags[random]:[789,456]", [event_2, event_3], [event_1])
- self.run_test_in_query("release:[1.0,1.2]", [event_1, event_2], [event_3])
- def test_in_query_events_stack(self):
- test_js = self.store_event(
- self.load_data(
- platform="javascript",
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- ),
- project_id=self.project.id,
- )
- test_java = self.store_event(
- self.load_data(
- platform="java",
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- ),
- project_id=self.project.id,
- )
- self.run_test_in_query(
- "stack.filename:[../../sentry/scripts/views.js]", [test_js], [test_java]
- )
- def test_in_query_transactions(self):
- data = self.transaction_data.copy()
- data["event_id"] = "a" * 32
- data["contexts"]["trace"]["status"] = "ok"
- transaction_1 = self.store_event(data, project_id=self.project.id)
- data = self.transaction_data.copy()
- data["event_id"] = "b" * 32
- data["contexts"]["trace"]["status"] = "aborted"
- transaction_2 = self.store_event(data, project_id=self.project.id)
- data = self.transaction_data.copy()
- data["event_id"] = "c" * 32
- data["contexts"]["trace"]["status"] = "already_exists"
- transaction_3 = self.store_event(data, project_id=self.project.id)
- self.run_test_in_query(
- "transaction.status:[aborted, already_exists]",
- [transaction_2, transaction_3],
- [transaction_1],
- )
- def test_messed_up_function_values(self):
- # TODO (evanh): It would be nice if this surfaced an error to the user.
- # The problem: The && causes the parser to treat that term not as a bad
- # function call but a valid raw search with parens in it. It's not trivial
- # to change the parser to recognize "bad function values" and surface them.
- for v in ["a", "b"]:
- self.store_event(
- data={
- "event_id": v * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group_1"],
- },
- project_id=self.project.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": [
- "transaction",
- "project",
- "epm()",
- "p50()",
- "p95()",
- "failure_rate()",
- "apdex(300)",
- "count_unique(user)",
- "user_misery(300)",
- "count_miserable(user, 300)",
- ],
- "query": "failure_rate():>0.003&& users:>10 event.type:transaction",
- "sort": "-failure_rate",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 0
- def test_context_fields_between_datasets(self):
- event_data = self.load_data(platform="android")
- transaction_data = self.load_data()
- event_data["spans"] = transaction_data["spans"]
- event_data["contexts"]["trace"] = transaction_data["contexts"]["trace"]
- event_data["type"] = "transaction"
- event_data["transaction"] = "/failure_rate/1"
- event_data["timestamp"] = iso_format(self.ten_mins_ago)
- event_data["start_timestamp"] = iso_format(before_now(minutes=10, seconds=5))
- event_data["user"]["geo"] = {"country_code": "US", "region": "CA", "city": "San Francisco"}
- self.store_event(event_data, project_id=self.project.id)
- event_data["type"] = "error"
- self.store_event(event_data, project_id=self.project.id)
- fields = [
- "os.build",
- "os.kernel_version",
- "device.arch",
- # TODO: battery level is not consistent across both datasets
- # "device.battery_level",
- "device.brand",
- "device.charging",
- "device.locale",
- "device.model_id",
- "device.name",
- "device.online",
- "device.orientation",
- "device.simulator",
- "device.uuid",
- ]
- data = [
- {"field": fields + ["location", "count()"], "query": "event.type:error"},
- {"field": fields + ["duration", "count()"], "query": "event.type:transaction"},
- ]
- for datum in data:
- response = self.do_request(datum)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1, datum
- results = response.data["data"]
- assert results[0]["count()"] == 1, datum
- for field in fields:
- key, value = field.split(".", 1)
- expected = str(event_data["contexts"][key][value])
- assert results[0][field] == expected, field + str(datum)
- def test_http_fields_between_datasets(self):
- event_data = self.load_data(platform="android")
- transaction_data = self.load_data()
- event_data["spans"] = transaction_data["spans"]
- event_data["contexts"]["trace"] = transaction_data["contexts"]["trace"]
- event_data["type"] = "transaction"
- event_data["transaction"] = "/failure_rate/1"
- event_data["timestamp"] = iso_format(self.ten_mins_ago)
- event_data["start_timestamp"] = iso_format(before_now(minutes=10, seconds=5))
- event_data["user"]["geo"] = {"country_code": "US", "region": "CA", "city": "San Francisco"}
- event_data["request"] = transaction_data["request"]
- self.store_event(event_data, project_id=self.project.id)
- event_data["type"] = "error"
- self.store_event(event_data, project_id=self.project.id)
- fields = ["http.method", "http.referer", "http.url"]
- expected = ["GET", "fixtures.transaction", "http://countries:8010/country_by_code/"]
- data = [
- {"field": fields + ["location", "count()"], "query": "event.type:error"},
- {"field": fields + ["duration", "count()"], "query": "event.type:transaction"},
- ]
- for datum in data:
- response = self.do_request(datum)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1, datum
- results = response.data["data"]
- assert results[0]["count()"] == 1, datum
- for field, exp in zip(fields, expected):
- assert results[0][field] == exp, field + str(datum)
- def test_failure_count_alias_field(self):
- data = self.transaction_data.copy()
- data["transaction"] = "/failure_count/success"
- self.store_event(data, project_id=self.project.id)
- data = self.transaction_data.copy()
- data["transaction"] = "/failure_count/unknown"
- data["contexts"]["trace"]["status"] = "unknown_error"
- self.store_event(data, project_id=self.project.id)
- for i in range(6):
- data = self.transaction_data.copy()
- data["transaction"] = f"/failure_count/{i}"
- data["contexts"]["trace"]["status"] = "unauthenticated"
- self.store_event(data, project_id=self.project.id)
- query = {"field": ["count()", "failure_count()"], "query": "event.type:transaction"}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["count()"] == 8
- assert data[0]["failure_count()"] == 6
- @mock.patch("sentry.utils.snuba.quantize_time")
- def test_quantize_dates(self, mock_quantize):
- self.create_project()
- mock_quantize.return_value = before_now(days=1).replace(tzinfo=timezone.utc)
- # Don't quantize short time periods
- query = {"statsPeriod": "1h", "query": "", "field": ["id", "timestamp"]}
- self.do_request(query)
- # Don't quantize absolute date periods
- self.do_request(query)
- query = {
- "start": iso_format(before_now(days=20)),
- "end": iso_format(before_now(days=15)),
- "query": "",
- "field": ["id", "timestamp"],
- }
- self.do_request(query)
- assert len(mock_quantize.mock_calls) == 0
- # Quantize long date periods
- query = {"field": ["id", "timestamp"], "statsPeriod": "90d", "query": ""}
- self.do_request(query)
- assert len(mock_quantize.mock_calls) == 2
- def test_limit_number_of_fields(self):
- self.create_project()
- for i in range(1, 25):
- response = self.do_request({"field": ["id"] * i})
- if i <= 20:
- assert response.status_code == 200
- else:
- assert response.status_code == 400
- assert (
- response.data["detail"]
- == "You can view up to 20 fields at a time. Please delete some and try again."
- )
- def test_percentile_function_meta_types(self):
- self.store_event(self.transaction_data, project_id=self.project.id)
- query = {
- "field": [
- "transaction",
- "percentile(transaction.duration, 0.95)",
- "percentile(measurements.fp, 0.95)",
- "percentile(measurements.fcp, 0.95)",
- "percentile(measurements.lcp, 0.95)",
- "percentile(measurements.fid, 0.95)",
- "percentile(measurements.ttfb, 0.95)",
- "percentile(measurements.ttfb.requesttime, 0.95)",
- "percentile(measurements.cls, 0.95)",
- "percentile(measurements.foo, 0.95)",
- "percentile(measurements.bar, 0.95)",
- ],
- "query": "",
- "orderby": ["transaction"],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- meta = response.data["meta"]["fields"]
- assert meta["percentile(transaction.duration, 0.95)"] == "duration"
- assert meta["percentile(measurements.fp, 0.95)"] == "duration"
- assert meta["percentile(measurements.fcp, 0.95)"] == "duration"
- assert meta["percentile(measurements.lcp, 0.95)"] == "duration"
- assert meta["percentile(measurements.fid, 0.95)"] == "duration"
- assert meta["percentile(measurements.ttfb, 0.95)"] == "duration"
- assert meta["percentile(measurements.ttfb.requesttime, 0.95)"] == "duration"
- assert meta["percentile(measurements.cls, 0.95)"] == "number"
- assert meta["percentile(measurements.foo, 0.95)"] == "number"
- assert meta["percentile(measurements.bar, 0.95)"] == "number"
- units = response.data["meta"]["units"]
- assert units["percentile(transaction.duration, 0.95)"] == "millisecond"
- assert units["percentile(measurements.fp, 0.95)"] == "millisecond"
- assert units["percentile(measurements.fcp, 0.95)"] == "millisecond"
- assert units["percentile(measurements.lcp, 0.95)"] == "millisecond"
- assert units["percentile(measurements.fid, 0.95)"] == "millisecond"
- assert units["percentile(measurements.ttfb, 0.95)"] == "millisecond"
- assert units["percentile(measurements.ttfb.requesttime, 0.95)"] == "millisecond"
- def test_count_at_least_query(self):
- self.store_event(self.transaction_data, self.project.id)
- response = self.do_request({"field": "count_at_least(measurements.fcp, 0)"})
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["count_at_least(measurements.fcp, 0)"] == 1
- # a value that's a little bigger than the stored fcp
- fcp = int(self.transaction_data["measurements"]["fcp"]["value"] + 1)
- response = self.do_request({"field": f"count_at_least(measurements.fcp, {fcp})"})
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- assert response.data["data"][0][f"count_at_least(measurements.fcp, {fcp})"] == 0
- def test_measurements_query(self):
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "measurements.fp",
- "measurements.fcp",
- "measurements.lcp",
- "measurements.fid",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- for field in query["field"]:
- measure = field.split(".", 1)[1]
- assert (
- response.data["data"][0][field]
- == self.transaction_data["measurements"][measure]["value"]
- )
- query = {
- "field": [
- "measurements.fP",
- "measurements.Fcp",
- "measurements.LcP",
- "measurements.FID",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- for field in query["field"]:
- measure = field.split(".", 1)[1].lower()
- assert (
- response.data["data"][0][field]
- == self.transaction_data["measurements"][measure]["value"]
- )
- def test_measurements_aggregations(self):
- self.store_event(self.transaction_data, self.project.id)
- # should try all the potential aggregates
- # Skipped tests for stddev and var since sampling one data point
- # results in nan.
- query = {
- "field": [
- "percentile(measurements.fcp, 0.5)",
- "count_unique(measurements.fcp)",
- "min(measurements.fcp)",
- "max(measurements.fcp)",
- "avg(measurements.fcp)",
- "sum(measurements.fcp)",
- ],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert (
- response.data["data"][0]["percentile(measurements.fcp, 0.5)"]
- == self.transaction_data["measurements"]["fcp"]["value"]
- )
- assert response.data["data"][0]["count_unique(measurements.fcp)"] == 1
- assert (
- response.data["data"][0]["min(measurements.fcp)"]
- == self.transaction_data["measurements"]["fcp"]["value"]
- )
- assert (
- response.data["data"][0]["max(measurements.fcp)"]
- == self.transaction_data["measurements"]["fcp"]["value"]
- )
- assert (
- response.data["data"][0]["avg(measurements.fcp)"]
- == self.transaction_data["measurements"]["fcp"]["value"]
- )
- assert (
- response.data["data"][0]["sum(measurements.fcp)"]
- == self.transaction_data["measurements"]["fcp"]["value"]
- )
- def get_measurement_condition_response(self, query_str, field):
- query = {
- "field": ["transaction", "count()"] + (field if field else []),
- "query": query_str,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- return response
- def assert_measurement_condition_without_results(self, query_str, field=None):
- response = self.get_measurement_condition_response(query_str, field)
- assert len(response.data["data"]) == 0
- def assert_measurement_condition_with_results(self, query_str, field=None):
- response = self.get_measurement_condition_response(query_str, field)
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["transaction"] == self.transaction_data["metadata"]["title"]
- assert response.data["data"][0]["count()"] == 1
- def test_measurements_conditions(self):
- self.store_event(self.transaction_data, self.project.id)
- fcp = self.transaction_data["measurements"]["fcp"]["value"]
- # equality condition
- # We use json dumps here to ensure precision when converting from float to str
- # This is necessary because equality on floating point values need to be precise
- self.assert_measurement_condition_with_results(f"measurements.fcp:{json.dumps(fcp)}")
- # greater than condition
- self.assert_measurement_condition_with_results(f"measurements.fcp:>{fcp - 1}")
- self.assert_measurement_condition_without_results(f"measurements.fcp:>{fcp + 1}")
- # less than condition
- self.assert_measurement_condition_with_results(f"measurements.fcp:<{fcp + 1}")
- self.assert_measurement_condition_without_results(f"measurements.fcp:<{fcp - 1}")
- # has condition
- self.assert_measurement_condition_with_results("has:measurements.fcp")
- self.assert_measurement_condition_without_results("!has:measurements.fcp")
- def test_measurements_aggregation_conditions(self):
- self.store_event(self.transaction_data, self.project.id)
- fcp = self.transaction_data["measurements"]["fcp"]["value"]
- functions = [
- "percentile(measurements.fcp, 0.5)",
- "min(measurements.fcp)",
- "max(measurements.fcp)",
- "avg(measurements.fcp)",
- "sum(measurements.fcp)",
- ]
- for function in functions:
- self.assert_measurement_condition_with_results(
- f"{function}:>{fcp - 1}", field=[function]
- )
- self.assert_measurement_condition_without_results(
- f"{function}:>{fcp + 1}", field=[function]
- )
- self.assert_measurement_condition_with_results(
- f"{function}:<{fcp + 1}", field=[function]
- )
- self.assert_measurement_condition_without_results(
- f"{function}:<{fcp - 1}", field=[function]
- )
- count_unique = "count_unique(measurements.fcp)"
- self.assert_measurement_condition_with_results(f"{count_unique}:1", field=[count_unique])
- self.assert_measurement_condition_without_results(f"{count_unique}:0", field=[count_unique])
- def test_compare_numeric_aggregate(self):
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "p75(measurements.fcp)",
- "compare_numeric_aggregate(p75_measurements_fcp,greater,0)",
- ],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert (
- response.data["data"][0]["compare_numeric_aggregate(p75_measurements_fcp,greater,0)"]
- == 1
- )
- query = {
- "field": ["p75()", "compare_numeric_aggregate(p75,equals,0)"],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["compare_numeric_aggregate(p75,equals,0)"] == 0
- def test_no_team_key_transactions(self):
- transactions = [
- "/blah_transaction/",
- "/foo_transaction/",
- "/zoo_transaction/",
- ]
- for transaction in transactions:
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "team": "myteams",
- "project": [self.project.id],
- # use the order by to ensure the result order
- "orderby": "transaction",
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "percentile(transaction.duration, 0.95)",
- ],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 3
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "/blah_transaction/"
- assert data[1]["team_key_transaction"] == 0
- assert data[1]["transaction"] == "/foo_transaction/"
- assert data[2]["team_key_transaction"] == 0
- assert data[2]["transaction"] == "/zoo_transaction/"
- 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)
- transactions = ["/blah_transaction/"]
- key_transactions = [
- (team1, "/foo_transaction/"),
- (team2, "/zoo_transaction/"),
- ]
- for transaction in transactions:
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- for team, transaction in key_transactions:
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- 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()",
- "percentile(transaction.duration, 0.95)",
- ],
- }
- query["orderby"] = ["team_key_transaction", "transaction"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 3
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "/blah_transaction/"
- assert data[1]["team_key_transaction"] == 0
- assert data[1]["transaction"] == "/zoo_transaction/"
- assert data[2]["team_key_transaction"] == 1
- assert data[2]["transaction"] == "/foo_transaction/"
- # not specifying any teams should use my teams
- query = {
- "project": [self.project.id],
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "percentile(transaction.duration, 0.95)",
- ],
- }
- query["orderby"] = ["team_key_transaction", "transaction"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 3
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "/blah_transaction/"
- assert data[1]["team_key_transaction"] == 0
- assert data[1]["transaction"] == "/zoo_transaction/"
- assert data[2]["team_key_transaction"] == 1
- assert data[2]["transaction"] == "/foo_transaction/"
- 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")
- transactions = ["/blah_transaction/"]
- key_transactions = [
- (team1, "/foo_transaction/"),
- (team2, "/zoo_transaction/"),
- ]
- for transaction in transactions:
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- for team, transaction in key_transactions:
- self.create_team_membership(team, user=self.user)
- self.project.add_team(team)
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- 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()",
- "percentile(transaction.duration, 0.95)",
- ],
- }
- # test ascending order
- query["orderby"] = ["team_key_transaction", "transaction"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 3
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "/blah_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"] == "/zoo_transaction/"
- # test descending order
- query["orderby"] = ["-team_key_transaction", "-transaction"]
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 3
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "/zoo_transaction/"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "/foo_transaction/"
- assert data[2]["team_key_transaction"] == 0
- assert data[2]["transaction"] == "/blah_transaction/"
- 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")
- transactions = ["/blah_transaction/"]
- key_transactions = [
- (team1, "/foo_transaction/"),
- (team2, "/zoo_transaction/"),
- ]
- for transaction in transactions:
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- for team, transaction in key_transactions:
- self.create_team_membership(team, user=self.user)
- self.project.add_team(team)
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- TeamKeyTransaction.objects.create(
- organization=self.organization,
- project_team=ProjectTeam.objects.get(
- project=self.project,
- team=team,
- ),
- transaction=transaction,
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- # use the order by to ensure the result order
- "orderby": "transaction",
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "percentile(transaction.duration, 0.95)",
- ],
- }
- # key transactions
- query["query"] = "has:team_key_transaction"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "/foo_transaction/"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "/zoo_transaction/"
- # key transactions
- query["query"] = "team_key_transaction:true"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["team_key_transaction"] == 1
- assert data[0]["transaction"] == "/foo_transaction/"
- assert data[1]["team_key_transaction"] == 1
- assert data[1]["transaction"] == "/zoo_transaction/"
- # not key transactions
- query["query"] = "!has:team_key_transaction"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "/blah_transaction/"
- # not key transactions
- query["query"] = "team_key_transaction:false"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["team_key_transaction"] == 0
- assert data[0]["transaction"] == "/blah_transaction/"
- 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)
- for i in range(MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS + 1):
- transaction = f"transaction-{team.id}-{i}"
- self.transaction_data["transaction"] = transaction
- self.store_event(self.transaction_data, self.project.id)
- TeamKeyTransaction.objects.bulk_create(
- [
- TeamKeyTransaction(
- organization=self.organization,
- project_team=project_team,
- transaction=f"transaction-{team.id}-{i}",
- )
- for i in range(MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS + 1)
- ]
- )
- query = {
- "team": "myteams",
- "project": [self.project.id],
- "orderby": "transaction",
- "field": [
- "team_key_transaction",
- "transaction",
- "transaction.status",
- "project",
- "epm()",
- "failure_rate()",
- "percentile(transaction.duration, 0.95)",
- ],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert (
- sum(row["team_key_transaction"] for row in data)
- == MAX_QUERYABLE_TEAM_KEY_TRANSACTIONS
- )
- def test_no_pagination_param(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=self.project.id,
- )
- query = {"field": ["id", "project.id"], "project": [self.project.id], "noPagination": True}
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- assert "Link" not in response
- def test_nan_result(self):
- query = {"field": ["apdex(300)"], "project": [self.project.id], "query": f"id:{'0' * 32}"}
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["apdex(300)"] == 0
- def test_equation_simple(self):
- event_data = self.load_data(
- timestamp=self.ten_mins_ago,
- )
- event_data["breakdowns"]["span_ops"]["ops.http"]["value"] = 1500
- self.store_event(data=event_data, project_id=self.project.id)
- query = {
- "field": ["spans.http", "equation|spans.http / 3"],
- "project": [self.project.id],
- "query": "event.type:transaction",
- }
- response = self.do_request(
- query,
- {
- "organizations:discover-basic": True,
- },
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert (
- response.data["data"][0]["equation|spans.http / 3"]
- == event_data["breakdowns"]["span_ops"]["ops.http"]["value"] / 3
- )
- assert response.data["meta"]["fields"]["equation|spans.http / 3"] == "number"
- def test_equation_sort(self):
- event_data = self.transaction_data.copy()
- event_data["breakdowns"] = {"span_ops": {"ops.http": {"value": 1500}}}
- self.store_event(data=event_data, project_id=self.project.id)
- event_data2 = self.transaction_data.copy()
- event_data2["breakdowns"] = {"span_ops": {"ops.http": {"value": 2000}}}
- self.store_event(data=event_data2, project_id=self.project.id)
- query = {
- "field": ["spans.http", "equation|spans.http / 3"],
- "project": [self.project.id],
- "orderby": "equation|spans.http / 3",
- "query": "event.type:transaction",
- }
- response = self.do_request(
- query,
- {
- "organizations:discover-basic": True,
- },
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 2
- assert (
- response.data["data"][0]["equation|spans.http / 3"]
- == event_data["breakdowns"]["span_ops"]["ops.http"]["value"] / 3
- )
- assert (
- response.data["data"][1]["equation|spans.http / 3"]
- == event_data2["breakdowns"]["span_ops"]["ops.http"]["value"] / 3
- )
- def test_equation_operation_limit(self):
- query = {
- "field": ["spans.http", f"equation|spans.http{' * 2' * 11}"],
- "project": [self.project.id],
- "query": "event.type:transaction",
- }
- response = self.do_request(
- query,
- {
- "organizations:discover-basic": True,
- },
- )
- assert response.status_code == 400
- @mock.patch("sentry.api.bases.organization_events.MAX_FIELDS", 2)
- def test_equation_field_limit(self):
- query = {
- "field": ["spans.http", "transaction.duration", "equation|5 * 2"],
- "project": [self.project.id],
- "query": "event.type:transaction",
- }
- response = self.do_request(
- query,
- {
- "organizations:discover-basic": True,
- },
- )
- assert response.status_code == 400
- def test_count_if(self):
- unicode_phrase1 = "\u716e\u6211\u66f4\u591a\u7684\u98df\u7269\uff0c\u6211\u9913\u4e86"
- for i in range(5):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + i)),
- duration=timedelta(milliseconds=100 if i < 3 else 200),
- )
- data["tags"] = {
- "sub_customer.is-Enterprise-42": "yes" if i == 0 else "no",
- "unicode-phrase": unicode_phrase1 if i == 0 else "no",
- }
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "count_if(transaction.duration, less, 150)",
- "count_if(transaction.duration, greater, 150)",
- "count_if(sub_customer.is-Enterprise-42, equals, yes)",
- "count_if(sub_customer.is-Enterprise-42, notEquals, yes)",
- f"count_if(unicode-phrase, equals, {unicode_phrase1})",
- ],
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["count_if(transaction.duration, less, 150)"] == 3
- assert response.data["data"][0]["count_if(transaction.duration, greater, 150)"] == 2
- assert response.data["data"][0]["count_if(sub_customer.is-Enterprise-42, equals, yes)"] == 1
- assert (
- response.data["data"][0]["count_if(sub_customer.is-Enterprise-42, notEquals, yes)"] == 4
- )
- assert response.data["data"][0][f"count_if(unicode-phrase, equals, {unicode_phrase1})"] == 1
- def test_count_if_array_field(self):
- data = self.load_data(platform="javascript")
- data["timestamp"] = self.ten_mins_ago_iso
- self.store_event(data=data, project_id=self.project.id)
- query = {
- "field": [
- "count_if(stack.filename, equals, raven.js)",
- ],
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["count_if(stack.filename, equals, raven.js)"] == 1
- def test_count_if_measurements_cls(self):
- data = self.transaction_data.copy()
- data["measurements"] = {"cls": {"value": 0.5}}
- self.store_event(data, project_id=self.project.id)
- data["measurements"] = {"cls": {"value": 0.1}}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "count_if(measurements.cls, greater, 0.05)",
- "count_if(measurements.cls, less, 0.3)",
- ],
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["count_if(measurements.cls, greater, 0.05)"] == 2
- assert response.data["data"][0]["count_if(measurements.cls, less, 0.3)"] == 1
- def test_count_if_filter(self):
- for i in range(5):
- data = self.load_data(
- timestamp=before_now(minutes=(10 + i)),
- duration=timedelta(milliseconds=100 if i < 3 else 200),
- )
- data["tags"] = {"sub_customer.is-Enterprise-42": "yes" if i == 0 else "no"}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": [
- "count_if(transaction.duration, less, 150)",
- ],
- "query": "count_if(transaction.duration, less, 150):>2",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["count_if(transaction.duration, less, 150)"] == 3
- query = {
- "field": [
- "count_if(transaction.duration, less, 150)",
- ],
- "query": "count_if(transaction.duration, less, 150):<2",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 0
- def test_filters_with_escaped_asterisk(self):
- self.transaction_data["transaction"] = r"/:a*/:b-:c(\d\.\e+)"
- self.store_event(self.transaction_data, project_id=self.project.id)
- query = {
- "field": ["transaction", "transaction.duration"],
- # make sure to escape the asterisk so it's not treated as a wildcard
- "query": r'transaction:"/:a\*/:b-:c(\d\.\e+)"',
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- def test_filters_with_back_slashes(self):
- self.transaction_data["transaction"] = r"a\b\c@d"
- self.store_event(self.transaction_data, project_id=self.project.id)
- query = {
- "field": ["transaction", "transaction.duration"],
- "query": r'transaction:"a\b\c@d"',
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- assert len(response.data["data"]) == 1
- def test_mobile_measurements(self):
- self.transaction_data["measurements"]["frames_total"] = {"value": 100}
- self.transaction_data["measurements"]["frames_slow"] = {"value": 10}
- self.transaction_data["measurements"]["frames_frozen"] = {"value": 5}
- self.transaction_data["measurements"]["stall_count"] = {"value": 2}
- self.transaction_data["measurements"]["stall_total_time"] = {"value": 12}
- self.transaction_data["measurements"]["stall_longest_time"] = {"value": 7}
- self.store_event(self.transaction_data, project_id=self.project.id)
- query = {
- "field": [
- "measurements.frames_total",
- "measurements.frames_slow",
- "measurements.frames_frozen",
- "measurements.frames_slow_rate",
- "measurements.frames_frozen_rate",
- "measurements.stall_count",
- "measurements.stall_total_time",
- "measurements.stall_longest_time",
- "measurements.stall_percentage",
- ],
- "query": "",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["measurements.frames_total"] == 100
- assert data[0]["measurements.frames_slow"] == 10
- assert data[0]["measurements.frames_frozen"] == 5
- assert data[0]["measurements.frames_slow_rate"] == 0.1
- assert data[0]["measurements.frames_frozen_rate"] == 0.05
- assert data[0]["measurements.stall_count"] == 2
- assert data[0]["measurements.stall_total_time"] == 12
- assert data[0]["measurements.stall_longest_time"] == 7
- assert data[0]["measurements.stall_percentage"] == 0.004
- meta = response.data["meta"]["fields"]
- assert meta["measurements.frames_total"] == "number"
- assert meta["measurements.frames_slow"] == "number"
- assert meta["measurements.frames_frozen"] == "number"
- assert meta["measurements.frames_slow_rate"] == "percentage"
- assert meta["measurements.frames_frozen_rate"] == "percentage"
- assert meta["measurements.stall_count"] == "number"
- assert meta["measurements.stall_total_time"] == "number"
- assert meta["measurements.stall_longest_time"] == "number"
- assert meta["measurements.stall_percentage"] == "percentage"
- query = {
- "field": [
- "p75(measurements.frames_slow_rate)",
- "p75(measurements.frames_frozen_rate)",
- "percentile(measurements.frames_slow_rate,0.5)",
- "percentile(measurements.frames_frozen_rate,0.5)",
- "p75(measurements.stall_percentage)",
- "percentile(measurements.stall_percentage,0.5)",
- ],
- "query": "",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p75(measurements.frames_slow_rate)"] == 0.1
- assert data[0]["p75(measurements.frames_frozen_rate)"] == 0.05
- assert data[0]["p75(measurements.stall_percentage)"] == 0.004
- assert data[0]["percentile(measurements.frames_slow_rate,0.5)"] == 0.1
- assert data[0]["percentile(measurements.frames_frozen_rate,0.5)"] == 0.05
- assert data[0]["percentile(measurements.stall_percentage,0.5)"] == 0.004
- meta = response.data["meta"]["fields"]
- assert meta["p75(measurements.frames_slow_rate)"] == "percentage"
- assert meta["p75(measurements.frames_frozen_rate)"] == "percentage"
- assert meta["p75(measurements.stall_percentage)"] == "percentage"
- assert meta["percentile(measurements.frames_slow_rate,0.5)"] == "percentage"
- assert meta["percentile(measurements.stall_percentage,0.5)"] == "percentage"
- def test_project_auto_fields(self):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "environment": "staging",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=self.project.id,
- )
- query = {"field": ["environment"]}
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["environment"] == "staging"
- assert response.data["data"][0]["project.name"] == self.project.slug
- def test_timestamp_different_from_params(self):
- fifteen_days_ago = iso_format(before_now(days=15))
- fifteen_days_later = iso_format(before_now(days=-15))
- for query_text in [
- f"timestamp:<{fifteen_days_ago}",
- f"timestamp:<={fifteen_days_ago}",
- f"timestamp:>{fifteen_days_later}",
- f"timestamp:>={fifteen_days_later}",
- ]:
- query = {
- "field": ["count()"],
- "query": query_text,
- "statsPeriod": "14d",
- "project": self.project.id,
- }
- response = self.do_request(query)
- assert response.status_code == 400, query_text
- @mock.patch("sentry.search.events.builder.discover.raw_snql_query")
- def test_removes_unnecessary_default_project_and_transaction_thresholds(self, mock_snql_query):
- mock_snql_query.side_effect = [{"meta": {}, "data": []}]
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.organization,
- # these are the default values that we use
- threshold=constants.DEFAULT_PROJECT_THRESHOLD,
- metric=TransactionMetric.DURATION.value,
- )
- ProjectTransactionThresholdOverride.objects.create(
- transaction="transaction",
- project=self.project,
- organization=self.organization,
- # these are the default values that we use
- threshold=constants.DEFAULT_PROJECT_THRESHOLD,
- metric=TransactionMetric.DURATION.value,
- )
- query = {
- "field": ["apdex()", "user_misery()"],
- "query": "event.type:transaction",
- "project": [self.project.id],
- }
- response = self.do_request(
- query,
- features={
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- },
- )
- assert response.status_code == 200, response.content
- assert mock_snql_query.call_count == 1
- assert (
- Function("tuple", ["duration", 300], "project_threshold_config")
- in mock_snql_query.call_args_list[0][0][0].query.select
- )
- @mock.patch("sentry.search.events.builder.discover.raw_snql_query")
- def test_removes_unnecessary_default_project_and_transaction_thresholds_keeps_others(
- self, mock_snql_query
- ):
- mock_snql_query.side_effect = [{"meta": {}, "data": []}]
- ProjectTransactionThreshold.objects.create(
- project=self.project,
- organization=self.organization,
- # these are the default values that we use
- threshold=constants.DEFAULT_PROJECT_THRESHOLD,
- metric=TransactionMetric.DURATION.value,
- )
- ProjectTransactionThresholdOverride.objects.create(
- transaction="transaction",
- project=self.project,
- organization=self.organization,
- # these are the default values that we use
- threshold=constants.DEFAULT_PROJECT_THRESHOLD,
- metric=TransactionMetric.DURATION.value,
- )
- project = self.create_project()
- ProjectTransactionThreshold.objects.create(
- project=project,
- organization=self.organization,
- threshold=100,
- metric=TransactionMetric.LCP.value,
- )
- ProjectTransactionThresholdOverride.objects.create(
- transaction="transaction",
- project=project,
- organization=self.organization,
- threshold=200,
- metric=TransactionMetric.LCP.value,
- )
- query = {
- "field": ["apdex()", "user_misery()"],
- "query": "event.type:transaction",
- "project": [self.project.id, project.id],
- }
- response = self.do_request(
- query,
- features={
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- },
- )
- assert response.status_code == 200, response.content
- assert mock_snql_query.call_count == 1
- project_threshold_override_config_index = Function(
- "indexOf",
- [
- # only 1 transaction override is present here
- # because the other use to the default values
- [(Function("toUInt64", [project.id]), "transaction")],
- (Column("project_id"), Column("transaction")),
- ],
- "project_threshold_override_config_index",
- )
- project_threshold_config_index = Function(
- "indexOf",
- [
- # only 1 project override is present here
- # because the other use to the default values
- [Function("toUInt64", [project.id])],
- Column("project_id"),
- ],
- "project_threshold_config_index",
- )
- assert (
- Function(
- "if",
- [
- Function("equals", [project_threshold_override_config_index, 0]),
- Function(
- "if",
- [
- Function("equals", [project_threshold_config_index, 0]),
- ("duration", 300),
- Function(
- "arrayElement", [[("lcp", 100)], project_threshold_config_index]
- ),
- ],
- ),
- Function(
- "arrayElement",
- [[("lcp", 200)], project_threshold_override_config_index],
- ),
- ],
- "project_threshold_config",
- )
- in mock_snql_query.call_args_list[0][0][0].query.select
- )
- def test_count_web_vitals(self):
- # Good
- self.transaction_data["measurements"] = {
- "lcp": {"value": constants.VITAL_THRESHOLDS["lcp"]["meh"] - 100},
- }
- self.store_event(self.transaction_data, self.project.id)
- # Meh
- self.transaction_data["measurements"] = {
- "lcp": {"value": constants.VITAL_THRESHOLDS["lcp"]["meh"] + 100},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "count_web_vitals(measurements.lcp, poor)",
- "count_web_vitals(measurements.lcp, meh)",
- "count_web_vitals(measurements.lcp, good)",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0] == {
- "count_web_vitals(measurements.lcp, poor)": 0,
- "count_web_vitals(measurements.lcp, meh)": 2,
- "count_web_vitals(measurements.lcp, good)": 1,
- }
- def test_count_web_vitals_invalid_vital(self):
- query = {
- "field": [
- "count_web_vitals(measurements.foo, poor)",
- ],
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- query = {
- "field": [
- "count_web_vitals(tags[lcp], poor)",
- ],
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- query = {
- "field": [
- "count_web_vitals(transaction.duration, poor)",
- ],
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- query = {
- "field": [
- "count_web_vitals(measurements.lcp, bad)",
- ],
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- def test_tag_that_looks_like_aggregate(self):
- data = self.load_data()
- data["tags"] = {"p95": "<5k"}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["p95"],
- "query": "p95:<5k",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["p95"] == "<5k"
- def test_chained_or_query_meta_tip(self):
- query = {
- "field": ["transaction"],
- "query": "transaction:a OR transaction:b",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- meta = response.data["meta"]
- assert meta["tips"] == {
- "query": "Did you know you can replace chained or conditions like `field:a OR field:b OR field:c` with `field:[a,b,c]`",
- "columns": None,
- }
- @override_settings(SENTRY_SELF_HOSTED=False)
- def test_no_ratelimit(self):
- query = {
- "field": ["transaction"],
- "project": [self.project.id],
- }
- with freeze_time("2000-01-01"):
- for _ in range(15):
- self.do_request(query)
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- def test_transaction_source(self):
- query = {
- "field": ["transaction"],
- "query": "transaction.source:task",
- "project": [self.project.id],
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- def test_readable_device_name(self):
- data = self.load_data()
- data["tags"] = {"device": "iPhone14,3"}
- self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["device"],
- "query": "",
- "project": [self.project.id],
- "readable": True,
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["device"] == "iPhone14,3"
- assert data[0]["readable"] == "iPhone 13 Pro Max"
- def test_http_status_code(self):
- project1 = self.create_project()
- project2 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"http.status_code": "200"},
- },
- project_id=project1.id,
- )
- self.store_event(
- data={
- "event_id": "b" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "contexts": {"response": {"status_code": 400}},
- },
- project_id=project2.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "http.status_code"],
- "query": "",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- result = {r["http.status_code"] for r in data}
- assert result == {"200", "400"}
- def test_http_status_code_context_priority(self):
- project1 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"http.status_code": "200"},
- "contexts": {"response": {"status_code": 400}},
- },
- project_id=project1.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["event.type", "http.status_code"],
- "query": "",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["http.status_code"] == "400"
- def test_total_count(self):
- project1 = self.create_project()
- for i in range(3):
- self.store_event(data=self.load_data(platform="javascript"), project_id=project1.id)
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=project1.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["transaction", "total.count", "count()"],
- "query": "!transaction:/example",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["total.count"] == 3
- def test_total_count_by_itself(self):
- project1 = self.create_project()
- for i in range(3):
- self.store_event(data=self.load_data(platform="javascript"), project_id=project1.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["total.count"],
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 400, response.content
- def test_total_count_equation(self):
- project1 = self.create_project()
- for i in range(3):
- self.store_event(data=self.load_data(platform="javascript"), project_id=project1.id)
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- },
- project_id=project1.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["transaction", "count()", "total.count", "equation|count()/total.count"],
- "query": "",
- "orderby": "equation|count()/total.count",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["equation|count()/total.count"] == 0.25
- assert data[1]["equation|count()/total.count"] == 0.75
- def test_total_count_filter(self):
- project1 = self.create_project()
- for i in range(3):
- self.store_event(data=self.load_data(platform="javascript"), project_id=project1.id)
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"total.count": ">45"},
- },
- project_id=project1.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["transaction", "count()", "total.count"],
- "query": "total.count:>45",
- "orderby": "count()",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["total.count"] == 1
- def test_total_sum_transaction_duration_equation(self):
- for i in range(3):
- data = self.load_data(
- timestamp=self.eleven_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/endpoint/1"
- self.store_event(data, project_id=self.project.id)
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/endpoint/2"
- self.store_event(data, project_id=self.project.id)
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": [
- "transaction",
- "sum(transaction.duration)",
- "total.transaction_duration",
- "equation|sum(transaction.duration)/total.transaction_duration",
- ],
- "query": "",
- "orderby": "-equation|sum(transaction.duration)/total.transaction_duration",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 2
- assert data[0]["equation|sum(transaction.duration)/total.transaction_duration"] == 0.75
- assert data[1]["equation|sum(transaction.duration)/total.transaction_duration"] == 0.25
- def test_device_class(self):
- project1 = self.create_project()
- for i in range(3):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"device.class": f"{i + 1}"},
- },
- project_id=project1.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["device.class"],
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 3
- result = (*map(lambda columns: columns["device.class"], data),)
- assert "low" in result
- assert "medium" in result
- assert "high" in result
- def test_device_class_filter_low(self):
- project1 = self.create_project()
- for i in range(3):
- self.store_event(data=self.load_data(platform="javascript"), project_id=project1.id)
- self.store_event(
- data={
- "event_id": "a" * 32,
- "transaction": "/example",
- "message": "how to make fast",
- "timestamp": self.ten_mins_ago_iso,
- "tags": {"device.class": "1"},
- },
- project_id=project1.id,
- )
- features = {"organizations:discover-basic": True, "organizations:global-views": True}
- query = {
- "field": ["device.class", "count()"],
- "query": "device.class:low",
- "orderby": "count()",
- "statsPeriod": "24h",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- assert data[0]["count()"] == 1
- def test_group_id_as_custom_tag(self):
- project1 = self.create_project()
- self.store_event(
- data={
- "event_id": "a" * 32,
- "message": "poof",
- "timestamp": self.ten_mins_ago_iso,
- "user": {"email": self.user.email},
- "tags": {"group_id": "this should just get returned"},
- },
- project_id=project1.id,
- )
- query = {
- "field": ["group_id"],
- "query": "",
- "orderby": "group_id",
- "statsPeriod": "24h",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["group_id"] == "this should just get returned"
- def test_floored_epm(self):
- for _ in range(5):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/aggregates/1"
- event1 = self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["transaction", "floored_epm()", "epm()"],
- "query": "event.type:transaction",
- "orderby": ["transaction"],
- "start": self.eleven_mins_ago_iso,
- "end": iso_format(self.nine_mins_ago),
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["transaction"] == event1.transaction
- assert data[0]["floored_epm()"] == 1
- assert data[0]["epm()"] == 2.5
- def test_floored_epm_more_events(self):
- for _ in range(25):
- data = self.load_data(
- timestamp=self.ten_mins_ago,
- duration=timedelta(seconds=5),
- )
- data["transaction"] = "/aggregates/1"
- event1 = self.store_event(data, project_id=self.project.id)
- query = {
- "field": ["transaction", "floored_epm()", "epm()"],
- "query": "event.type:transaction",
- "orderby": ["transaction"],
- "start": self.eleven_mins_ago_iso,
- "end": iso_format(self.nine_mins_ago),
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["transaction"] == event1.transaction
- assert data[0]["epm()"] == 12.5
- assert data[0]["floored_epm()"] == 10
- @region_silo_test
- class OrganizationEventsProfilesDatasetEndpointTest(OrganizationEventsEndpointTestBase):
- @mock.patch("sentry.search.events.builder.discover.raw_snql_query")
- def test_profiles_dataset_simple(self, mock_snql_query):
- mock_snql_query.side_effect = [
- {
- "data": [
- {
- "project": self.project.id,
- "transaction": "foo",
- "last_seen": "2022-10-20T16:41:22+00:00",
- "latest_event": "a" * 32,
- "count": 1,
- "count_unique_transaction": 1,
- "percentile_profile_duration_0_25": 1,
- "p50_profile_duration": 1,
- "p75_profile_duration": 1,
- "p95_profile_duration": 1,
- "p99_profile_duration": 1,
- "p100_profile_duration": 1,
- "min_profile_duration": 1,
- "max_profile_duration": 1,
- "avg_profile_duration": 1,
- "sum_profile_duration": 1,
- },
- ],
- "meta": [
- {
- "name": "project",
- "type": "UInt64",
- },
- {
- "name": "transaction",
- "type": "LowCardinality(String)",
- },
- {
- "name": "last_seen",
- "type": "DateTime",
- },
- {
- "name": "latest_event",
- "type": "String",
- },
- {
- "name": "count",
- "type": "UInt64",
- },
- {
- "name": "count_unique_transaction",
- "type": "UInt64",
- },
- {
- "name": "percentile_profile_duration_0_25",
- "type": "Float64",
- },
- *[
- {
- "name": f"{fn}_profile_duration",
- "type": "Float64",
- }
- for fn in ["p50", "p75", "p95", "p99", "p100", "min", "max", "avg", "sum"]
- ],
- ],
- },
- ]
- fields = [
- "project",
- "transaction",
- "last_seen()",
- "latest_event()",
- "count()",
- "count_unique(transaction)",
- "percentile(profile.duration, 0.25)",
- "p50(profile.duration)",
- "p75(profile.duration)",
- "p95(profile.duration)",
- "p99(profile.duration)",
- "p100(profile.duration)",
- "min(profile.duration)",
- "max(profile.duration)",
- "avg(profile.duration)",
- "sum(profile.duration)",
- ]
- query = {
- "field": fields,
- "project": [self.project.id],
- "dataset": "profiles",
- }
- response = self.do_request(query, features={"organizations:profiling": True})
- assert response.status_code == 200, response.content
- # making sure the response keys are in the form we expect and not aliased
- data_keys = {key for row in response.data["data"] for key in row}
- field_keys = {key for key in response.data["meta"]["fields"]}
- unit_keys = {key for key in response.data["meta"]["units"]}
- assert set(fields) == data_keys
- assert set(fields) == field_keys
- assert set(fields) == unit_keys
- @region_silo_test
- class OrganizationEventsProfileFunctionsDatasetEndpointTest(
- OrganizationEventsEndpointTestBase, ProfilesSnubaTestCase
- ):
- def test_functions_dataset_simple(self):
- self.store_functions(
- [
- {
- "self_times_ns": [100 for _ in range(100)],
- "package": "foo",
- "function": "bar",
- "in_app": True,
- },
- ],
- project=self.project,
- timestamp=before_now(hours=3),
- )
- self.store_functions(
- [
- {
- "self_times_ns": [150 for _ in range(100)],
- "package": "foo",
- "function": "bar",
- "in_app": True,
- },
- ],
- project=self.project,
- timestamp=before_now(hours=1),
- )
- mid = before_now(hours=2)
- fields = [
- "transaction",
- "project",
- "function",
- "package",
- "is_application",
- "platform.name",
- "environment",
- "release",
- "count()",
- "examples()",
- "p50()",
- "p75()",
- "p95()",
- "p99()",
- "avg()",
- "sum()",
- f"regression_score(function.duration, 0.95, {int(mid.timestamp())})",
- ]
- response = self.do_request(
- {
- "field": fields,
- "statsPeriod": "4h",
- "project": [self.project.id],
- "dataset": "profileFunctions",
- },
- features={"organizations:profiling": True},
- )
- assert response.status_code == 200, response.content
- # making sure the response keys are in the form we expect and not aliased
- data_keys = {key for row in response.data["data"] for key in row}
- field_keys = {key for key in response.data["meta"]["fields"]}
- unit_keys = {key for key in response.data["meta"]["units"]}
- assert set(fields) == data_keys
- assert set(fields) == field_keys
- assert set(fields) == unit_keys
- assert response.data["meta"]["units"] == {
- "transaction": None,
- "project": None,
- "function": None,
- "package": None,
- "is_application": None,
- "platform.name": None,
- "environment": None,
- "release": None,
- "count()": None,
- "examples()": None,
- "p50()": "nanosecond",
- "p75()": "nanosecond",
- "p95()": "nanosecond",
- "p99()": "nanosecond",
- "avg()": "nanosecond",
- "sum()": "nanosecond",
- f"regression_score(function.duration, 0.95, {int(mid.timestamp())})": None,
- }
- @region_silo_test
- class OrganizationEventsIssuePlatformDatasetEndpointTest(
- OrganizationEventsEndpointTestBase, SearchIssueTestMixin, PerformanceIssueTestCase
- ):
- def test_performance_issue_id_filter(self):
- event = self.create_performance_issue()
- query = {
- "field": ["count()"],
- "statsPeriod": "2h",
- "query": f"issue.id:{event.group.id}",
- "dataset": "issuePlatform",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 1
- def test_generic_issue_ids_filter(self):
- user_data = {
- "id": self.user.id,
- "username": "user",
- "email": "hellboy@bar.com",
- "ip_address": "127.0.0.1",
- }
- event, _, group_info = self.store_search_issue(
- self.project.id,
- self.user.id,
- [f"{ProfileFileIOGroupType.type_id}-group1"],
- "prod",
- before_now(hours=1).replace(tzinfo=timezone.utc),
- user=user_data,
- )
- event, _, group_info = self.store_search_issue(
- self.project.id,
- self.user.id,
- [f"{ProfileFileIOGroupType.type_id}-group2"],
- "prod",
- before_now(hours=1).replace(tzinfo=timezone.utc),
- user=user_data,
- )
- assert group_info is not None
- query = {
- "field": ["title", "release", "environment", "user.display", "timestamp"],
- "statsPeriod": "90d",
- "query": f"issue.id:{group_info.group.id}",
- "dataset": "issuePlatform",
- }
- with self.feature(["organizations:profiling"]):
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["title"] == group_info.group.title
- assert response.data["data"][0]["environment"] == "prod"
- assert response.data["data"][0]["user.display"] == user_data["email"]
- assert response.data["data"][0]["timestamp"] == event.timestamp
- query = {
- "field": ["title", "release", "environment", "user.display", "timestamp"],
- "statsPeriod": "90d",
- "query": f"issue:{group_info.group.qualified_short_id}",
- "dataset": "issuePlatform",
- }
- with self.feature(["organizations:profiling"]):
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0]["title"] == group_info.group.title
- assert response.data["data"][0]["environment"] == "prod"
- assert response.data["data"][0]["user.display"] == user_data["email"]
- assert response.data["data"][0]["timestamp"] == event.timestamp
- def test_performance_short_group_id(self):
- event = self.create_performance_issue()
- query = {
- "field": ["count()"],
- "statsPeriod": "1h",
- "query": f"project:{event.group.project.slug} issue:{event.group.qualified_short_id}",
- "dataset": "issuePlatform",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 1
- def test_multiple_performance_short_group_ids_filter(self):
- event1 = self.create_performance_issue()
- event2 = self.create_performance_issue()
- query = {
- "field": ["count()"],
- "statsPeriod": "1h",
- "query": f"project:{event1.group.project.slug} issue:[{event1.group.qualified_short_id},{event2.group.qualified_short_id}]",
- "dataset": "issuePlatform",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 2
- def test_user_display_issue_platform(self):
- project1 = self.create_project()
- user_data = {
- "id": self.user.id,
- "username": "user",
- "email": "hellboy@bar.com",
- "ip_address": "127.0.0.1",
- }
- _, _, group_info = self.store_search_issue(
- project1.id,
- 1,
- ["group1-fingerprint"],
- None,
- before_now(hours=1).replace(tzinfo=timezone.utc),
- user=user_data,
- )
- assert group_info is not None
- features = {
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- "organizations:profiling": True,
- }
- query = {
- "field": ["user.display"],
- "query": f"user.display:hell* issue.id:{group_info.group.id}",
- "statsPeriod": "24h",
- "dataset": "issuePlatform",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- result = {r["user.display"] for r in data}
- assert result == {user_data["email"]}
- def test_all_events_fields(self):
- user_data = {
- "id": self.user.id,
- "username": "user",
- "email": "hellboy@bar.com",
- "ip_address": "127.0.0.1",
- }
- replay_id = str(uuid.uuid4())
- profile_id = str(uuid.uuid4())
- event = self.create_performance_issue(
- contexts={
- "trace": {
- "trace_id": str(uuid.uuid4().hex),
- "span_id": "933e5c9a8e464da9",
- "type": "trace",
- },
- "replay": {"replay_id": replay_id},
- "profile": {"profile_id": profile_id},
- },
- user_data=user_data,
- )
- query = {
- "field": [
- "id",
- "transaction",
- "title",
- "release",
- "environment",
- "user.display",
- "device",
- "os",
- "url",
- "runtime",
- "replayId",
- "profile.id",
- "transaction.duration",
- "timestamp",
- ],
- "statsPeriod": "1h",
- "query": f"project:{event.group.project.slug} issue:{event.group.qualified_short_id}",
- "dataset": "issuePlatform",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"][0]
- assert data == {
- "id": event.event_id,
- "transaction": event.transaction,
- "project.name": event.project.name.lower(),
- "title": event.group.title,
- "release": event.release,
- "environment": event.get_environment().name,
- "user.display": user_data["email"],
- "device": "Mac",
- "os": "",
- "url": event.interfaces.data["request"].full_url,
- "runtime": dict(event.get_raw_data()["tags"])["runtime"],
- "replayId": replay_id.replace("-", ""),
- "profile.id": profile_id.replace("-", ""),
- "transaction.duration": 3000,
- "timestamp": event.datetime.replace(microsecond=0).isoformat(),
- }
- class OrganizationEventsErrorsDatasetEndpointTest(OrganizationEventsEndpointTestBase):
- def test_status(self):
- with self.options({"issues.group_attributes.send_kafka": True}):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=self.project.id,
- ).group
- group_2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group2"],
- },
- project_id=self.project.id,
- ).group
- group_3 = self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group3"],
- },
- project_id=self.project.id,
- ).group
- query = {
- "field": ["count()"],
- "statsPeriod": "2h",
- "query": "status:unresolved",
- "dataset": "errors",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 3
- group_2.status = GroupStatus.IGNORED
- group_2.substatus = GroupSubStatus.FOREVER
- group_2.save(update_fields=["status", "substatus"])
- group_3.status = GroupStatus.IGNORED
- group_3.substatus = GroupSubStatus.FOREVER
- group_3.save(update_fields=["status", "substatus"])
- # XXX: Snuba caches query results, so change the time period so that the query
- # changes enough to bust the cache.
- query["statsPeriod"] = "3h"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 1
- def test_is_status(self):
- with self.options({"issues.group_attributes.send_kafka": True}):
- self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=self.project.id,
- ).group
- group_2 = self.store_event(
- data={
- "event_id": "b" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group2"],
- },
- project_id=self.project.id,
- ).group
- group_3 = self.store_event(
- data={
- "event_id": "c" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group3"],
- },
- project_id=self.project.id,
- ).group
- query = {
- "field": ["count()"],
- "statsPeriod": "2h",
- "query": "is:unresolved",
- "dataset": "errors",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 3
- group_2.status = GroupStatus.IGNORED
- group_2.substatus = GroupSubStatus.FOREVER
- group_2.save(update_fields=["status", "substatus"])
- group_3.status = GroupStatus.IGNORED
- group_3.substatus = GroupSubStatus.FOREVER
- group_3.save(update_fields=["status", "substatus"])
- # XXX: Snuba caches query results, so change the time period so that the query
- # changes enough to bust the cache.
- query["statsPeriod"] = "3h"
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 1
- def test_short_group_id(self):
- group_1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- },
- project_id=self.project.id,
- ).group
- query = {
- "field": ["count()"],
- "statsPeriod": "1h",
- "query": f"project:{group_1.project.slug} issue:{group_1.qualified_short_id}",
- "dataset": "errors",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert response.data["data"][0]["count()"] == 1
- def test_user_display(self):
- with self.options({"issues.group_attributes.send_kafka": True}):
- group_1 = self.store_event(
- data={
- "event_id": "a" * 32,
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- "user": {
- "email": "hellboy@bar.com",
- },
- },
- project_id=self.project.id,
- ).group
- features = {
- "organizations:discover-basic": True,
- "organizations:global-views": True,
- }
- query = {
- "field": ["user.display"],
- "query": f"user.display:hell* issue.id:{group_1.id}",
- "statsPeriod": "24h",
- "dataset": "errors",
- }
- response = self.do_request(query, features=features)
- assert response.status_code == 200, response.content
- data = response.data["data"]
- assert len(data) == 1
- result = {r["user.display"] for r in data}
- assert result == {"hellboy@bar.com"}
- def test_performance_score(self):
- self.transaction_data["measurements"] = {
- "score.lcp": {"value": 0.03},
- "score.weight.lcp": {"value": 0.3},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.transaction_data["measurements"] = {
- "score.lcp": {"value": 1.0},
- "score.weight.lcp": {"value": 1.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "performance_score(measurements.score.lcp)",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0] == {
- "performance_score(measurements.score.lcp)": 0.7923076923076923,
- }
- def test_weighted_performance_score(self):
- self.transaction_data["measurements"] = {
- "score.lcp": {"value": 0.03},
- "score.weight.lcp": {"value": 0.3},
- "score.total": {"value": 0.03},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.transaction_data["measurements"] = {
- "score.lcp": {"value": 1.0},
- "score.weight.lcp": {"value": 1.0},
- "score.total": {"value": 1.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.transaction_data["measurements"] = {
- "score.total": {"value": 0.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "weighted_performance_score(measurements.score.lcp)",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0] == {
- "weighted_performance_score(measurements.score.lcp)": 0.3433333333333333,
- }
- def test_invalid_performance_score_column(self):
- self.transaction_data["measurements"] = {
- "score.total": {"value": 0.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "performance_score(measurements.score.fp)",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- def test_invalid_weighted_performance_score_column(self):
- self.transaction_data["measurements"] = {
- "score.total": {"value": 0.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "weighted_performance_score(measurements.score.fp)",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 400, response.content
- def test_all_events_fields(self):
- user_data = {
- "id": self.user.id,
- "username": "user",
- "email": "hellboy@bar.com",
- "ip_address": "127.0.0.1",
- }
- replay_id = str(uuid.uuid4())
- with self.options({"issues.group_attributes.send_kafka": True}):
- event = self.store_event(
- data={
- "timestamp": self.ten_mins_ago_iso,
- "fingerprint": ["group1"],
- "contexts": {
- "trace": {
- "trace_id": str(uuid.uuid4().hex),
- "span_id": "933e5c9a8e464da9",
- "type": "trace",
- },
- "replay": {"replay_id": replay_id},
- },
- "tags": {"device": "Mac"},
- "user": user_data,
- },
- project_id=self.project.id,
- )
- query = {
- "field": [
- "id",
- "transaction",
- "title",
- "release",
- "environment",
- "user.display",
- "device",
- "os",
- "replayId",
- "timestamp",
- ],
- "statsPeriod": "2d",
- "query": "is:unresolved",
- "dataset": "errors",
- "sort": "-title",
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- data = response.data["data"][0]
- assert data == {
- "id": event.event_id,
- "events.transaction": "",
- "project.name": event.project.name.lower(),
- "events.title": event.group.title,
- "release": event.release,
- "events.environment": None,
- "user.display": user_data["email"],
- "device": "Mac",
- "os": "",
- "replayId": replay_id,
- "events.timestamp": event.datetime.replace(microsecond=0).isoformat(),
- }
- def test_opportunity_score(self):
- self.transaction_data["measurements"] = {
- "score.lcp": {"value": 0.03},
- "score.weight.lcp": {"value": 0.3},
- "score.fcp": {"value": 0.4},
- "score.weight.fcp": {"value": 0.7},
- "score.total": {"value": 0.43},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.transaction_data["measurements"] = {
- "score.lcp": {"value": 1.0},
- "score.weight.lcp": {"value": 1.0},
- "score.total": {"value": 1.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.transaction_data["measurements"] = {
- "score.total": {"value": 0.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "opportunity_score(measurements.score.lcp)",
- "opportunity_score(measurements.score.total)",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0] == {
- "opportunity_score(measurements.score.lcp)": 0.27,
- "opportunity_score(measurements.score.total)": 1.57,
- }
- def test_count_scores(self):
- self.transaction_data["measurements"] = {
- "score.lcp": {"value": 0.03},
- "score.total": {"value": 0.43},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.transaction_data["measurements"] = {
- "score.total": {"value": 1.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- self.transaction_data["measurements"] = {
- "score.total": {"value": 0.0},
- }
- self.store_event(self.transaction_data, self.project.id)
- query = {
- "field": [
- "count_scores(measurements.score.lcp)",
- "count_scores(measurements.score.total)",
- ]
- }
- response = self.do_request(query)
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- assert response.data["data"][0] == {
- "count_scores(measurements.score.lcp)": 1,
- "count_scores(measurements.score.total)": 3,
- }
|