|
19 | 19 |
|
20 | 20 | from opencensus.__version__ import __version__ |
21 | 21 | from opencensus.stats import aggregation as aggregation_module |
| 22 | +from opencensus.stats import aggregation_data as aggregation_data_module |
22 | 23 | from opencensus.stats import measure as measure_module |
23 | 24 | from opencensus.stats import stats as stats_module |
24 | 25 | from opencensus.stats import view as view_module |
@@ -621,6 +622,43 @@ def test_create_timeseries_float_tagvalue(self, monitor_resource_mock): |
621 | 622 | "custom.googleapis.com/opencensus/view-name2") |
622 | 623 | self.assertIsNotNone(time_series) |
623 | 624 |
|
| 625 | + def test_create_timeseries_from_distribution(self): |
| 626 | + """Check for explicit 0-bound bucket for SD export.""" |
| 627 | + |
| 628 | + v_data = mock.Mock(spec=view_data_module.ViewData) |
| 629 | + v_data.view.name = "example.org/test_view" |
| 630 | + v_data.start_time = '2018-11-21T00:12:34.56Z' |
| 631 | + v_data.end_time = '2018-11-21T00:23:45.67Z' |
| 632 | + |
| 633 | + # Aggregation over (10 * range(10)) for buckets [2, 4, 6, 8] |
| 634 | + dad = aggregation_data_module.DistributionAggregationData( |
| 635 | + mean_data=4.5, |
| 636 | + count_data=100, |
| 637 | + min_=0, |
| 638 | + max_=9, |
| 639 | + sum_of_sqd_deviations=825, |
| 640 | + counts_per_bucket=[20, 20, 20, 20, 20], |
| 641 | + bounds=[2, 4, 6, 8], |
| 642 | + exemplars={mock.Mock() for ii in range(5)} |
| 643 | + ) |
| 644 | + v_data.tag_value_aggregation_data_map = ({'tag_key': dad}) |
| 645 | + |
| 646 | + exporter = stackdriver.StackdriverStatsExporter( |
| 647 | + options=mock.Mock(), |
| 648 | + client=mock.Mock(), |
| 649 | + ) |
| 650 | + time_series = exporter.create_time_series_list(v_data, "", "") |
| 651 | + |
| 652 | + self.assertEqual(len(time_series.points), 1) |
| 653 | + [point] = time_series.points |
| 654 | + dv = point.value.distribution_value |
| 655 | + self.assertEqual(100, dv.count) |
| 656 | + self.assertEqual(4.5, dv.mean) |
| 657 | + self.assertEqual(825.0, dv.sum_of_squared_deviation) |
| 658 | + self.assertEqual([0, 20, 20, 20, 20, 20], dv.bucket_counts) |
| 659 | + self.assertEqual([0, 2, 4, 6, 8], |
| 660 | + dv.bucket_options.explicit_buckets.bounds) |
| 661 | + |
624 | 662 | def test_create_metric_descriptor_count(self): |
625 | 663 | client = mock.Mock() |
626 | 664 | option = stackdriver.Options( |
|
0 commit comments