@@ -497,32 +497,26 @@ def test_flask_metrics(self):
497497 self .client .get ("/hello/321" )
498498 self .client .get ("/hello/756" )
499499 duration = max (round ((default_timer () - start ) * 1000 ), 0 )
500- metrics_list = self .memory_metrics_reader . get_metrics_data ()
500+ metrics = self .get_sorted_metrics ()
501501 number_data_point_seen = False
502502 histogram_data_point_seen = False
503- self .assertTrue (len (metrics_list .resource_metrics ) != 0 )
504- for resource_metric in metrics_list .resource_metrics :
505- self .assertTrue (len (resource_metric .scope_metrics ) != 0 )
506- for scope_metric in resource_metric .scope_metrics :
507- self .assertTrue (len (scope_metric .metrics ) != 0 )
508- for metric in scope_metric .metrics :
509- self .assertIn (metric .name , _expected_metric_names_old )
510- data_points = list (metric .data .data_points )
511- self .assertEqual (len (data_points ), 1 )
512- for point in data_points :
513- if isinstance (point , HistogramDataPoint ):
514- self .assertEqual (point .count , 3 )
515- self .assertAlmostEqual (
516- duration , point .sum , delta = 10
517- )
518- histogram_data_point_seen = True
519- if isinstance (point , NumberDataPoint ):
520- number_data_point_seen = True
521- for attr in point .attributes :
522- self .assertIn (
523- attr ,
524- _recommended_metrics_attrs_old [metric .name ],
525- )
503+ self .assertTrue (len (metrics ) != 0 )
504+ for metric in metrics :
505+ self .assertIn (metric .name , _expected_metric_names_old )
506+ data_points = list (metric .data .data_points )
507+ self .assertEqual (len (data_points ), 1 )
508+ for point in data_points :
509+ if isinstance (point , HistogramDataPoint ):
510+ self .assertEqual (point .count , 3 )
511+ self .assertAlmostEqual (duration , point .sum , delta = 10 )
512+ histogram_data_point_seen = True
513+ if isinstance (point , NumberDataPoint ):
514+ number_data_point_seen = True
515+ for attr in point .attributes :
516+ self .assertIn (
517+ attr ,
518+ _recommended_metrics_attrs_old [metric .name ],
519+ )
526520 self .assertTrue (number_data_point_seen and histogram_data_point_seen )
527521
528522 def test_flask_metrics_new_semconv (self ):
@@ -531,36 +525,30 @@ def test_flask_metrics_new_semconv(self):
531525 self .client .get ("/hello/321" )
532526 self .client .get ("/hello/756" )
533527 duration_s = max (default_timer () - start , 0 )
534- metrics_list = self .memory_metrics_reader . get_metrics_data ()
528+ metrics = self .get_sorted_metrics ()
535529 number_data_point_seen = False
536530 histogram_data_point_seen = False
537- self .assertTrue (len (metrics_list .resource_metrics ) != 0 )
538- for resource_metric in metrics_list .resource_metrics :
539- self .assertTrue (len (resource_metric .scope_metrics ) != 0 )
540- for scope_metric in resource_metric .scope_metrics :
541- self .assertTrue (len (scope_metric .metrics ) != 0 )
542- for metric in scope_metric .metrics :
543- self .assertIn (metric .name , _expected_metric_names_new )
544- data_points = list (metric .data .data_points )
545- self .assertEqual (len (data_points ), 1 )
546- for point in data_points :
547- if isinstance (point , HistogramDataPoint ):
548- self .assertEqual (point .count , 3 )
549- self .assertAlmostEqual (
550- duration_s , point .sum , places = 1
551- )
552- self .assertEqual (
553- point .explicit_bounds ,
554- HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
555- )
556- histogram_data_point_seen = True
557- if isinstance (point , NumberDataPoint ):
558- number_data_point_seen = True
559- for attr in point .attributes :
560- self .assertIn (
561- attr ,
562- _recommended_metrics_attrs_new [metric .name ],
563- )
531+ self .assertTrue (len (metrics ) != 0 )
532+ for metric in metrics :
533+ self .assertIn (metric .name , _expected_metric_names_new )
534+ data_points = list (metric .data .data_points )
535+ self .assertEqual (len (data_points ), 1 )
536+ for point in data_points :
537+ if isinstance (point , HistogramDataPoint ):
538+ self .assertEqual (point .count , 3 )
539+ self .assertAlmostEqual (duration_s , point .sum , places = 1 )
540+ self .assertEqual (
541+ point .explicit_bounds ,
542+ HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
543+ )
544+ histogram_data_point_seen = True
545+ if isinstance (point , NumberDataPoint ):
546+ number_data_point_seen = True
547+ for attr in point .attributes :
548+ self .assertIn (
549+ attr ,
550+ _recommended_metrics_attrs_new [metric .name ],
551+ )
564552 self .assertTrue (number_data_point_seen and histogram_data_point_seen )
565553
566554 def test_flask_metric_values (self ):
@@ -569,18 +557,14 @@ def test_flask_metric_values(self):
569557 self .client .post ("/hello/756" )
570558 self .client .post ("/hello/756" )
571559 duration = max (round ((default_timer () - start ) * 1000 ), 0 )
572- metrics_list = self .memory_metrics_reader .get_metrics_data ()
573- for resource_metric in metrics_list .resource_metrics :
574- for scope_metric in resource_metric .scope_metrics :
575- for metric in scope_metric .metrics :
576- for point in list (metric .data .data_points ):
577- if isinstance (point , HistogramDataPoint ):
578- self .assertEqual (point .count , 3 )
579- self .assertAlmostEqual (
580- duration , point .sum , delta = 10
581- )
582- if isinstance (point , NumberDataPoint ):
583- self .assertEqual (point .value , 0 )
560+ metrics = self .get_sorted_metrics ()
561+ for metric in metrics :
562+ for point in list (metric .data .data_points ):
563+ if isinstance (point , HistogramDataPoint ):
564+ self .assertEqual (point .count , 3 )
565+ self .assertAlmostEqual (duration , point .sum , delta = 10 )
566+ if isinstance (point , NumberDataPoint ):
567+ self .assertEqual (point .value , 0 )
584568
585569 def _assert_basic_metric (
586570 self ,
@@ -589,28 +573,26 @@ def _assert_basic_metric(
589573 expected_histogram_explicit_bounds = None ,
590574 ):
591575 # pylint: disable=too-many-nested-blocks
592- metrics_list = self .memory_metrics_reader .get_metrics_data ()
593- for resource_metric in metrics_list .resource_metrics :
594- for scope_metrics in resource_metric .scope_metrics :
595- for metric in scope_metrics .metrics :
596- for point in list (metric .data .data_points ):
597- if isinstance (point , HistogramDataPoint ):
598- self .assertDictEqual (
599- expected_duration_attributes ,
600- dict (point .attributes ),
601- )
602- if expected_histogram_explicit_bounds is not None :
603- self .assertEqual (
604- expected_histogram_explicit_bounds ,
605- point .explicit_bounds ,
606- )
607- self .assertEqual (point .count , 1 )
608- elif isinstance (point , NumberDataPoint ):
609- self .assertDictEqual (
610- expected_requests_count_attributes ,
611- dict (point .attributes ),
612- )
613- self .assertEqual (point .value , 0 )
576+ metrics = self .get_sorted_metrics ()
577+ for metric in metrics :
578+ for point in list (metric .data .data_points ):
579+ if isinstance (point , HistogramDataPoint ):
580+ self .assertDictEqual (
581+ expected_duration_attributes ,
582+ dict (point .attributes ),
583+ )
584+ if expected_histogram_explicit_bounds is not None :
585+ self .assertEqual (
586+ expected_histogram_explicit_bounds ,
587+ point .explicit_bounds ,
588+ )
589+ self .assertEqual (point .count , 1 )
590+ elif isinstance (point , NumberDataPoint ):
591+ self .assertDictEqual (
592+ expected_requests_count_attributes ,
593+ dict (point .attributes ),
594+ )
595+ self .assertEqual (point .value , 0 )
614596
615597 def test_basic_metric_success (self ):
616598 self .client .get ("/hello/756" )
0 commit comments