@@ -487,26 +487,21 @@ def test_traced_not_recording(self):
487487 self .assertFalse (mock_span .set_attribute .called )
488488 self .assertFalse (mock_span .set_status .called )
489489
490- metrics_list = self .memory_metrics_reader .get_metrics_data ()
491- self .assertTrue (len (metrics_list .resource_metrics ) != 0 )
492-
493- for resource_metric in metrics_list .resource_metrics :
494- for scope_metric in resource_metric .scope_metrics :
495- for metric in scope_metric .metrics :
496- data_points = list (metric .data .data_points )
497- self .assertEqual (len (data_points ), 1 )
498- for point in list (metric .data .data_points ):
499- if isinstance (point , HistogramDataPoint ):
500- self .assertEqual (point .count , 1 )
501- if isinstance (point , NumberDataPoint ):
502- self .assertEqual (point .value , 0 )
503- for attr in point .attributes :
504- self .assertIn (
505- attr ,
506- _recommended_metrics_attrs_old [
507- metric .name
508- ],
509- )
490+ metrics = self .get_sorted_metrics ()
491+ self .assertTrue (len (metrics ) != 0 )
492+ for metric in metrics :
493+ data_points = list (metric .data .data_points )
494+ self .assertEqual (len (data_points ), 1 )
495+ for point in list (metric .data .data_points ):
496+ if isinstance (point , HistogramDataPoint ):
497+ self .assertEqual (point .count , 1 )
498+ if isinstance (point , NumberDataPoint ):
499+ self .assertEqual (point .value , 0 )
500+ for attr in point .attributes :
501+ self .assertIn (
502+ attr ,
503+ _recommended_metrics_attrs_old [metric .name ],
504+ )
510505
511506 def test_uninstrument_after_instrument (self ):
512507 self .client ().simulate_get (path = "/hello" )
@@ -524,28 +519,22 @@ def test_falcon_metrics(self):
524519 self .client ().simulate_get ("/hello/756" )
525520 self .client ().simulate_get ("/hello/756" )
526521 self .client ().simulate_get ("/hello/756" )
527- metrics_list = self .memory_metrics_reader . get_metrics_data ()
522+ metrics = self .get_sorted_metrics ()
528523 number_data_point_seen = False
529524 histogram_data_point_seen = False
530- self .assertTrue (len (metrics_list .resource_metrics ) != 0 )
531- for resource_metric in metrics_list .resource_metrics :
532- self .assertTrue (len (resource_metric .scope_metrics ) != 0 )
533- for scope_metric in resource_metric .scope_metrics :
534- self .assertTrue (len (scope_metric .metrics ) != 0 )
535- for metric in scope_metric .metrics :
536- self .assertIn (metric .name , _expected_metric_names )
537- data_points = list (metric .data .data_points )
538- self .assertEqual (len (data_points ), 1 )
539- for point in data_points :
540- if isinstance (point , HistogramDataPoint ):
541- self .assertEqual (point .count , 3 )
542- histogram_data_point_seen = True
543- if isinstance (point , NumberDataPoint ):
544- number_data_point_seen = True
545- for attr in point .attributes :
546- self .assertIn (
547- attr , _recommended_attrs [metric .name ]
548- )
525+ self .assertTrue (len (metrics ) != 0 )
526+ for metric in metrics :
527+ self .assertIn (metric .name , _expected_metric_names )
528+ data_points = list (metric .data .data_points )
529+ self .assertEqual (len (data_points ), 1 )
530+ for point in data_points :
531+ if isinstance (point , HistogramDataPoint ):
532+ self .assertEqual (point .count , 3 )
533+ histogram_data_point_seen = True
534+ if isinstance (point , NumberDataPoint ):
535+ number_data_point_seen = True
536+ for attr in point .attributes :
537+ self .assertIn (attr , _recommended_attrs [metric .name ])
549538 self .assertTrue (number_data_point_seen and histogram_data_point_seen )
550539
551540 def test_falcon_metric_values_new_semconv (self ):
@@ -556,31 +545,27 @@ def test_falcon_metric_values_new_semconv(self):
556545 self .client ().simulate_get ("/hello/756" )
557546 duration = max (default_timer () - start , 0 )
558547
559- metrics_list = self .memory_metrics_reader .get_metrics_data ()
560- for resource_metric in metrics_list .resource_metrics :
561- for scope_metric in resource_metric .scope_metrics :
562- for metric in scope_metric .metrics :
563- data_points = list (metric .data .data_points )
564- self .assertEqual (len (data_points ), 1 )
565- for point in data_points :
566- if isinstance (point , HistogramDataPoint ):
567- self .assertEqual (point .count , 1 )
568- histogram_data_point_seen = True
569- self .assertAlmostEqual (
570- duration , point .sum , delta = 10
571- )
572- self .assertEqual (
573- point .explicit_bounds ,
574- HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
575- )
576- if isinstance (point , NumberDataPoint ):
577- self .assertEqual (point .value , 0 )
578- number_data_point_seen = True
579- for attr in point .attributes :
580- self .assertIn (
581- attr ,
582- _recommended_metrics_attrs_new [metric .name ],
583- )
548+ metrics = self .get_sorted_metrics ()
549+ for metric in metrics :
550+ data_points = list (metric .data .data_points )
551+ self .assertEqual (len (data_points ), 1 )
552+ for point in data_points :
553+ if isinstance (point , HistogramDataPoint ):
554+ self .assertEqual (point .count , 1 )
555+ histogram_data_point_seen = True
556+ self .assertAlmostEqual (duration , point .sum , delta = 10 )
557+ self .assertEqual (
558+ point .explicit_bounds ,
559+ HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
560+ )
561+ if isinstance (point , NumberDataPoint ):
562+ self .assertEqual (point .value , 0 )
563+ number_data_point_seen = True
564+ for attr in point .attributes :
565+ self .assertIn (
566+ attr ,
567+ _recommended_metrics_attrs_new [metric .name ],
568+ )
584569
585570 self .assertTrue (number_data_point_seen and histogram_data_point_seen )
586571
@@ -592,51 +577,45 @@ def test_falcon_metric_values_both_semconv(self):
592577 self .client ().simulate_get ("/hello/756" )
593578 duration_s = default_timer () - start
594579
595- metrics_list = self .memory_metrics_reader . get_metrics_data ()
580+ metrics = self .get_sorted_metrics ()
596581
597582 # pylint: disable=too-many-nested-blocks
598- for resource_metric in metrics_list .resource_metrics :
599- for scope_metric in resource_metric .scope_metrics :
600- for metric in scope_metric .metrics :
583+ for metric in metrics :
584+ if metric .unit == "ms" :
585+ self .assertEqual (metric .name , "http.server.duration" )
586+ elif metric .unit == "s" :
587+ self .assertEqual (metric .name , "http.server.request.duration" )
588+ else :
589+ self .assertEqual (metric .name , "http.server.active_requests" )
590+ data_points = list (metric .data .data_points )
591+ self .assertEqual (len (data_points ), 1 )
592+ for point in data_points :
593+ if isinstance (point , HistogramDataPoint ):
594+ self .assertEqual (point .count , 1 )
601595 if metric .unit == "ms" :
602- self .assertEqual (metric .name , "http.server.duration" )
596+ self .assertAlmostEqual (
597+ max (round (duration_s * 1000 ), 0 ),
598+ point .sum ,
599+ delta = 10 ,
600+ )
603601 elif metric .unit == "s" :
604- self .assertEqual (
605- metric . name , "http.server.request.duration"
602+ self .assertAlmostEqual (
603+ max ( duration_s , 0 ), point . sum , delta = 10
606604 )
607- else :
608605 self .assertEqual (
609- metric .name , "http.server.active_requests"
606+ point .explicit_bounds ,
607+ HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
610608 )
611- data_points = list (metric .data .data_points )
612- self .assertEqual (len (data_points ), 1 )
613- for point in data_points :
614- if isinstance (point , HistogramDataPoint ):
615- self .assertEqual (point .count , 1 )
616- if metric .unit == "ms" :
617- self .assertAlmostEqual (
618- max (round (duration_s * 1000 ), 0 ),
619- point .sum ,
620- delta = 10 ,
621- )
622- elif metric .unit == "s" :
623- self .assertAlmostEqual (
624- max (duration_s , 0 ), point .sum , delta = 10
625- )
626- self .assertEqual (
627- point .explicit_bounds ,
628- HTTP_DURATION_HISTOGRAM_BUCKETS_NEW ,
629- )
630-
631- histogram_data_point_seen = True
632- if isinstance (point , NumberDataPoint ):
633- self .assertEqual (point .value , 0 )
634- number_data_point_seen = True
635- for attr in point .attributes :
636- self .assertIn (
637- attr ,
638- _recommended_metrics_attrs_both [metric .name ],
639- )
609+
610+ histogram_data_point_seen = True
611+ if isinstance (point , NumberDataPoint ):
612+ self .assertEqual (point .value , 0 )
613+ number_data_point_seen = True
614+ for attr in point .attributes :
615+ self .assertIn (
616+ attr ,
617+ _recommended_metrics_attrs_both [metric .name ],
618+ )
640619 self .assertTrue (number_data_point_seen and histogram_data_point_seen )
641620
642621 def test_falcon_metric_values (self ):
@@ -647,41 +626,35 @@ def test_falcon_metric_values(self):
647626 self .client ().simulate_get ("/hello/756" )
648627 duration = max (round ((default_timer () - start ) * 1000 ), 0 )
649628
650- metrics_list = self .memory_metrics_reader .get_metrics_data ()
651- for resource_metric in metrics_list .resource_metrics :
652- for scope_metric in resource_metric .scope_metrics :
653- for metric in scope_metric .metrics :
654- data_points = list (metric .data .data_points )
655- self .assertEqual (len (data_points ), 1 )
656- for point in list (metric .data .data_points ):
657- if isinstance (point , HistogramDataPoint ):
658- self .assertEqual (point .count , 1 )
659- histogram_data_point_seen = True
660- self .assertAlmostEqual (
661- duration , point .sum , delta = 10
662- )
663- if isinstance (point , NumberDataPoint ):
664- self .assertEqual (point .value , 0 )
665- number_data_point_seen = True
666- for attr in point .attributes :
667- self .assertIn (
668- attr ,
669- _recommended_metrics_attrs_old [metric .name ],
670- )
629+ metrics = self .get_sorted_metrics ()
630+ for metric in metrics :
631+ data_points = list (metric .data .data_points )
632+ self .assertEqual (len (data_points ), 1 )
633+ for point in list (metric .data .data_points ):
634+ if isinstance (point , HistogramDataPoint ):
635+ self .assertEqual (point .count , 1 )
636+ histogram_data_point_seen = True
637+ self .assertAlmostEqual (duration , point .sum , delta = 10 )
638+ if isinstance (point , NumberDataPoint ):
639+ self .assertEqual (point .value , 0 )
640+ number_data_point_seen = True
641+ for attr in point .attributes :
642+ self .assertIn (
643+ attr ,
644+ _recommended_metrics_attrs_old [metric .name ],
645+ )
671646
672647 self .assertTrue (number_data_point_seen and histogram_data_point_seen )
673648
674649 def test_metric_uninstrument (self ):
675650 self .client ().simulate_request (method = "POST" , path = "/hello/756" )
676651 FalconInstrumentor ().uninstrument ()
677652 self .client ().simulate_request (method = "POST" , path = "/hello/756" )
678- metrics_list = self .memory_metrics_reader .get_metrics_data ()
679- for resource_metric in metrics_list .resource_metrics :
680- for scope_metric in resource_metric .scope_metrics :
681- for metric in scope_metric .metrics :
682- for point in list (metric .data .data_points ):
683- if isinstance (point , HistogramDataPoint ):
684- self .assertEqual (point .count , 1 )
653+ metrics = self .get_sorted_metrics ()
654+ for metric in metrics :
655+ for point in list (metric .data .data_points ):
656+ if isinstance (point , HistogramDataPoint ):
657+ self .assertEqual (point .count , 1 )
685658
686659
687660class TestFalconInstrumentationWithTracerProvider (TestBase ):
0 commit comments