@@ -4951,7 +4951,15 @@ def test_count_web_vitals_invalid_vital(self):
49514951
49524952
49534953class OrganizationEventsMetricsEnhancedPerformanceEndpointTest (MetricsEnhancedPerformanceTestCase ):
4954- METRIC_STRINGS = ["foo_transaction" , "bar_transaction" , "staging" ]
4954+ # Poor intentionally omitted for test_measurement_rating_that_does_not_exist
4955+ METRIC_STRINGS = [
4956+ "foo_transaction" ,
4957+ "bar_transaction" ,
4958+ "staging" ,
4959+ "measurement_rating" ,
4960+ "good" ,
4961+ "meh" ,
4962+ ]
49554963
49564964 def setUp (self ):
49574965 super ().setUp ()
@@ -5171,3 +5179,121 @@ def test_performance_homepage_query(self):
51715179 assert data ["p75_measurements_fid" ] == 3.0
51725180 assert data ["p75_measurements_cls" ] == 4.0
51735181 assert response .data ["meta" ]["isMetricsData" ]
5182+
5183+ def test_measurement_rating (self ):
5184+ self .store_metric (
5185+ 50 ,
5186+ metric = "measurements.lcp" ,
5187+ tags = {"measurement_rating" : "good" , "transaction" : "foo_transaction" },
5188+ timestamp = self .min_ago ,
5189+ )
5190+ self .store_metric (
5191+ 15 ,
5192+ metric = "measurements.fp" ,
5193+ tags = {"measurement_rating" : "good" , "transaction" : "foo_transaction" },
5194+ timestamp = self .min_ago ,
5195+ )
5196+ self .store_metric (
5197+ 1500 ,
5198+ metric = "measurements.fcp" ,
5199+ tags = {"measurement_rating" : "meh" , "transaction" : "foo_transaction" },
5200+ timestamp = self .min_ago ,
5201+ )
5202+ self .store_metric (
5203+ 125 ,
5204+ metric = "measurements.fid" ,
5205+ tags = {"measurement_rating" : "meh" , "transaction" : "foo_transaction" },
5206+ timestamp = self .min_ago ,
5207+ )
5208+ self .store_metric (
5209+ 0.15 ,
5210+ metric = "measurements.cls" ,
5211+ tags = {"measurement_rating" : "good" , "transaction" : "foo_transaction" },
5212+ timestamp = self .min_ago ,
5213+ )
5214+
5215+ response = self .do_request (
5216+ {
5217+ "field" : [
5218+ "transaction" ,
5219+ "count_web_vitals(measurements.lcp, good)" ,
5220+ "count_web_vitals(measurements.fp, good)" ,
5221+ "count_web_vitals(measurements.fcp, meh)" ,
5222+ "count_web_vitals(measurements.fid, meh)" ,
5223+ "count_web_vitals(measurements.cls, good)" ,
5224+ ],
5225+ "query" : "event.type:transaction" ,
5226+ "metricsEnhanced" : "1" ,
5227+ "per_page" : 50 ,
5228+ }
5229+ )
5230+ assert response .status_code == 200 , response .content
5231+ assert len (response .data ["data" ]) == 1
5232+ assert response .data ["meta" ]["isMetricsData" ]
5233+ assert response .data ["data" ][0 ]["count_web_vitals_measurements_lcp_good" ] == 1
5234+ assert response .data ["data" ][0 ]["count_web_vitals_measurements_fp_good" ] == 1
5235+ assert response .data ["data" ][0 ]["count_web_vitals_measurements_fcp_meh" ] == 1
5236+ assert response .data ["data" ][0 ]["count_web_vitals_measurements_fid_meh" ] == 1
5237+ assert response .data ["data" ][0 ]["count_web_vitals_measurements_cls_good" ] == 1
5238+
5239+ def test_measurement_rating_that_does_not_exist (self ):
5240+ self .store_metric (
5241+ 1 ,
5242+ metric = "measurements.lcp" ,
5243+ tags = {"measurement_rating" : "good" , "transaction" : "foo_transaction" },
5244+ timestamp = self .min_ago ,
5245+ )
5246+
5247+ response = self .do_request (
5248+ {
5249+ "field" : ["transaction" , "count_web_vitals(measurements.lcp, poor)" ],
5250+ "query" : "event.type:transaction" ,
5251+ "metricsEnhanced" : "1" ,
5252+ "per_page" : 50 ,
5253+ }
5254+ )
5255+ assert response .status_code == 200 , response .content
5256+ assert len (response .data ["data" ]) == 1
5257+ assert response .data ["meta" ]["isMetricsData" ]
5258+ assert response .data ["data" ][0 ]["count_web_vitals_measurements_lcp_poor" ] == 0
5259+
5260+ def test_count_web_vitals_invalid_vital (self ):
5261+ query = {
5262+ "field" : [
5263+ "count_web_vitals(measurements.foo, poor)" ,
5264+ ],
5265+ "project" : [self .project .id ],
5266+ "metricsEnhanced" : "1" ,
5267+ }
5268+ response = self .do_request (query )
5269+ assert response .status_code == 400 , response .content
5270+
5271+ query = {
5272+ "field" : [
5273+ "count_web_vitals(tags[lcp], poor)" ,
5274+ ],
5275+ "project" : [self .project .id ],
5276+ "metricsEnhanced" : "1" ,
5277+ }
5278+ response = self .do_request (query )
5279+ assert response .status_code == 400 , response .content
5280+
5281+ query = {
5282+ "field" : [
5283+ "count_web_vitals(transaction.duration, poor)" ,
5284+ ],
5285+ "project" : [self .project .id ],
5286+ "metricsEnhanced" : "1" ,
5287+ }
5288+ response = self .do_request (query )
5289+ assert response .status_code == 400 , response .content
5290+
5291+ query = {
5292+ "field" : [
5293+ "count_web_vitals(measurements.lcp, bad)" ,
5294+ ],
5295+ "project" : [self .project .id ],
5296+ "metricsEnhanced" : "1" ,
5297+ }
5298+ response = self .do_request (query )
5299+ assert response .status_code == 400 , response .content
0 commit comments