|
26 | 26 | _convert_aggregation_temporality,
|
27 | 27 | )
|
28 | 28 | from opentelemetry.sdk._metrics.measurement import Measurement
|
29 |
| -from opentelemetry.sdk._metrics.point import Gauge, Sum |
| 29 | +from opentelemetry.sdk._metrics.point import Gauge, Histogram, Sum |
30 | 30 |
|
31 | 31 |
|
32 | 32 | class TestSynchronousSumAggregation(TestCase):
|
@@ -576,3 +576,167 @@ def test_current_point_gauge(self):
|
576 | 576 | ),
|
577 | 577 | current_point,
|
578 | 578 | )
|
| 579 | + |
| 580 | + |
| 581 | +class TestHistogramConvertAggregationTemporality(TestCase): |
| 582 | + def test_previous_point_none(self): |
| 583 | + |
| 584 | + current_point = Histogram( |
| 585 | + start_time_unix_nano=0, |
| 586 | + time_unix_nano=1, |
| 587 | + bucket_counts=[0, 2, 1, 2, 0], |
| 588 | + explicit_bounds=[0, 5, 10, 25], |
| 589 | + sum=70, |
| 590 | + aggregation_temporality=AggregationTemporality.DELTA, |
| 591 | + ) |
| 592 | + |
| 593 | + self.assertEqual( |
| 594 | + _convert_aggregation_temporality( |
| 595 | + None, current_point, AggregationTemporality.CUMULATIVE |
| 596 | + ), |
| 597 | + replace( |
| 598 | + current_point, |
| 599 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 600 | + ), |
| 601 | + ) |
| 602 | + |
| 603 | + def test_previous_point_non_cumulative(self): |
| 604 | + |
| 605 | + with self.assertRaises(Exception): |
| 606 | + |
| 607 | + _convert_aggregation_temporality( |
| 608 | + Histogram( |
| 609 | + start_time_unix_nano=0, |
| 610 | + time_unix_nano=1, |
| 611 | + bucket_counts=[0, 2, 1, 2, 0], |
| 612 | + explicit_bounds=[0, 5, 10, 25], |
| 613 | + sum=70, |
| 614 | + aggregation_temporality=AggregationTemporality.DELTA, |
| 615 | + ), |
| 616 | + Histogram( |
| 617 | + start_time_unix_nano=1, |
| 618 | + time_unix_nano=2, |
| 619 | + bucket_counts=[0, 1, 3, 0, 0], |
| 620 | + explicit_bounds=[0, 5, 10, 25], |
| 621 | + sum=35, |
| 622 | + aggregation_temporality=AggregationTemporality.DELTA, |
| 623 | + ), |
| 624 | + AggregationTemporality.DELTA, |
| 625 | + ), |
| 626 | + |
| 627 | + def test_same_aggregation_temporality_cumulative(self): |
| 628 | + current_point = Histogram( |
| 629 | + start_time_unix_nano=0, |
| 630 | + time_unix_nano=2, |
| 631 | + bucket_counts=[0, 3, 4, 2, 0], |
| 632 | + explicit_bounds=[0, 5, 10, 25], |
| 633 | + sum=105, |
| 634 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 635 | + ) |
| 636 | + self.assertEqual( |
| 637 | + _convert_aggregation_temporality( |
| 638 | + Histogram( |
| 639 | + start_time_unix_nano=0, |
| 640 | + time_unix_nano=1, |
| 641 | + bucket_counts=[0, 2, 1, 2, 0], |
| 642 | + explicit_bounds=[0, 5, 10, 25], |
| 643 | + sum=70, |
| 644 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 645 | + ), |
| 646 | + current_point, |
| 647 | + AggregationTemporality.CUMULATIVE, |
| 648 | + ), |
| 649 | + current_point, |
| 650 | + ) |
| 651 | + |
| 652 | + def test_same_aggregation_temporality_delta(self): |
| 653 | + current_point = Histogram( |
| 654 | + start_time_unix_nano=1, |
| 655 | + time_unix_nano=2, |
| 656 | + bucket_counts=[0, 1, 3, 0, 0], |
| 657 | + explicit_bounds=[0, 5, 10, 25], |
| 658 | + sum=35, |
| 659 | + aggregation_temporality=AggregationTemporality.DELTA, |
| 660 | + ) |
| 661 | + |
| 662 | + self.assertEqual( |
| 663 | + _convert_aggregation_temporality( |
| 664 | + Histogram( |
| 665 | + start_time_unix_nano=0, |
| 666 | + time_unix_nano=2, |
| 667 | + bucket_counts=[0, 3, 4, 2, 0], |
| 668 | + explicit_bounds=[0, 5, 10, 25], |
| 669 | + sum=105, |
| 670 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 671 | + ), |
| 672 | + current_point, |
| 673 | + AggregationTemporality.DELTA, |
| 674 | + ), |
| 675 | + current_point, |
| 676 | + ) |
| 677 | + |
| 678 | + def test_aggregation_temporality_to_cumulative(self): |
| 679 | + current_point = Histogram( |
| 680 | + start_time_unix_nano=1, |
| 681 | + time_unix_nano=2, |
| 682 | + bucket_counts=[0, 1, 3, 0, 0], |
| 683 | + explicit_bounds=[0, 5, 10, 25], |
| 684 | + sum=35, |
| 685 | + aggregation_temporality=AggregationTemporality.DELTA, |
| 686 | + ) |
| 687 | + |
| 688 | + self.assertEqual( |
| 689 | + _convert_aggregation_temporality( |
| 690 | + Histogram( |
| 691 | + start_time_unix_nano=0, |
| 692 | + time_unix_nano=1, |
| 693 | + bucket_counts=[0, 2, 1, 2, 0], |
| 694 | + explicit_bounds=[0, 5, 10, 25], |
| 695 | + sum=70, |
| 696 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 697 | + ), |
| 698 | + current_point, |
| 699 | + AggregationTemporality.CUMULATIVE, |
| 700 | + ), |
| 701 | + Histogram( |
| 702 | + start_time_unix_nano=0, |
| 703 | + time_unix_nano=2, |
| 704 | + bucket_counts=[0, 3, 4, 2, 0], |
| 705 | + explicit_bounds=[0, 5, 10, 25], |
| 706 | + sum=105, |
| 707 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 708 | + ), |
| 709 | + ) |
| 710 | + |
| 711 | + def test_aggregation_temporality_to_delta(self): |
| 712 | + current_point = Histogram( |
| 713 | + start_time_unix_nano=0, |
| 714 | + time_unix_nano=2, |
| 715 | + bucket_counts=[0, 3, 4, 2, 0], |
| 716 | + explicit_bounds=[0, 5, 10, 25], |
| 717 | + sum=105, |
| 718 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 719 | + ) |
| 720 | + |
| 721 | + self.assertEqual( |
| 722 | + _convert_aggregation_temporality( |
| 723 | + Histogram( |
| 724 | + start_time_unix_nano=0, |
| 725 | + time_unix_nano=1, |
| 726 | + bucket_counts=[0, 2, 1, 2, 0], |
| 727 | + explicit_bounds=[0, 5, 10, 25], |
| 728 | + sum=70, |
| 729 | + aggregation_temporality=AggregationTemporality.CUMULATIVE, |
| 730 | + ), |
| 731 | + current_point, |
| 732 | + AggregationTemporality.DELTA, |
| 733 | + ), |
| 734 | + Histogram( |
| 735 | + start_time_unix_nano=1, |
| 736 | + time_unix_nano=2, |
| 737 | + bucket_counts=[0, 1, 3, 0, 0], |
| 738 | + explicit_bounds=[0, 5, 10, 25], |
| 739 | + sum=35, |
| 740 | + aggregation_temporality=AggregationTemporality.DELTA, |
| 741 | + ), |
| 742 | + ) |
0 commit comments