def test_create_timeseries_multiple_tags(self):
        """Check that exporter creates timeseries for multiple tag values.

        create_time_series_list should return a time series for each set of
        values in the tag value aggregation map.
        """
        agg = aggregation_module.CountAggregation(
            aggregation_type=aggregation_module.Type.COUNT)

        view = view_module.View(
            name="example.org/test_view",
            description="example.org/test_view",
            columns=[
                tag_key_module.TagKey('color'),
                tag_key_module.TagKey('shape')
            ],
            measure=mock.Mock(),
            aggregation=agg,
        )

        v_data = view_data_module.ViewData(
            view=view,
            start_time=TEST_TIME_STR,
            end_time=TEST_TIME_STR,
        )

        rs_count = aggregation_data_module.CountAggregationData(10)
        bc_count = aggregation_data_module.CountAggregationData(20)
        v_data._tag_value_aggregation_data_map = {
            ('red', 'square'): rs_count,
            ('blue', 'circle'): bc_count,
        }

        v_data = metric_utils.view_data_to_metric(v_data, TEST_TIME)

        exporter = stackdriver.StackdriverStatsExporter()
        time_series_list = exporter.create_time_series_list(v_data)

        self.assertEqual(len(time_series_list), 2)
        self.assertEqual(len(time_series_list[0].points), 1)
        self.assertEqual(len(time_series_list[1].points), 1)

        ts_by_color = {
            ts.metric.labels.get('color'): ts
            for ts in time_series_list
        }
        rs_ts = ts_by_color['red']
        bc_ts = ts_by_color['blue']
        self.assertEqual(rs_ts.metric.labels.get('shape'), 'square')
        self.assertEqual(bc_ts.metric.labels.get('shape'), 'circle')
        self.assertEqual(rs_ts.points[0].value.int64_value, 10)
        self.assertEqual(bc_ts.points[0].value.int64_value, 20)
    def test_add_sample(self):
        count_data = 0
        count_aggregation_data = aggregation_data_module.CountAggregationData(
            count_data=count_data)
        count_aggregation_data.add_sample(10, None, None)

        self.assertEqual(1, count_aggregation_data.count_data)
Esempio n. 3
0
    def test_create_timeseries_something(self):
        """Check that exporter creates timeseries for multiple tag values.

        create_time_series_list should return a time series for each set of
        values in the tag value aggregation map.
        """

        v_data = mock.Mock(spec=view_data_module.ViewData)
        v_data.view.name = "example.org/test_view"
        v_data.view.columns = [
            tag_key_module.TagKey('color'),
            tag_key_module.TagKey('shape')
        ]
        v_data.view.aggregation.aggregation_type = \
            aggregation_module.Type.COUNT
        v_data.start_time = TEST_TIME
        v_data.end_time = TEST_TIME

        rs_count = aggregation_data_module.CountAggregationData(10)
        bc_count = aggregation_data_module.CountAggregationData(20)
        v_data.tag_value_aggregation_data_map = {
            ('red', 'square'): rs_count,
            ('blue', 'circle'): bc_count,
        }

        exporter = stackdriver.StackdriverStatsExporter(
            options=mock.Mock(),
            client=mock.Mock(),
        )
        time_series_list = exporter.create_time_series_list(v_data, "", "")

        self.assertEqual(len(time_series_list), 2)
        self.assertEqual(len(time_series_list[0].points), 1)
        self.assertEqual(len(time_series_list[1].points), 1)

        ts_by_color = {
            ts.metric.labels.get('color'): ts
            for ts in time_series_list
        }
        rs_ts = ts_by_color['red']
        bc_ts = ts_by_color['blue']
        self.assertEqual(rs_ts.metric.labels.get('shape'), 'square')
        self.assertEqual(bc_ts.metric.labels.get('shape'), 'circle')
        self.assertEqual(rs_ts.points[0].value.int64_value, 10)
        self.assertEqual(bc_ts.points[0].value.int64_value, 20)
 def test_to_point(self):
     count_data = 123
     timestamp = datetime(1970, 1, 1)
     agg = aggregation_data_module.CountAggregationData(count_data)
     converted_point = agg.to_point(timestamp)
     self.assertTrue(isinstance(converted_point, point.Point))
     self.assertTrue(isinstance(converted_point.value, value.ValueLong))
     self.assertEqual(converted_point.value.value, count_data)
     self.assertEqual(converted_point.timestamp, timestamp)
Esempio n. 5
0
 def new_aggregation_data(self, measure=None):
     """Get a new AggregationData for this aggregation."""
     return aggregation_data.CountAggregationData(self._initial_count)
    def test_constructor(self):
        count_data = 0
        count_aggregation_data = aggregation_data_module.CountAggregationData(
            count_data=count_data)

        self.assertEqual(0, count_aggregation_data.count_data)
Esempio n. 7
0
 def __init__(self, count=0, aggregation_type=Type.COUNT):
     super(CountAggregation,
           self).__init__(aggregation_type=aggregation_type)
     self._count = aggregation_data.CountAggregationData(count)
     self.aggregation_data = self._count
Esempio n. 8
0
 def __init__(self, count=0):
     super(CountAggregation, self).__init__()
     self._aggregation_type = "count"
     self._count = aggregation_data.CountAggregationData(count)